use of password.pwm.http.bean.ActivateUserBean in project pwm by pwm-project.
the class ActivateUserServlet method handleActivateRequest.
@ActionHandler(action = "activate")
public ProcessStatus handleActivateRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final LocalSessionStateBean ssBean = pwmSession.getSessionStateBean();
if (CaptchaUtility.captchaEnabledForRequest(pwmRequest)) {
if (!CaptchaUtility.verifyReCaptcha(pwmRequest)) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_BAD_CAPTCHA_RESPONSE);
throw new PwmUnrecoverableException(errorInfo);
}
}
pwmApplication.getSessionStateService().clearBean(pwmRequest, ActivateUserBean.class);
final List<FormConfiguration> configuredActivationForm = config.readSettingAsForm(PwmSetting.ACTIVATE_USER_FORM);
Map<FormConfiguration, String> formValues = new HashMap<>();
try {
// read the values from the request
formValues = FormUtility.readFormValuesFromRequest(pwmRequest, configuredActivationForm, ssBean.getLocale());
// check for intruders
pwmApplication.getIntruderManager().convenience().checkAttributes(formValues);
// read the context attr
final String contextParam = pwmRequest.readParameterAsString(PwmConstants.PARAM_CONTEXT);
// read the profile attr
final String ldapProfile = pwmRequest.readParameterAsString(PwmConstants.PARAM_LDAP_PROFILE);
// see if the values meet the configured form requirements.
FormUtility.validateFormValues(config, formValues, ssBean.getLocale());
final String searchFilter = ActivateUserUtils.figureLdapSearchFilter(pwmRequest);
// read an ldap user object based on the params
final UserIdentity userIdentity;
{
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
final SearchConfiguration searchConfiguration = SearchConfiguration.builder().contexts(Collections.singletonList(contextParam)).filter(searchFilter).formValues(formValues).ldapProfile(ldapProfile).build();
userIdentity = userSearchEngine.performSingleUserSearch(searchConfiguration, pwmRequest.getSessionLabel());
}
ActivateUserUtils.validateParamsAgainstLDAP(pwmRequest, formValues, userIdentity);
final List<UserPermission> userPermissions = config.readSettingAsUserPermission(PwmSetting.ACTIVATE_USER_QUERY_MATCH);
if (!LdapPermissionTester.testUserPermissions(pwmApplication, pwmSession.getLabel(), userIdentity, userPermissions)) {
final String errorMsg = "user " + userIdentity + " attempted activation, but does not match query string";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_ACTIVATE_NO_PERMISSION, errorMsg);
pwmApplication.getIntruderManager().convenience().markUserIdentity(userIdentity, pwmSession);
pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
throw new PwmUnrecoverableException(errorInformation);
}
final ActivateUserBean activateUserBean = pwmApplication.getSessionStateService().getBean(pwmRequest, ActivateUserBean.class);
activateUserBean.setUserIdentity(userIdentity);
activateUserBean.setFormValidated(true);
pwmApplication.getIntruderManager().convenience().clearAttributes(formValues);
pwmApplication.getIntruderManager().convenience().clearAddressAndSession(pwmSession);
} catch (PwmOperationalException e) {
pwmApplication.getIntruderManager().convenience().markAttributes(formValues, pwmSession);
pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
setLastError(pwmRequest, e.getErrorInformation());
LOGGER.debug(pwmSession.getLabel(), e.getErrorInformation().toDebugStr());
}
return ProcessStatus.Continue;
}
use of password.pwm.http.bean.ActivateUserBean in project pwm by pwm-project.
the class ActivateUserServlet method processTokenChoice.
@ActionHandler(action = "tokenChoice")
private ProcessStatus processTokenChoice(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
final ActivateUserBean activateUserBean = activateUserBean(pwmRequest);
final UserInfo userInfo = userInfo(pwmRequest);
final MessageSendMethod tokenSendMethod = pwmRequest.getConfig().readSettingAsEnum(PwmSetting.ACTIVATE_TOKEN_SEND_METHOD, MessageSendMethod.class);
final List<TokenDestinationItem> tokenDestinationItems = TokenUtil.figureAvailableTokenDestinations(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getLocale(), userInfo, tokenSendMethod);
final String requestedID = pwmRequest.readParameterAsString("choice", PwmHttpRequestWrapper.Flag.BypassValidation);
if (!StringUtil.isEmpty(requestedID)) {
for (final TokenDestinationItem item : tokenDestinationItems) {
if (requestedID.equals(item.getId())) {
activateUserBean.setTokenDestination(item);
}
}
}
return ProcessStatus.Continue;
}
use of password.pwm.http.bean.ActivateUserBean in project pwm by pwm-project.
the class ActivateUserServlet method handleAgreeRequest.
@ActionHandler(action = "agree")
public ProcessStatus handleAgreeRequest(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException {
LOGGER.debug(pwmRequest, "user accepted agreement");
final ActivateUserBean activateUserBean = activateUserBean(pwmRequest);
if (!activateUserBean.isAgreementPassed()) {
activateUserBean.setAgreementPassed(true);
final AuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createUserAuditRecord(AuditEvent.AGREEMENT_PASSED, pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel(), "ActivateUser");
pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
}
return ProcessStatus.Continue;
}
use of password.pwm.http.bean.ActivateUserBean in project pwm by pwm-project.
the class ActivateUserServlet method nextStep.
@Override
protected void nextStep(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final ActivateUserBean activateUserBean = activateUserBean(pwmRequest);
if (!activateUserBean.isFormValidated() || activateUserBean.getUserIdentity() == null) {
ActivateUserUtils.forwardToActivateUserForm(pwmRequest);
return;
}
final UserInfo userInfo = userInfo(pwmRequest);
final MessageSendMethod tokenSendMethod = config.readSettingAsEnum(PwmSetting.ACTIVATE_TOKEN_SEND_METHOD, MessageSendMethod.class);
if (MessageSendMethod.NONE != tokenSendMethod) {
final List<TokenDestinationItem> tokenDestinationItems = TokenUtil.figureAvailableTokenDestinations(pwmApplication, pwmRequest.getSessionLabel(), pwmRequest.getLocale(), userInfo, tokenSendMethod);
if (activateUserBean.getTokenDestination() == null) {
final boolean autoSelect = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.ACTIVATE_USER_TOKEN_AUTO_SELECT_DEST));
if (tokenDestinationItems.size() == 1 && autoSelect) {
activateUserBean.setTokenDestination(tokenDestinationItems.iterator().next());
} else {
forwardToTokenChoiceJsp(pwmRequest, tokenDestinationItems);
return;
}
}
if (!activateUserBean.isTokenSent() && activateUserBean.getTokenDestination() != null) {
TokenUtil.initializeAndSendToken(pwmRequest, TokenUtil.TokenInitAndSendRequest.builder().userInfo(userInfo).tokenDestinationItem(activateUserBean.getTokenDestination()).emailToSend(PwmSetting.EMAIL_ACTIVATION_VERIFICATION).tokenType(TokenType.ACTIVATION).smsToSend(PwmSetting.SMS_ACTIVATION_VERIFICATION_TEXT).build());
}
if (!activateUserBean.isTokenPassed()) {
forwardToEnterCodeJsp(pwmRequest, tokenDestinationItems);
return;
}
}
final String agreementText = config.readSettingAsLocalizedString(PwmSetting.ACTIVATE_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
if (!StringUtil.isEmpty(agreementText) && !activateUserBean.isAgreementPassed()) {
ActivateUserUtils.forwardToAgreementPage(pwmRequest);
return;
}
try {
ActivateUserUtils.activateUser(pwmRequest, activateUserBean.getUserIdentity());
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_ActivateUser);
} catch (PwmOperationalException e) {
LOGGER.debug(pwmRequest, e.getErrorInformation());
pwmApplication.getIntruderManager().convenience().markUserIdentity(activateUserBean.getUserIdentity(), pwmSession);
pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
pwmRequest.respondWithError(e.getErrorInformation());
}
}
use of password.pwm.http.bean.ActivateUserBean in project pwm by pwm-project.
the class ActivateUserServlet method handleEnterCode.
@ActionHandler(action = "enterCode")
public ProcessStatus handleEnterCode(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final ActivateUserBean activateUserBean = pwmApplication.getSessionStateService().getBean(pwmRequest, ActivateUserBean.class);
final String userEnteredCode = pwmRequest.readParameterAsString(PwmConstants.PARAM_TOKEN);
ErrorInformation errorInformation = null;
try {
final TokenPayload tokenPayload = TokenUtil.checkEnteredCode(pwmRequest, userEnteredCode, activateUserBean.getTokenDestination(), null, TokenType.ACTIVATION, TokenService.TokenEntryType.unauthenticated);
activateUserBean.setUserIdentity(tokenPayload.getUserIdentity());
activateUserBean.setTokenPassed(true);
activateUserBean.setFormValidated(true);
activateUserBean.setTokenDestination(tokenPayload.getDestination());
if (pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.DISPLAY_TOKEN_SUCCESS_BUTTON)) {
pwmRequest.setAttribute(PwmRequestAttribute.TokenDestItems, tokenPayload.getDestination());
pwmRequest.forwardToJsp(JspUrl.ACTIVATE_USER_TOKEN_SUCCESS);
return ProcessStatus.Halt;
}
} catch (PwmUnrecoverableException e) {
LOGGER.debug(pwmRequest, "error while checking entered token: ");
errorInformation = e.getErrorInformation();
}
if (!activateUserBean.isTokenPassed()) {
if (errorInformation == null) {
errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT);
}
LOGGER.debug(pwmSession.getLabel(), errorInformation.toDebugStr());
setLastError(pwmRequest, errorInformation);
}
return ProcessStatus.Continue;
}
Aggregations