Search in sources :

Example 11 with NewUserProfile

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

the class TokenService method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> returnRecords = new ArrayList<>();
    if (tokensAreUsedInConfig(configuration)) {
        if (errorInformation != null) {
            returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, errorInformation.toDebugStr()));
        }
    }
    if (storageMethod == TokenStorageMethod.STORE_LDAP) {
        if (configuration.readSettingAsBoolean(PwmSetting.NEWUSER_ENABLE)) {
            for (final NewUserProfile newUserProfile : configuration.getNewUserProfiles().values()) {
                if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_EMAIL_VERIFICATION)) {
                    final String label = PwmSetting.NEWUSER_EMAIL_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
                    final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
                    returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
                }
                if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_SMS_VERIFICATION)) {
                    final String label = PwmSetting.NEWUSER_SMS_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
                    final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
                    returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
                }
            }
        }
    }
    return returnRecords;
}
Also used : HealthRecord(password.pwm.health.HealthRecord) ArrayList(java.util.ArrayList) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 12 with NewUserProfile

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

the class NewUserServlet method forwardToFormPage.

private void forwardToFormPage(final PwmRequest pwmRequest, final NewUserBean newUserBean) throws ServletException, PwmUnrecoverableException, IOException {
    final List<FormConfiguration> formConfigurations = getFormDefinition(pwmRequest);
    final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
    final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
    final Map<FormConfiguration, String> formData = new HashMap<>();
    if (newUserBean.getRemoteInputData() != null) {
        final Map<String, String> remoteData = newUserBean.getRemoteInputData();
        for (final FormConfiguration formConfiguration : formConfigurations) {
            if (remoteData.containsKey(formConfiguration.getName())) {
                formData.put(formConfiguration, remoteData.get(formConfiguration.getName()));
            }
        }
    }
    pwmRequest.addFormInfoToRequestAttr(formConfigurations, formData, false, promptForPassword);
    {
        final boolean showBack = !newUserBean.isUrlSpecifiedProfile() && pwmRequest.getConfig().getNewUserProfiles().keySet().size() > 1;
        pwmRequest.setAttribute(PwmRequestAttribute.NewUser_FormShowBackButton, showBack);
    }
    pwmRequest.forwardToJsp(JspUrl.NEW_USER);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormConfiguration(password.pwm.config.value.data.FormConfiguration) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 13 with NewUserProfile

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

the class NewUserServlet method restCheckProgress.

@ActionHandler(action = "checkProgress")
private ProcessStatus restCheckProgress(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    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);
    final BigDecimal percentComplete;
    final boolean complete;
    // be sure minimum wait time has passed
    if (Instant.now().isAfter(completeTime)) {
        percentComplete = new BigDecimal("100");
        complete = true;
    } else {
        final TimeDuration elapsedTime = TimeDuration.fromCurrent(startTime);
        complete = false;
        percentComplete = new Percent(elapsedTime.getTotalMilliseconds(), minWaitTime).asBigDecimal();
    }
    final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
    outputMap.put("percentComplete", percentComplete);
    outputMap.put("complete", complete);
    final RestResultBean restResultBean = RestResultBean.withData(outputMap);
    LOGGER.trace(pwmRequest, "returning result for restCheckProgress: " + JsonUtil.serialize(restResultBean));
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) NewUserProfile(password.pwm.config.profile.NewUserProfile) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TimeDuration(password.pwm.util.java.TimeDuration) NewUserBean(password.pwm.http.bean.NewUserBean) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 14 with NewUserProfile

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

the class NewUserUtils method remoteSendFormData.

