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);
}
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;
}
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;
}
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();
}
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;
}
Aggregations