Search in sources :

Example 1 with UpdateProfileBean

use of password.pwm.http.bean.UpdateProfileBean in project pwm by pwm-project.

the class UpdateProfileServlet method nextStep.

protected void nextStep(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
    final UpdateProfileProfile updateProfileProfile = getProfile(pwmRequest);
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    {
        final String updateProfileAgreementText = updateProfileProfile.readSettingAsLocalizedString(PwmSetting.UPDATE_PROFILE_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
        if (!StringUtil.isEmpty(updateProfileAgreementText)) {
            if (!updateProfileBean.isAgreementPassed()) {
                final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
                final String expandedText = macroMachine.expandMacros(updateProfileAgreementText);
                pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
                pwmRequest.forwardToJsp(JspUrl.UPDATE_ATTRIBUTES_AGREEMENT);
                return;
            }
        }
    }
    // make sure there is form data in the bean.
    if (!updateProfileBean.isFormLdapLoaded()) {
        updateProfileBean.getFormData().clear();
        updateProfileBean.getFormData().putAll((UpdateProfileUtil.formDataFromLdap(pwmRequest, updateProfileProfile)));
        updateProfileBean.setFormLdapLoaded(true);
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    if (!updateProfileBean.isFormSubmitted()) {
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    // validate the form data.
    try {
        // verify form meets the form requirements
        final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
        final Map<FormConfiguration, String> formValues = FormUtility.readFormValuesFromMap(updateProfileBean.getFormData(), formFields, pwmRequest.getLocale());
        UpdateProfileUtil.verifyFormAttributes(pwmRequest.getPwmApplication(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getLocale(), formValues, true);
    } catch (PwmException e) {
        LOGGER.error(pwmSession, e.getMessage());
        setLastError(pwmRequest, e.getErrorInformation());
        UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
        return;
    }
    {
        final boolean requireConfirmation = updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_SHOW_CONFIRMATION);
        if (requireConfirmation && !updateProfileBean.isConfirmationPassed()) {
            UpdateProfileUtil.forwardToConfirmForm(pwmRequest, updateProfileProfile, updateProfileBean);
            return;
        }
    }
    if (UpdateProfileUtil.checkForTokenVerificationProgress(pwmRequest, updateProfileBean, updateProfileProfile) == ProcessStatus.Halt) {
        return;
    }
    try {
        // write the form values
        final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
        UpdateProfileUtil.doProfileUpdate(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getLocale(), pwmSession.getUserInfo(), pwmSession.getSessionManager().getMacroMachine(pwmApplication), updateProfileProfile, updateProfileBean.getFormData(), theUser);
        // re-populate the uiBean because we have changed some values.
        pwmSession.reloadUserInfoBean(pwmApplication);
        // clear cached read attributes.
        pwmRequest.getPwmSession().reloadUserInfoBean(pwmApplication);
        // mark the event log
        pwmApplication.getAuditManager().submit(AuditEvent.UPDATE_PROFILE, pwmSession.getUserInfo(), pwmSession);
        // clear the bean
        pwmApplication.getSessionStateService().clearBean(pwmRequest, UpdateProfileBean.class);
        pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_UpdateProfile);
        return;
    } catch (PwmException e) {
        LOGGER.error(pwmSession, e.getMessage());
        setLastError(pwmRequest, e.getErrorInformation());
    } catch (ChaiException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UPDATE_ATTRS_FAILURE, e.toString());
        LOGGER.error(pwmSession, errorInformation.toDebugStr());
        setLastError(pwmRequest, errorInformation);
    }
    UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
}
Also used : PwmApplication(password.pwm.PwmApplication) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration) PwmSession(password.pwm.http.PwmSession) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 2 with UpdateProfileBean

use of password.pwm.http.bean.UpdateProfileBean in project pwm by pwm-project.

the class UpdateProfileServlet method handleUpdateProfileRequest.

@ActionHandler(action = "updateProfile")
ProcessStatus handleUpdateProfileRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException {
    final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
    final UpdateProfileProfile updateProfileProfile = getProfile(pwmRequest);
    try {
        readFormParametersFromRequest(pwmRequest, updateProfileProfile, updateProfileBean);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest, e.getMessage());
        setLastError(pwmRequest, e.getErrorInformation());
    }
    updateProfileBean.setFormSubmitted(true);
    return ProcessStatus.Continue;
}
Also used : UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 3 with UpdateProfileBean