private static void remoteSendFormData(final PwmRequest pwmRequest, final NewUserForm newUserForm, final FormDataRequestBean.Mode mode) throws PwmUnrecoverableException, PwmDataValidationException {
    final RestFormDataClient restFormDataClient = new RestFormDataClient(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel());
    if (!restFormDataClient.isEnabled()) {
        return;
    }
    final NewUserBean newUserBean = NewUserServlet.getNewUserBean(pwmRequest);
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    final FormDataRequestBean.FormInfo formInfo = FormDataRequestBean.FormInfo.builder().mode(mode).moduleProfileID(newUserBean.getProfileID()).sessionID(pwmRequest.getPwmSession().getLoginInfoBean().getGuid()).module(FormDataRequestBean.FormType.NewUser).build();
    final FormDataRequestBean formDataRequestBean = FormDataRequestBean.builder().formInfo(formInfo).formConfigurations(newUserProfile.readSettingAsForm(PwmSetting.NEWUSER_FORM)).formValues(newUserForm.getFormData()).build();
    final FormDataResponseBean formDataResponseBean = restFormDataClient.invoke(formDataRequestBean, pwmRequest.getLocale());
    if (formDataResponseBean.isError()) {
        final ErrorInformation error = new ErrorInformation(PwmError.ERROR_REMOTE_ERROR_VALUE, formDataResponseBean.getErrorDetail(), new String[] { formDataResponseBean.getErrorMessage() });
        throw new PwmDataValidationException(error);
    }
}
Also used : FormDataResponseBean(password.pwm.ws.client.rest.form.FormDataResponseBean) ErrorInformation(password.pwm.error.ErrorInformation) PwmDataValidationException(password.pwm.error.PwmDataValidationException) RestFormDataClient(password.pwm.ws.client.rest.form.RestFormDataClient) FormDataRequestBean(password.pwm.ws.client.rest.form.FormDataRequestBean) NewUserBean(password.pwm.http.bean.NewUserBean) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 15 with NewUserProfile

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

the class NewUserUtils method determineUserDN.

static String determineUserDN(final PwmRequest pwmRequest, final NewUserForm formValues) throws PwmUnrecoverableException, ChaiUnavailableException {
    final MacroMachine macroMachine = createMacroMachineForNewUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), formValues, null);
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    final List<String> configuredNames = newUserProfile.readSettingAsStringArray(PwmSetting.NEWUSER_USERNAME_DEFINITION);
    final List<String> failedValues = new ArrayList<>();
    final String configuredContext = newUserProfile.readSettingAsString(PwmSetting.NEWUSER_CONTEXT);
    final String expandedContext = macroMachine.expandMacros(configuredContext);
    if (configuredNames == null || configuredNames.isEmpty() || configuredNames.iterator().next().isEmpty()) {
        final String namingAttribute = pwmRequest.getConfig().getDefaultLdapProfile().readSettingAsString(PwmSetting.LDAP_NAMING_ATTRIBUTE);
        String namingValue = null;
        for (final String formKey : formValues.getFormData().keySet()) {
            if (formKey.equals(namingAttribute)) {
                namingValue = formValues.getFormData().get(formKey);
            }
        }
        if (namingValue == null || namingValue.isEmpty()) {
            throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_NEW_USER_FAILURE, "username definition not set, and naming attribute is not present in form"));
        }
        final String escapedName = StringUtil.escapeLdapDN(namingValue);
        final String generatedDN = namingAttribute + "=" + escapedName + "," + expandedContext;
        NewUserUtils.LOGGER.debug(pwmRequest, "generated dn for new user: " + generatedDN);
        return generatedDN;
    }
    int attemptCount = 0;
    final String generatedDN;
    while (attemptCount < configuredNames.size()) {
        final String expandedName;
        {
            {
                final String configuredName = configuredNames.get(attemptCount);
                expandedName = macroMachine.expandMacros(configuredName);
            }
            if (!testIfEntryNameExists(pwmRequest, expandedName)) {
                NewUserUtils.LOGGER.trace(pwmRequest, "generated entry name for new user is unique: " + expandedName);
                final String namingAttribute = pwmRequest.getConfig().getDefaultLdapProfile().readSettingAsString(PwmSetting.LDAP_NAMING_ATTRIBUTE);
                final String escapedName = StringUtil.escapeLdapDN(expandedName);
                generatedDN = namingAttribute + "=" + escapedName + "," + expandedContext;
                NewUserUtils.LOGGER.debug(pwmRequest, "generated dn for new user: " + generatedDN);
                return generatedDN;
            } else {
                failedValues.add(expandedName);
            }
        }
        NewUserUtils.LOGGER.debug(pwmRequest, "generated entry name for new user is not unique, will try again");
        attemptCount++;
    }
    NewUserUtils.LOGGER.error(pwmRequest, "failed to generate new user DN after " + attemptCount + " attempts, failed values: " + JsonUtil.serializeCollection(failedValues));
    throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_NEW_USER_FAILURE, "unable to generate a unique DN value"));
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ArrayList(java.util.ArrayList) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) NewUserProfile(password.pwm.config.profile.NewUserProfile)

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