Search in sources :

Example 21 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class NewUserServlet method nextStep.

@Override
protected void nextStep(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
    final NewUserBean newUserBean = getNewUserBean(pwmRequest);
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    if (newUserBean.getProfileID() == null) {
        final Set<String> newUserProfileIDs = pwmApplication.getConfig().getNewUserProfiles().keySet();
        if (newUserProfileIDs.isEmpty()) {
            pwmRequest.respondWithError(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "no new user profiles are defined"));
            return;
        }
        final LinkedHashMap<String, String> visibleProfiles = new LinkedHashMap<>(NewUserUtils.figureDisplayableProfiles(pwmRequest));
        if (visibleProfiles.size() == 1) {
            final String singleID = newUserProfileIDs.iterator().next();
            LOGGER.trace(pwmRequest, "only one new user profile is defined, auto-selecting profile " + singleID);
            newUserBean.setProfileID(singleID);
        } else {
            LOGGER.trace(pwmRequest, "new user profile not yet selected, redirecting to choice page");
            pwmRequest.setAttribute(PwmRequestAttribute.NewUser_VisibleProfiles, visibleProfiles);
            pwmRequest.forwardToJsp(JspUrl.NEW_USER_PROFILE_CHOICE);
            return;
        }
    }
    final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
    if (newUserBean.getCreateStartTime() != null) {
        forwardToWait(pwmRequest, newUserProfile);
        return;
    }
    // try to read the new user policy to make sure it's readable, that way an exception is thrown here instead of by the jsp
    newUserProfile.getNewUserPasswordPolicy(pwmApplication, pwmSession.getSessionStateBean().getLocale());
    if (!newUserBean.isFormPassed()) {
        if (showFormPage(newUserProfile)) {
            forwardToFormPage(pwmRequest, newUserBean);
            return;
        } else {
            NewUserFormUtils.injectRemoteValuesIntoForm(newUserBean, newUserProfile);
            try {
                verifyForm(pwmRequest, newUserBean.getNewUserForm(), false);
            } catch (PwmDataValidationException e) {
                throw new PwmUnrecoverableException(e.getErrorInformation());
            }
            newUserBean.setFormPassed(true);
        }
    }
    if (NewUserUtils.checkForTokenVerificationProgress(pwmRequest, newUserBean, newUserProfile) == ProcessStatus.Halt) {
        return;
    }
    final String newUserAgreementText = newUserProfile.readSettingAsLocalizedString(PwmSetting.NEWUSER_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
    if (!StringUtil.isEmpty(newUserAgreementText)) {
        if (!newUserBean.isAgreementPassed()) {
            final MacroMachine macroMachine = NewUserUtils.createMacroMachineForNewUser(pwmApplication, pwmRequest.getSessionLabel(), newUserBean.getNewUserForm(), null);
            final String expandedText = macroMachine.expandMacros(newUserAgreementText);
            pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
            pwmRequest.forwardToJsp(JspUrl.NEW_USER_AGREEMENT);
            return;
        }
    }
    // success so create the new user.
    final String newUserDN = NewUserUtils.determineUserDN(pwmRequest, newUserBean.getNewUserForm());
    try {
        NewUserUtils.createUser(newUserBean.getNewUserForm(), pwmRequest, newUserDN);
        newUserBean.setCreateStartTime(Instant.now());
        forwardToWait(pwmRequest, newUserProfile);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest, "error during user creation: " + e.getMessage());
        if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_DELETE_ON_FAIL)) {
            NewUserUtils.deleteUserAccount(newUserDN, pwmRequest);
        }
        LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
        pwmRequest.respondWithError(e.getErrorInformation());
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) NewUserProfile(password.pwm.config.profile.NewUserProfile) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) PwmDataValidationException(password.pwm.error.PwmDataValidationException) MacroMachine(password.pwm.util.macro.MacroMachine) NewUserBean(password.pwm.http.bean.NewUserBean) PwmSession(password.pwm.http.PwmSession)

Example 22 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class NewUserServlet method handleComplete.

@ActionHandler(action = "complete")
private ProcessStatus handleComplete(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException {
    final NewUserBean newUserBean = getNewUserBean(pwmRequest);
    final Instant startTime = newUserBean.getCreateStartTime();
    if (startTime == null) {
        pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
        return ProcessStatus.Halt;
    }
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
    final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
    // be sure minimum wait time has passed
    if (Instant.now().isBefore(completeTime)) {
        pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
        return ProcessStatus.Halt;
    }
    // -- process complete -- \\
    pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, NewUserBean.class);
    final String configuredRedirectUrl = newUserProfile.readSettingAsString(PwmSetting.NEWUSER_REDIRECT_URL);
    if (!StringUtil.isEmpty(configuredRedirectUrl) && StringUtil.isEmpty(pwmRequest.getPwmSession().getSessionStateBean().getForwardURL())) {
        final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
        final String macroedUrl = macroMachine.expandMacros(configuredRedirectUrl);
        pwmRequest.sendRedirect(macroedUrl);
        return ProcessStatus.Halt;
    }
    pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_CreateUser);
    return ProcessStatus.Halt;
}
Also used : Instant(java.time.Instant) MacroMachine(password.pwm.util.macro.MacroMachine) NewUserBean(password.pwm.http.bean.NewUserBean) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 23 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class PeopleSearchDataReader method figureDisplaynames.

private List<String> figureDisplaynames(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final List<String> displayLabels = new ArrayList<>();
    final List<String> displayStringSettings = pwmRequest.getConfig().readSettingAsStringArray(PwmSetting.PEOPLE_SEARCH_DISPLAY_NAMES_CARD_LABELS);
    if (displayStringSettings != null) {
        final MacroMachine macroMachine = getMacroMachine(userIdentity);
        for (final String displayStringSetting : displayStringSettings) {
            final String displayLabel = macroMachine.expandMacros(displayStringSetting);
            displayLabels.add(displayLabel);
        }
    }
    return displayLabels;
}
Also used : ArrayList(java.util.ArrayList) MacroMachine(password.pwm.util.macro.MacroMachine)

Example 24 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class PeopleSearchDataReader method figureDisplaynameValue.

private String figureDisplaynameValue(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final MacroMachine macroMachine = getMacroMachine(userIdentity);
    final String settingValue = pwmRequest.getConfig().readSettingAsString(PwmSetting.PEOPLE_SEARCH_DISPLAY_NAME);
    return macroMachine.expandMacros(settingValue);
}
Also used : MacroMachine(password.pwm.util.macro.MacroMachine)

Example 25 with MacroMachine

use of password.pwm.util.macro.MacroMachine 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)

Aggregations

MacroMachine (password.pwm.util.macro.MacroMachine)61 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)20 Locale (java.util.Locale)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Configuration (password.pwm.config.Configuration)13 UserInfo (password.pwm.ldap.UserInfo)13 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 PwmApplication (password.pwm.PwmApplication)12 FormConfiguration (password.pwm.config.value.data.FormConfiguration)12 ChaiUser (com.novell.ldapchai.ChaiUser)10 PwmException (password.pwm.error.PwmException)10 List (java.util.List)9 EmailItemBean (password.pwm.bean.EmailItemBean)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 Map (java.util.Map)8 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)8 PwmSession (password.pwm.http.PwmSession)8 Instant (java.time.Instant)7