class SetPasswordHandler implements EventHandler<SetPasswordRequest> {

    @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())) {
                WorkloadCredential workloadCredential = umsCredentialProvider.getCredentials(request.getUserCrn(), MDCUtils.getRequestId());

                LOGGER.info("IPA has password hash support. Credentials information from UMS will be used.");
                workloadCredentialService.setWorkloadCredential(freeIpaClient, request.getUsername(), 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);
        }
    }

}