Search in sources :

Example 51 with FormConfiguration

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

the class FormValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public FormValue fromJson(final String input) {
            if (input == null) {
                return new FormValue(Collections.<FormConfiguration>emptyList());
            } else {
                List<FormConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<FormConfiguration>>() {
                });
                srcList = srcList == null ? Collections.<FormConfiguration>emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new FormValue(Collections.unmodifiableList(srcList));
            }
        }

        public FormValue fromXmlElement(final Element settingElement, final PwmSecurityKey key) throws PwmOperationalException {
            final boolean oldType = PwmSettingSyntax.LOCALIZED_STRING_ARRAY.toString().equals(settingElement.getAttributeValue("syntax"));
            final List valueElements = settingElement.getChildren("value");
            final List<FormConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0 && loopValueElement.getAttribute("locale") == null) {
                    if (oldType) {
                        values.add(FormConfiguration.parseOldConfigString(value));
                    } else {
                        values.add(JsonUtil.deserialize(value, FormConfiguration.class));
                    }
                }
            }
            final FormValue formValue = new FormValue(values);
            formValue.needsXmlUpdate = oldType;
            return formValue;
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 52 with FormConfiguration

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

the class FormValue method toDebugString.

public String toDebugString(final Locale locale) {
    if (values != null && !values.isEmpty()) {
        final StringBuilder sb = new StringBuilder();
        for (final FormConfiguration formRow : values) {
            sb.append("FormItem Name:").append(formRow.getName()).append("\n");
            sb.append(" Type:").append(formRow.getType());
            sb.append(" Min:").append(formRow.getMinimumLength());
            sb.append(" Max:").append(formRow.getMaximumLength());
            sb.append(" ReadOnly:").append(formRow.isReadonly());
            sb.append(" Required:").append(formRow.isRequired());
            sb.append(" Confirm:").append(formRow.isConfirmationRequired());
            sb.append(" Unique:").append(formRow.isUnique());
            sb.append(" Multi-Value:").append(formRow.isMultivalue());
            sb.append(" Source:").append(formRow.getSource());
            sb.append("\n");
            sb.append(" Label:").append(JsonUtil.serializeMap(formRow.getLabels())).append("\n");
            sb.append(" Description:").append(JsonUtil.serializeMap(formRow.getDescription())).append("\n");
            if (formRow.getSelectOptions() != null && !formRow.getSelectOptions().isEmpty()) {
                sb.append(" Select Options: ").append(JsonUtil.serializeMap(formRow.getSelectOptions())).append("\n");
            }
            if (!StringUtil.isEmpty(formRow.getRegex())) {
                sb.append(" Regex:").append(formRow.getRegex()).append(" Regex Error:").append(JsonUtil.serializeMap(formRow.getRegexErrors())).append("\n");
            }
        }
        return sb.toString();
    } else {
        return "";
    }
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration)

Example 53 with FormConfiguration

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

the class GuestRegistrationServlet method determineUserDN.

