use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class FormUtility method readFormValuesFromMap.
public static Map<FormConfiguration, String> readFormValuesFromMap(final Map<String, String> inputMap, final Collection<FormConfiguration> formItems, final Locale locale) throws PwmDataValidationException, PwmUnrecoverableException {
if (formItems == null || formItems.isEmpty()) {
return Collections.emptyMap();
}
final Map<FormConfiguration, String> returnMap = new LinkedHashMap<>();
if (inputMap == null) {
return returnMap;
}
for (final FormConfiguration formItem : formItems) {
final String keyName = formItem.getName();
final String value = inputMap.get(keyName);
if (formItem.isRequired() && !formItem.isReadonly()) {
if (StringUtil.isEmpty(value)) {
final String errorMsg = "missing required value for field '" + formItem.getName() + "'";
final ErrorInformation error = new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg, new String[] { formItem.getLabel(locale) });
throw new PwmDataValidationException(error);
}
}
if (formItem.isConfirmationRequired()) {
final String confirmValue = inputMap.get(keyName + Validator.PARAM_CONFIRM_SUFFIX);
if (confirmValue == null || !confirmValue.equals(value)) {
final String errorMsg = "incorrect confirmation value for field '" + formItem.getName() + "'";
final ErrorInformation error = new ErrorInformation(PwmError.ERROR_FIELD_BAD_CONFIRM, errorMsg, new String[] { formItem.getLabel(locale) });
throw new PwmDataValidationException(error);
}
}
if (formItem.getType() == FormConfiguration.Type.checkbox) {
final String parsedValue = parseInputValueToFormValue(formItem, value);
returnMap.put(formItem, parsedValue);
} else if (value != null && !formItem.isReadonly()) {
final String parsedValue = parseInputValueToFormValue(formItem, value);
returnMap.put(formItem, parsedValue);
}
}
return returnMap;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class ForgottenPasswordUtil method initBogusForgottenPasswordBean.
static void initBogusForgottenPasswordBean(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
final ForgottenPasswordBean forgottenPasswordBean = ForgottenPasswordServlet.forgottenPasswordBean(pwmRequest);
forgottenPasswordBean.setUserIdentity(null);
forgottenPasswordBean.setPresentableChallengeSet(null);
final List<Challenge> challengeList = new ArrayList<>();
{
final String firstProfile = pwmRequest.getConfig().getChallengeProfileIDs().iterator().next();
final ChallengeSet challengeSet = pwmRequest.getConfig().getChallengeProfile(firstProfile, PwmConstants.DEFAULT_LOCALE).getChallengeSet();
challengeList.addAll(challengeSet.getRequiredChallenges());
for (int i = 0; i < challengeSet.getMinRandomRequired(); i++) {
challengeList.add(challengeSet.getRandomChallenges().get(i));
}
}
final List<FormConfiguration> formData = new ArrayList<>();
{
int counter = 0;
for (Challenge challenge : challengeList) {
final FormConfiguration formConfiguration = FormConfiguration.builder().name("challenge" + counter++).type(FormConfiguration.Type.text).labels(Collections.singletonMap("", challenge.getChallengeText())).minimumLength(challenge.getMinLength()).maximumLength(challenge.getMaxLength()).source(FormConfiguration.Source.bogus).build();
formData.add(formConfiguration);
}
}
forgottenPasswordBean.setAttributeForm(formData);
forgottenPasswordBean.setBogusUser(true);
{
final String profileID = pwmRequest.getConfig().getForgottenPasswordProfiles().keySet().iterator().next();
forgottenPasswordBean.setForgottenPasswordProfileID(profileID);
}
final ForgottenPasswordBean.RecoveryFlags recoveryFlags = new ForgottenPasswordBean.RecoveryFlags(false, Collections.singleton(IdentityVerificationMethod.ATTRIBUTES), Collections.emptySet(), 0);
forgottenPasswordBean.setRecoveryFlags(recoveryFlags);
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class ForgottenPasswordUtil method figureAttributeForm.
static List<FormConfiguration> figureAttributeForm(final ForgottenPasswordProfile forgottenPasswordProfile, final ForgottenPasswordBean forgottenPasswordBean, final PwmRequest pwmRequest, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmOperationalException, PwmUnrecoverableException {
final List<FormConfiguration> requiredAttributesForm = forgottenPasswordProfile.readSettingAsForm(PwmSetting.RECOVERY_ATTRIBUTE_FORM);
if (requiredAttributesForm.isEmpty()) {
return requiredAttributesForm;
}
final UserInfo userInfo = readUserInfo(pwmRequest, forgottenPasswordBean);
final List<FormConfiguration> returnList = new ArrayList<>();
for (final FormConfiguration formItem : requiredAttributesForm) {
if (formItem.isRequired()) {
returnList.add(formItem);
} else {
try {
final String currentValue = userInfo.readStringAttribute(formItem.getName());
if (currentValue != null && currentValue.length() > 0) {
returnList.add(formItem);
} else {
LOGGER.trace(pwmRequest, "excluding optional required attribute(" + formItem.getName() + "), user has no value");
}
} catch (PwmUnrecoverableException e) {
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_NO_CHALLENGES, "unexpected error reading value for attribute " + formItem.getName()));
}
}
}
if (returnList.isEmpty()) {
throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_NO_CHALLENGES, "user has no values for any optional attribute"));
}
return returnList;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class HelpdeskDetailInfoBean method getProfileData.
private static List<DisplayElement> getProfileData(final HelpdeskProfile helpdeskProfile, final UserInfo userInfo, final SessionLabel sessionLabel, final Locale actorLocale) throws PwmUnrecoverableException {
final List<FormConfiguration> detailFormConfig = helpdeskProfile.readSettingAsForm(PwmSetting.HELPDESK_DETAIL_FORM);
final Map<FormConfiguration, List<String>> formData = FormUtility.populateFormMapFromLdap(detailFormConfig, sessionLabel, userInfo);
final List<DisplayElement> profileData = new ArrayList<>();
for (final Map.Entry<FormConfiguration, List<String>> entry : formData.entrySet()) {
final FormConfiguration formConfiguration = entry.getKey();
if (formConfiguration.isMultivalue()) {
profileData.add(new DisplayElement(formConfiguration.getName(), DisplayElement.Type.multiString, formConfiguration.getLabel(actorLocale), entry.getValue()));
} else {
final String value = JavaHelper.isEmpty(entry.getValue()) ? "" : entry.getValue().iterator().next();
profileData.add(new DisplayElement(formConfiguration.getName(), DisplayElement.Type.string, formConfiguration.getLabel(actorLocale), value));
}
}
return profileData;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class HelpdeskServlet method restValidateAttributes.
@ActionHandler(action = "validateAttributes")
private ProcessStatus restValidateAttributes(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException {
final HelpdeskProfile helpdeskProfile = getHelpdeskProfile(pwmRequest);
final Instant startTime = Instant.now();
final String bodyString = pwmRequest.readRequestBodyAsString();
final HelpdeskVerificationRequestBean helpdeskVerificationRequestBean = JsonUtil.deserialize(bodyString, HelpdeskVerificationRequestBean.class);
final UserIdentity userIdentity = UserIdentity.fromKey(helpdeskVerificationRequestBean.getUserKey(), pwmRequest.getPwmApplication());
boolean passed = false;
{
final List<FormConfiguration> verificationForms = helpdeskProfile.readSettingAsForm(PwmSetting.HELPDESK_VERIFICATION_FORM);
if (verificationForms == null || verificationForms.isEmpty()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "attempt to verify ldap attributes with no ldap verification attributes configured");
throw new PwmUnrecoverableException(errorInformation);
}
final Map<String, String> bodyMap = JsonUtil.deserializeStringMap(bodyString);
final ChaiUser chaiUser;
try {
chaiUser = getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
} catch (ChaiUnavailableException e) {
throw new PwmUnrecoverableException(PwmError.forChaiError(e.getErrorCode()));
}
int successCount = 0;
for (final FormConfiguration formConfiguration : verificationForms) {
final String name = formConfiguration.getName();
final String suppliedValue = bodyMap.get(name);
try {
if (chaiUser.compareStringAttribute(name, suppliedValue)) {
successCount++;
}
} catch (ChaiException e) {
LOGGER.error(pwmRequest, "error comparing ldap attribute during verification " + e.getMessage());
}
}
if (successCount == verificationForms.size()) {
passed = true;
}
}
final HelpdeskVerificationStateBean verificationStateBean = HelpdeskVerificationStateBean.fromClientString(pwmRequest, helpdeskVerificationRequestBean.getVerificationState());
if (passed) {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final HelpdeskAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createHelpdeskAuditRecord(AuditEvent.HELPDESK_VERIFY_ATTRIBUTES, pwmSession.getUserInfo().getUserIdentity(), null, userIdentity, pwmSession.getSessionStateBean().getSrcAddress(), pwmSession.getSessionStateBean().getSrcHostname());
pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
verificationStateBean.addRecord(userIdentity, IdentityVerificationMethod.ATTRIBUTES);
} else {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final HelpdeskAuditRecord auditRecord = new AuditRecordFactory(pwmRequest).createHelpdeskAuditRecord(AuditEvent.HELPDESK_VERIFY_ATTRIBUTES_INCORRECT, pwmSession.getUserInfo().getUserIdentity(), null, userIdentity, pwmSession.getSessionStateBean().getSrcAddress(), pwmSession.getSessionStateBean().getSrcHostname());
pwmRequest.getPwmApplication().getAuditManager().submit(auditRecord);
}
// add a delay to prevent continuous checks
final long delayMs = Long.parseLong(pwmRequest.getConfig().readAppProperty(AppProperty.HELPDESK_VERIFICATION_INVALID_DELAY_MS));
while (TimeDuration.fromCurrent(startTime).isShorterThan(delayMs)) {
JavaHelper.pause(100);
}
final HelpdeskVerificationResponseBean responseBean = new HelpdeskVerificationResponseBean(passed, verificationStateBean.toClientString(pwmRequest.getPwmApplication()));
final RestResultBean restResultBean = RestResultBean.withData(responseBean);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
Aggregations