Search in sources :

Example 1 with NewUserProfile

use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.

the class ConfigurationChecker method doHealthCheck.

public List<HealthRecord> doHealthCheck(final PwmApplication pwmApplication) {
    if (pwmApplication.getConfig() == null) {
        return Collections.emptyList();
    }
    final Configuration config = pwmApplication.getConfig();
    final List<HealthRecord> records = new ArrayList<>();
    if (pwmApplication.getApplicationMode() == PwmApplicationMode.CONFIGURATION) {
        records.add(HealthRecord.forMessage(HealthMessage.Config_ConfigMode));
    }
    if (config.readSettingAsBoolean(PwmSetting.NEWUSER_ENABLE)) {
        for (final NewUserProfile newUserProfile : config.getNewUserProfiles().values()) {
            try {
                newUserProfile.getNewUserPasswordPolicy(pwmApplication, PwmConstants.DEFAULT_LOCALE);
            } catch (PwmUnrecoverableException e) {
                records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.Configuration, e.getMessage()));
            }
        }
    }
    records.addAll(doHealthCheck(config, PwmConstants.DEFAULT_LOCALE));
    return records;
}
Also used : Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 2 with NewUserProfile

use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.

the class NewUserFormUtils method readFromRequest.

static NewUserForm readFromRequest(final PwmRequest pwmRequest, final NewUserBean newUserBean) throws PwmDataValidationException, PwmUnrecoverableException {
    final Locale userLocale = pwmRequest.getLocale();
    final List<FormConfiguration> newUserForm = NewUserServlet.getFormDefinition(pwmRequest);
    final Map<FormConfiguration, String> userFormValues = FormUtility.readFormValuesFromRequest(pwmRequest, newUserForm, userLocale);
    final PasswordData passwordData1 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD1);
    final PasswordData passwordData2 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD2);
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    return injectRemoteValuesIntoForm(userFormValues, newUserBean.getRemoteInputData(), newUserProfile, passwordData1, passwordData2);
}
Also used : Locale(java.util.Locale) PasswordData(password.pwm.util.PasswordData) FormConfiguration(password.pwm.config.value.data.FormConfiguration) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 3 with NewUserProfile

use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.

the class NewUserFormUtils method readFromJsonRequest.

static NewUserForm readFromJsonRequest(final PwmRequest pwmRequest, final NewUserBean newUserBean) throws IOException, PwmUnrecoverableException, PwmDataValidationException {
    final Locale userLocale = pwmRequest.getLocale();
    final List<FormConfiguration> newUserForm = NewUserServlet.getFormDefinition(pwmRequest);
    final Map<String, String> jsonBodyMap = pwmRequest.readBodyAsJsonStringMap();
    final Map<FormConfiguration, String> userFormValues = FormUtility.readFormValuesFromMap(jsonBodyMap, newUserForm, userLocale);
    final PasswordData passwordData1 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD1) && !jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD1).isEmpty() ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD1)) : null;
    final PasswordData passwordData2 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD2) && !jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD2).isEmpty() ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD2)) : null;
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    return injectRemoteValuesIntoForm(userFormValues, newUserBean.getRemoteInputData(), newUserProfile, passwordData1, passwordData2);
}
Also used : Locale(java.util.Locale) PasswordData(password.pwm.util.PasswordData) FormConfiguration(password.pwm.config.value.data.FormConfiguration) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 4 with NewUserProfile

use of password.pwm.config.profile.NewUserProfile 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 5 with NewUserProfile

use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.

the class NewUserServlet method verifyForm.

static PasswordUtility.PasswordCheckInfo verifyForm(final PwmRequest pwmRequest, final NewUserForm newUserForm, final boolean allowResultCaching) throws PwmDataValidationException, PwmUnrecoverableException, ChaiUnavailableException {
    final Locale locale = pwmRequest.getLocale();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
    final List<FormConfiguration> formDefinition = newUserProfile.readSettingAsForm(PwmSetting.NEWUSER_FORM);
    final Map<FormConfiguration, String> formValueData = FormUtility.readFormValuesFromMap(newUserForm.getFormData(), formDefinition, locale);
    FormUtility.validateFormValues(pwmApplication.getConfig(), formValueData, locale);
    final List<FormUtility.ValidationFlag> validationFlags = new ArrayList<>();
    validationFlags.add(FormUtility.ValidationFlag.checkReadOnlyAndHidden);
    if (allowResultCaching) {
        validationFlags.add(FormUtility.ValidationFlag.allowResultCaching);
    }
    FormUtility.validateFormValueUniqueness(pwmApplication, formValueData, locale, Collections.emptyList(), validationFlags.toArray(new FormUtility.ValidationFlag[validationFlags.size()]));
    NewUserUtils.remoteVerifyFormData(pwmRequest, newUserForm);
    final UserInfo uiBean = UserInfoBean.builder().cachedPasswordRuleAttributes(FormUtility.asStringMap(formValueData)).passwordPolicy(newUserProfile.getNewUserPasswordPolicy(pwmApplication, locale)).build();
    final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
    if (promptForPassword) {
        return PasswordUtility.checkEnteredPassword(pwmApplication, locale, null, uiBean, null, newUserForm.getNewUserPassword(), newUserForm.getConfirmPassword());
    }
    return new PasswordUtility.PasswordCheckInfo(null, true, 0, PasswordUtility.PasswordCheckInfo.MatchStatus.MATCH, 0);
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) ArrayList(java.util.ArrayList) UserInfo(password.pwm.ldap.UserInfo) NewUserProfile(password.pwm.config.profile.NewUserProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration)

Aggregations

NewUserProfile (password.pwm.config.profile.NewUserProfile)15 ArrayList (java.util.ArrayList)5 FormConfiguration (password.pwm.config.value.data.FormConfiguration)5 ErrorInformation (password.pwm.error.ErrorInformation)5 NewUserBean (password.pwm.http.bean.NewUserBean)5 Locale (java.util.Locale)4 PwmApplication (password.pwm.PwmApplication)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 PwmSession (password.pwm.http.PwmSession)4 MacroMachine (password.pwm.util.macro.MacroMachine)4 LinkedHashMap (java.util.LinkedHashMap)3 PwmOperationalException (password.pwm.error.PwmOperationalException)3 PasswordData (password.pwm.util.PasswordData)3 Instant (java.time.Instant)2 Configuration (password.pwm.config.Configuration)2 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)2 PwmDataValidationException (password.pwm.error.PwmDataValidationException)2 TimeDuration (password.pwm.util.java.TimeDuration)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)1