use of password.pwm.http.bean.UpdateProfileBean in project pwm by pwm-project.

the class UpdateProfileServlet method restValidateForm.

@ActionHandler(action = "validate")
ProcessStatus restValidateForm(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
    final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
    final UpdateProfileProfile updateProfileProfile = getProfile(pwmRequest);
    boolean success = true;
    String userMessage = Message.getLocalizedMessage(pwmRequest.getLocale(), Message.Success_UpdateForm, pwmRequest.getConfig());
    try {
        // read in the responses from the request
        final Map<FormConfiguration, String> formValues = UpdateProfileUtil.readFromJsonRequest(pwmRequest, updateProfileProfile, updateProfileBean);
        // verify form meets the form requirements
        UpdateProfileUtil.verifyFormAttributes(pwmRequest.getPwmApplication(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getLocale(), formValues, true);
        updateProfileBean.getFormData().putAll(FormUtility.asStringMap(formValues));
    } catch (PwmOperationalException e) {
        success = false;
        userMessage = e.getErrorInformation().toUserStr(pwmRequest.getPwmSession(), pwmRequest.getPwmApplication());
    }
    final ValidateResponse response = new ValidateResponse();
    response.setMessage(userMessage);
    response.setSuccess(success);
    pwmRequest.outputJsonResult(RestResultBean.withData(response));
    return ProcessStatus.Halt;
}
Also used : UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 4 with UpdateProfileBean

use of password.pwm.http.bean.UpdateProfileBean in project pwm by pwm-project.

the class UpdateProfileServlet method processReset.

@ActionHandler(action = "reset")
private ProcessStatus processReset(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ResetAction resetType = pwmRequest.readParameterAsEnum(PwmConstants.PARAM_RESET_TYPE, ResetAction.class, ResetAction.exitProfileUpdate);
    switch(resetType) {
        case unConfirm:
            final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
            updateProfileBean.setFormSubmitted(false);
            updateProfileBean.setConfirmationPassed(false);
            updateProfileBean.getCompletedTokenFields().clear();
            updateProfileBean.setTokenSent(false);
            updateProfileBean.setCurrentTokenField(null);
            break;
        case exitProfileUpdate:
            pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, UpdateProfileBean.class);
            pwmRequest.sendRedirectToContinue();
            return ProcessStatus.Halt;
        default:
            JavaHelper.unhandledSwitchStatement(resetType);
    }
    return ProcessStatus.Continue;
}
Also used : UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean)

Example 5 with UpdateProfileBean

use of password.pwm.http.bean.UpdateProfileBean in project pwm by pwm-project.

the class UpdateProfileServlet method handleAgreeRequest.

@ActionHandler(action = "agree")
ProcessStatus handleAgreeRequest(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException {
    LOGGER.debug(pwmRequest, "user accepted agreement");
    final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
    if (!updateProfileBean.isAgreementPassed()) {
        updateProfileBean.setAgreementPassed(true);
        final AuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createUserAuditRecord(AuditEvent.AGREEMENT_PASSED, pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel(), "UpdateProfile");
        pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
    }
    return ProcessStatus.Continue;
}
Also used : AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) UpdateProfileBean(password.pwm.http.bean.UpdateProfileBean) AuditRecord(password.pwm.svc.event.AuditRecord)

Aggregations

UpdateProfileBean (password.pwm.http.bean.UpdateProfileBean)7 UpdateProfileProfile (password.pwm.config.profile.UpdateProfileProfile)4 FormConfiguration (password.pwm.config.value.data.FormConfiguration)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiException (com.novell.ldapchai.exception.ChaiException)1 PwmApplication (password.pwm.PwmApplication)1 TokenDestinationItem (password.pwm.bean.TokenDestinationItem)1 PwmException (password.pwm.error.PwmException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 PwmSession (password.pwm.http.PwmSession)1 AuditRecord (password.pwm.svc.event.AuditRecord)1 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)1 MacroMachine (password.pwm.util.macro.MacroMachine)1