Search in sources :

Example 1 with FormConfiguration

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

the class LdapOperationsHelper method writeFormValuesToLdap.

/**
 * Writes a Map of form values to ldap onto the supplied user object.
 * The map key must be a string of attribute names.
 * <p/>
 * Any ldap operation exceptions are not reported (but logged).
 *
 * @param theUser    User to write to
 * @param formValues A map with {@link FormConfiguration} keys and String values.
 * @throws ChaiUnavailableException if the directory is unavailable
 * @throws PwmOperationalException  if their is an unexpected ldap problem
 */
public static void writeFormValuesToLdap(final PwmApplication pwmApplication, final MacroMachine macroMachine, final ChaiUser theUser, final Map<FormConfiguration, String> formValues, final boolean expandMacros) throws ChaiUnavailableException, PwmOperationalException, PwmUnrecoverableException {
    final Map<String, String> tempMap = new HashMap<>();
    for (final Map.Entry<FormConfiguration, String> entry : formValues.entrySet()) {
        final FormConfiguration formItem = entry.getKey();
        if (!formItem.isReadonly()) {
            tempMap.put(formItem.getName(), entry.getValue());
        }
    }
    writeMapToLdap(theUser, tempMap, macroMachine, expandMacros);
}
Also used : HashMap(java.util.HashMap) FormConfiguration(password.pwm.config.value.data.FormConfiguration) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with FormConfiguration

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

the class UserInfoReader method isRequiresUpdateProfile.

@Override
public boolean isRequiresUpdateProfile() throws PwmUnrecoverableException {
    final Configuration configuration = pwmApplication.getConfig();
    if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_ENABLE)) {
        LOGGER.debug(sessionLabel, "checkProfiles: " + userIdentity.toString() + " profile module is not enabled");
        return false;
    }
    UpdateProfileProfile updateProfileProfile = null;
    final Map<ProfileType, String> profileIDs = selfCachedReference.getProfileIDs();
    if (profileIDs.containsKey(ProfileType.UpdateAttributes)) {
        updateProfileProfile = configuration.getUpdateAttributesProfile().get(profileIDs.get(ProfileType.UpdateAttributes));
    }
    if (updateProfileProfile == null) {
        return false;
    }
    if (!updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_FORCE_SETUP)) {
        LOGGER.debug(sessionLabel, "checkProfiles: " + userIdentity.toString() + " profile force setup is not enabled");
        return false;
    }
    final List<FormConfiguration> updateFormFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
    try {
        final Map<FormConfiguration, List<String>> valueMap = FormUtility.populateFormMapFromLdap(updateFormFields, sessionLabel, selfCachedReference, FormUtility.Flag.ReturnEmptyValues);
        final Map<FormConfiguration, String> singleValueMap = FormUtility.multiValueMapToSingleValue(valueMap);
        FormUtility.validateFormValues(configuration, singleValueMap, locale);
        LOGGER.debug(sessionLabel, "checkProfile: " + userIdentity + " has value for attributes, update profile will not be required");
        return false;
    } catch (PwmDataValidationException e) {
        LOGGER.debug(sessionLabel, "checkProfile: " + userIdentity + " does not have good attributes (" + e.getMessage() + "), update profile will be required");
        return true;
    } catch (PwmUnrecoverableException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : PwmDataValidationException(password.pwm.error.PwmDataValidationException) ProfileType(password.pwm.config.profile.ProfileType) FormConfiguration(password.pwm.config.value.data.FormConfiguration) Configuration(password.pwm.config.Configuration) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration) List(java.util.List) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 3 with FormConfiguration

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

the class FormUtility method identifyFormItemsNeedingPotentialTokenValidation.

public static Map<String, TokenDestinationItem.Type> identifyFormItemsNeedingPotentialTokenValidation(final LdapProfile ldapProfile, final Collection<FormConfiguration> formConfigurations) {
    final Map<PwmSetting, TokenDestinationItem.Type> settingTypeMap = TokenDestinationItem.getSettingToDestTypeMap();
    final Map<String, TokenDestinationItem.Type> returnObj = new LinkedHashMap<>();
    for (final Map.Entry<PwmSetting, TokenDestinationItem.Type> entry : settingTypeMap.entrySet()) {
        final String attrName = ldapProfile.readSettingAsString(entry.getKey());
        if (!StringUtil.isEmpty(attrName)) {
            for (final FormConfiguration formConfiguration : formConfigurations) {
                if (attrName.equalsIgnoreCase(formConfiguration.getName())) {
                    returnObj.put(attrName, entry.getValue());
                }
            }
        }
    }
    return returnObj;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) FormConfiguration(password.pwm.config.value.data.FormConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with FormConfiguration

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

the class FormUtility method ldapSearchFilterForForm.

public static String ldapSearchFilterForForm(final PwmApplication pwmApplication, final Collection<FormConfiguration> formElements) throws PwmUnrecoverableException {
    if (formElements == null || formElements.isEmpty()) {
        final String errorMsg = "can not auto-generate ldap search filter for form with no required form items";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { errorMsg });
        throw new PwmUnrecoverableException(errorInformation);
    }
    final StringBuilder sb = new StringBuilder();
    sb.append("(&");
    final List<String> objectClasses = pwmApplication.getConfig().readSettingAsStringArray(PwmSetting.DEFAULT_OBJECT_CLASSES);
    if (objectClasses != null && !objectClasses.isEmpty()) {
        if (objectClasses.size() == 1) {
            sb.append("(objectclass=");
            sb.append(objectClasses.iterator().next());
            sb.append(")");
        } else {
            sb.append("(|");
            for (final String objectClassValue : objectClasses) {
                sb.append("(objectclass=");
                sb.append(objectClassValue);
                sb.append(")");
            }
            sb.append(")");
        }
    }
    for (final FormConfiguration formConfiguration : formElements) {
        final String formElementName = formConfiguration.getName();
        sb.append("(");
        sb.append(formElementName);
        sb.append("=");
        sb.append("%").append(formElementName).append("%");
        sb.append(")");
    }
    sb.append(")");
    return sb.toString();
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) FormConfiguration(password.pwm.config.value.data.FormConfiguration)

Example 5 with FormConfiguration

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

the class FormUtility method multiValueMapToSingleValue.

public static Map<FormConfiguration, String> multiValueMapToSingleValue(final Map<FormConfiguration, List<String>> input) {
    final Map<FormConfiguration, String> returnMap = new LinkedHashMap<>();
    for (final Map.Entry<FormConfiguration, List<String>> entry : input.entrySet()) {
        final FormConfiguration formConfiguration = entry.getKey();
        final List<String> listValue = entry.getValue();
        final String value = listValue != null && !listValue.isEmpty() ? listValue.iterator().next() : null;
        returnMap.put(formConfiguration, value);
    }
    return returnMap;
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) 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