use of com.novell.ldapchai.exception.ImpossiblePasswordPolicyException in project pwm by pwm-project.
the class ActivateUserUtils method activateUser.
@SuppressFBWarnings("SE_BAD_FIELD")
static void activateUser(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final ChaiUser theUser = pwmApplication.getProxiedChaiUser(userIdentity);
if (config.readSettingAsBoolean(PwmSetting.ACTIVATE_USER_UNLOCK)) {
try {
theUser.unlockPassword();
} catch (ChaiOperationException e) {
final String errorMsg = "error unlocking user " + userIdentity + ": " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
throw new PwmOperationalException(errorInformation);
}
}
try {
{
// execute configured actions
LOGGER.debug(pwmSession.getLabel(), "executing configured pre-actions to user " + theUser.getEntryDN());
final List<ActionConfiguration> configValues = config.readSettingAsAction(PwmSetting.ACTIVATE_USER_PRE_WRITE_ATTRIBUTES);
if (configValues != null && !configValues.isEmpty()) {
final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest, userIdentity);
final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
}
}
// authenticate the pwm session
final SessionAuthenticator sessionAuthenticator = new SessionAuthenticator(pwmApplication, pwmSession, PwmAuthenticationSource.USER_ACTIVATION);
sessionAuthenticator.authUserWithUnknownPassword(userIdentity, AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
// ensure a change password is triggered
pwmSession.getLoginInfoBean().setType(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
pwmSession.getLoginInfoBean().getAuthFlags().add(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
pwmSession.getLoginInfoBean().getLoginFlags().add(LoginInfoBean.LoginFlag.forcePwChange);
// mark the event log
pwmApplication.getAuditManager().submit(AuditEvent.ACTIVATE_USER, pwmSession.getUserInfo(), pwmSession);
// update the stats bean
pwmApplication.getStatisticsManager().incrementValue(Statistic.ACTIVATED_USERS);
// send email or sms
sendPostActivationNotice(pwmRequest);
// setup post-change attributes
final PostChangePasswordAction postAction = new PostChangePasswordAction() {
public String getLabel() {
return "ActivateUser write attributes";
}
public boolean doAction(final PwmSession pwmSession, final String newPassword) throws PwmUnrecoverableException {
try {
{
// execute configured actions
LOGGER.debug(pwmSession.getLabel(), "executing post-activate configured actions to user " + userIdentity.toDisplayString());
final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
final List<ActionConfiguration> configValues = pwmApplication.getConfig().readSettingAsAction(PwmSetting.ACTIVATE_USER_POST_WRITE_ATTRIBUTES);
final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
}
} catch (PwmOperationalException e) {
final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, e.getErrorInformation().getDetailedErrorMsg(), e.getErrorInformation().getFieldValues());
final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
newException.initCause(e);
throw newException;
} catch (ChaiUnavailableException e) {
final String errorMsg = "unable to reach ldap server while writing post-activate attributes: " + e.getMessage();
final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
newException.initCause(e);
throw newException;
}
return true;
}
};
pwmSession.getUserSessionDataCacheBean().addPostChangePasswordActions("activateUserWriteAttributes", postAction);
} catch (ImpossiblePasswordPolicyException e) {
final ErrorInformation info = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected ImpossiblePasswordPolicyException error while activating user");
LOGGER.warn(pwmSession, info, e);
throw new PwmOperationalException(info);
}
}
Aggregations