use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class SetupResponsesServlet method handleClearExisting.
@ActionHandler(action = "clearExisting")
private ProcessStatus handleClearExisting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException {
LOGGER.trace(pwmRequest, "request for response clear received");
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
try {
final String userGUID = pwmSession.getUserInfo().getUserGuid();
final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
pwmApplication.getCrService().clearResponses(pwmSession.getLabel(), pwmRequest.getUserInfoIfLoggedIn(), theUser, userGUID);
pwmSession.reloadUserInfoBean(pwmApplication);
pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, SetupResponsesBean.class);
// mark the event log
final UserAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createUserAuditRecord(AuditEvent.CLEAR_RESPONSES, pwmSession.getUserInfo(), pwmSession);
pwmApplication.getAuditManager().submit(auditRecord);
pwmRequest.sendRedirect(PwmServletDefinition.SetupResponses);
} catch (PwmOperationalException e) {
LOGGER.debug(pwmSession, e.getErrorInformation());
setLastError(pwmRequest, e.getErrorInformation());
}
return ProcessStatus.Continue;
}
use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class SetupResponsesServlet method saveResponses.
private void saveResponses(final PwmRequest pwmRequest, final ResponseInfoBean responseInfoBean) throws PwmUnrecoverableException, ChaiUnavailableException, PwmOperationalException, ChaiValidationException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
final String userGUID = pwmSession.getUserInfo().getUserGuid();
pwmApplication.getCrService().writeResponses(pwmRequest.getUserInfoIfLoggedIn(), theUser, userGUID, responseInfoBean);
pwmSession.reloadUserInfoBean(pwmApplication);
pwmApplication.getStatisticsManager().incrementValue(Statistic.SETUP_RESPONSES);
pwmApplication.getAuditManager().submit(AuditEvent.SET_RESPONSES, pwmSession.getUserInfo(), pwmSession);
}
use of password.pwm.http.PwmSession 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.PwmSession 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;
}
use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class ChangePasswordServletUtil method executeChangePassword.
static void executeChangePassword(final PwmRequest pwmRequest, final PasswordData newPassword) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
// password accepted, setup change password
final ChangePasswordBean cpb = pwmApplication.getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
// change password
PasswordUtility.setActorPassword(pwmSession, pwmApplication, newPassword);
// init values for progress screen
{
final PasswordChangeProgressChecker.ProgressTracker tracker = new PasswordChangeProgressChecker.ProgressTracker();
final PasswordChangeProgressChecker checker = new PasswordChangeProgressChecker(pwmApplication, pwmSession.getUserInfo().getUserIdentity(), pwmSession.getLabel(), pwmSession.getSessionStateBean().getLocale());
cpb.setChangeProgressTracker(tracker);
cpb.setChangePasswordMaxCompletion(checker.maxCompletionTime(tracker));
}
// send user an email confirmation
ChangePasswordServletUtil.sendChangePasswordEmailNotice(pwmSession, pwmApplication);
// send audit event
pwmApplication.getAuditManager().submit(AuditEvent.CHANGE_PASSWORD, pwmSession.getUserInfo(), pwmSession);
}
Aggregations