Search in sources :

Example 1 with SetPasswordResult

use of com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordResult in project cloudbreak by hortonworks.

the class SetPasswordHandler method accept.

@Override
public void accept(Event<SetPasswordRequest> setPasswordRequestEvent) {
    SetPasswordRequest request = setPasswordRequestEvent.getData();
    LOGGER.info("SetPasswordHandler accepting request {}", request);
    try {
        Stack stack = stackService.getStackById(request.getResourceId());
        MDCBuilder.buildMdcContext(stack);
        FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
        if (FreeIpaCapabilities.hasSetPasswordHashSupport(freeIpaClient.getConfig())) {
            LOGGER.info("IPA has password hash support. Credentials information from UMS will be used.");
            WorkloadCredential workloadCredential = umsCredentialProvider.getCredentials(request.getUserCrn(), MDCUtils.getRequestId());
            setPasswordHash(stack, request, freeIpaClient, workloadCredential);
            if (StringUtils.isBlank(workloadCredential.getHashedPassword())) {
                LOGGER.info("IPA has password hash support but user does not have a password set in UMS; using the provided password directly.");
                freeIpaClient.userSetPasswordWithExpiration(request.getUsername(), request.getPassword(), request.getExpirationInstant());
            }
        } else {
            LOGGER.info("IPA does not have password hash support; using the provided password directly.");
            freeIpaClient.userSetPasswordWithExpiration(request.getUsername(), request.getPassword(), request.getExpirationInstant());
        }
        SetPasswordResult result = new SetPasswordResult(request);
        request.getResult().onNext(result);
    } catch (Exception e) {
        request.getResult().onError(e);
    }
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest) SetPasswordResult(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordResult) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) IOException(java.io.IOException) Stack(com.sequenceiq.freeipa.entity.Stack) WorkloadCredential(com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)

Aggregations

FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 SetPasswordRequest (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)1 SetPasswordResult (com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordResult)1 WorkloadCredential (com.sequenceiq.freeipa.service.freeipa.user.model.WorkloadCredential)1 IOException (java.io.IOException)1