private static String determineUserDN(final Map<FormConfiguration, String> formValues, final Configuration config) throws PwmUnrecoverableException {
    final String namingAttribute = config.getDefaultLdapProfile().readSettingAsString(PwmSetting.LDAP_NAMING_ATTRIBUTE);
    for (final Map.Entry<FormConfiguration, String> entry : formValues.entrySet()) {
        final FormConfiguration formItem = entry.getKey();
        if (namingAttribute.equals(formItem.getName())) {
            final String namingValue = entry.getValue();
            final String gestUserContextDN = config.readSettingAsString(PwmSetting.GUEST_CONTEXT);
            return namingAttribute + "=" + namingValue + "," + gestUserContextDN;
        }
    }
    final String errorMsg = "unable to determine new user DN due to missing form value for naming attribute '" + namingAttribute + '"';
    throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) FormConfiguration(password.pwm.config.value.data.FormConfiguration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Map(java.util.Map) FormMap(password.pwm.util.FormMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with FormConfiguration

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

the class ForgottenPasswordServlet method processSearch.

@ActionHandler(action = "search")
private ProcessStatus processSearch(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final Locale userLocale = pwmRequest.getLocale();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final String contextParam = pwmRequest.readParameterAsString(PwmConstants.PARAM_CONTEXT);
    final String ldapProfile = pwmRequest.readParameterAsString(PwmConstants.PARAM_LDAP_PROFILE);
    final boolean bogusUserModeEnabled = pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.RECOVERY_BOGUS_USER_ENABLE);
    // clear the bean
    clearForgottenPasswordBean(pwmRequest);
    if (CaptchaUtility.captchaEnabledForRequest(pwmRequest)) {
        if (!CaptchaUtility.verifyReCaptcha(pwmRequest)) {
            final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_BAD_CAPTCHA_RESPONSE);
            LOGGER.debug(pwmRequest, errorInfo);
            setLastError(pwmRequest, errorInfo);
            return ProcessStatus.Continue;
        }
    }
    final List<FormConfiguration> forgottenPasswordForm = pwmApplication.getConfig().readSettingAsForm(PwmSetting.FORGOTTEN_PASSWORD_SEARCH_FORM);
    Map<FormConfiguration, String> formValues = new LinkedHashMap<>();
    try {
        // read the values from the request
        formValues = FormUtility.readFormValuesFromRequest(pwmRequest, forgottenPasswordForm, userLocale);
        // check for intruder search values
        pwmApplication.getIntruderManager().convenience().checkAttributes(formValues);
        // see if the values meet the configured form requirements.
        FormUtility.validateFormValues(pwmRequest.getConfig(), formValues, userLocale);
        final String searchFilter;
        {
            final String configuredSearchFilter = pwmApplication.getConfig().readSettingAsString(PwmSetting.FORGOTTEN_PASSWORD_SEARCH_FILTER);
            if (configuredSearchFilter == null || configuredSearchFilter.isEmpty()) {
                searchFilter = FormUtility.ldapSearchFilterForForm(pwmApplication, forgottenPasswordForm);
                LOGGER.trace(pwmSession, "auto generated ldap search filter: " + searchFilter);
            } else {
                searchFilter = configuredSearchFilter;
            }
        }
        // convert the username field to an identity
        final UserIdentity userIdentity;
        {
            final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
            final SearchConfiguration searchConfiguration = SearchConfiguration.builder().filter(searchFilter).formValues(formValues).contexts(Collections.singletonList(contextParam)).ldapProfile(ldapProfile).build();
            userIdentity = userSearchEngine.performSingleUserSearch(searchConfiguration, pwmRequest.getSessionLabel());
        }
        if (userIdentity == null) {
            throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_CANT_MATCH_USER));
        }
        AuthenticationUtility.checkIfUserEligibleToAuthentication(pwmApplication, userIdentity);
        final ForgottenPasswordBean forgottenPasswordBean = forgottenPasswordBean(pwmRequest);
        ForgottenPasswordUtil.initForgottenPasswordBean(pwmRequest, userIdentity, forgottenPasswordBean);
        // clear intruder search values
        pwmApplication.getIntruderManager().convenience().clearAttributes(formValues);
        return ProcessStatus.Continue;
    } catch (PwmOperationalException e) {
        if (e.getError() != PwmError.ERROR_CANT_MATCH_USER || !bogusUserModeEnabled) {
            final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_RESPONSES_NORESPONSES, e.getErrorInformation().getDetailedErrorMsg(), e.getErrorInformation().getFieldValues());
            pwmApplication.getStatisticsManager().incrementValue(Statistic.RECOVERY_FAILURES);
            pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
            pwmApplication.getIntruderManager().convenience().markAttributes(formValues, pwmSession);
            LOGGER.debug(pwmSession, errorInfo.toDebugStr());
            setLastError(pwmRequest, errorInfo);
            return ProcessStatus.Continue;
        }
    }
    if (bogusUserModeEnabled) {
        ForgottenPasswordUtil.initBogusForgottenPasswordBean(pwmRequest);
        forgottenPasswordBean(pwmRequest).setUserSearchValues(FormUtility.asStringMap(formValues));
    }
    return ProcessStatus.Continue;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) UserIdentity(password.pwm.bean.UserIdentity) UserSearchEngine(password.pwm.ldap.search.UserSearchEngine) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) FormConfiguration(password.pwm.config.value.data.FormConfiguration) PwmSession(password.pwm.http.PwmSession) ForgottenPasswordBean(password.pwm.http.bean.ForgottenPasswordBean)

Example 55 with FormConfiguration

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

the class NewUserFormUtils method injectRemoteValuesIntoForm.

private static NewUserForm injectRemoteValuesIntoForm(final Map<FormConfiguration, String> userFormValues, final Map<String, String> injectedValues, final NewUserProfile newUserProfile, final PasswordData passwordData1, final PasswordData passwordData2) {
    final Map<String, String> newFormValues = new LinkedHashMap<>();
    newFormValues.putAll(FormUtility.asStringMap(userFormValues));
    final List<FormConfiguration> formConfigurations = newUserProfile.readSettingAsForm(PwmSetting.NEWUSER_FORM);
    if (injectedValues != null) {
        for (final FormConfiguration formConfiguration : formConfigurations) {
            final String name = formConfiguration.getName();
            final boolean formHasValue = !StringUtil.isEmpty(newFormValues.get(name));
            if (formConfiguration.isReadonly() || (!formHasValue && injectedValues.containsKey(name))) {
                newFormValues.put(formConfiguration.getName(), injectedValues.get(formConfiguration.getName()));
            }
        }
    }
    return new NewUserForm(newFormValues, passwordData1, passwordData2);
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

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