Search in sources :

Example 36 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class UpdateProfileUtil method formDataFromLdap.

static Map<String, String> formDataFromLdap(final PwmRequest pwmRequest, final UpdateProfileProfile updateProfileProfile) throws PwmUnrecoverableException {
    final UserInfo userInfo = pwmRequest.getPwmSession().getUserInfo();
    final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
    final Map<FormConfiguration, String> formMap = new LinkedHashMap<>();
    FormUtility.populateFormMapFromLdap(formFields, pwmRequest.getSessionLabel(), formMap, userInfo);
    return FormUtility.asStringMap(formMap);
}
Also used : UserInfo(password.pwm.ldap.UserInfo) FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class UpdateProfileUtil method tokenDestinationItemForCurrentValidation.

static TokenDestinationItem tokenDestinationItemForCurrentValidation(final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean, final UpdateProfileProfile updateProfileProfile) {
    final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
    final LdapProfile ldapProfile = pwmRequest.getUserInfoIfLoggedIn().getLdapProfile(pwmRequest.getConfig());
    final Map<String, TokenDestinationItem.Type> tokenTypeMap = FormUtility.identifyFormItemsNeedingPotentialTokenValidation(ldapProfile, formFields);
    final String value = updateProfileBean.getFormData().get(updateProfileBean.getCurrentTokenField());
    final TokenDestinationItem.Type type = tokenTypeMap.get(updateProfileBean.getCurrentTokenField());
    return TokenDestinationItem.builder().display(value).id("1").value(value).type(type).build();
}
Also used : TokenType(password.pwm.svc.token.TokenType) FormConfiguration(password.pwm.config.value.data.FormConfiguration) LdapProfile(password.pwm.config.profile.LdapProfile) TokenDestinationItem(password.pwm.bean.TokenDestinationItem)

Example 38 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class UpdateProfileUtil method doProfileUpdate.

@SuppressWarnings("checkstyle:ParameterNumber")
public static void doProfileUpdate(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final Locale locale, final UserInfo userInfo, final MacroMachine macroMachine, final UpdateProfileProfile updateProfileProfile, final Map<String, String> formValues, final ChaiUser theUser) throws PwmUnrecoverableException, ChaiUnavailableException, PwmOperationalException {
    final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
    final Map<FormConfiguration, String> formMap = FormUtility.readFormValuesFromMap(formValues, formFields, locale);
    // verify form meets the form requirements (may be redundant, but shouldn't hurt)
    verifyFormAttributes(pwmApplication, userInfo.getUserIdentity(), locale, formMap, false);
    // write values.
    LOGGER.info("updating profile for " + userInfo.getUserIdentity());
    LdapOperationsHelper.writeFormValuesToLdap(pwmApplication, macroMachine, theUser, formMap, false);
    final UserIdentity userIdentity = userInfo.getUserIdentity();
    {
        // execute configured actions
        final List<ActionConfiguration> actions = updateProfileProfile.readSettingAsAction(PwmSetting.UPDATE_PROFILE_WRITE_ATTRIBUTES);
        if (actions != null && !actions.isEmpty()) {
            LOGGER.debug(sessionLabel, "executing configured actions to user " + userIdentity);
            final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
            actionExecutor.executeActions(actions, sessionLabel);
        }
    }
    sendProfileUpdateEmailNotice(pwmApplication, macroMachine, userInfo, locale, sessionLabel);
    // success, so forward to success page
    pwmApplication.getStatisticsManager().incrementValue(Statistic.UPDATE_ATTRIBUTES);
}
Also used : ActionExecutor(password.pwm.util.operations.ActionExecutor) UserIdentity(password.pwm.bean.UserIdentity) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration 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 40 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration 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)

Aggregations

FormConfiguration (password.pwm.config.value.data.FormConfiguration)63 LinkedHashMap (java.util.LinkedHashMap)26 ErrorInformation (password.pwm.error.ErrorInformation)23 Map (java.util.Map)19 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 PwmOperationalException (password.pwm.error.PwmOperationalException)14 List (java.util.List)13 UserIdentity (password.pwm.bean.UserIdentity)13 PwmApplication (password.pwm.PwmApplication)11 UserInfo (password.pwm.ldap.UserInfo)10 ChaiUser (com.novell.ldapchai.ChaiUser)9 Locale (java.util.Locale)9 PwmSession (password.pwm.http.PwmSession)9 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)9 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)8 Configuration (password.pwm.config.Configuration)7 PwmDataValidationException (password.pwm.error.PwmDataValidationException)7 UserSearchEngine (password.pwm.ldap.search.UserSearchEngine)7