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