Search in sources :

Example 6 with FormConfiguration

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmDataValidationException(password.pwm.error.PwmDataValidationException) FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with FormConfiguration

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);
}
Also used : ChallengeSet(com.novell.ldapchai.cr.ChallengeSet) ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ForgottenPasswordBean(password.pwm.http.bean.ForgottenPasswordBean) Challenge(com.novell.ldapchai.cr.Challenge)

Example 8 with FormConfiguration

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) UserInfo(password.pwm.ldap.UserInfo) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 9 with FormConfiguration

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;
}
Also used : ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) DisplayElement(password.pwm.http.bean.DisplayElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with FormConfiguration

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;
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Instant(java.time.Instant) UserIdentity(password.pwm.bean.UserIdentity) HelpdeskProfile(password.pwm.config.profile.HelpdeskProfile) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) HelpdeskAuditRecord(password.pwm.svc.event.HelpdeskAuditRecord) ErrorInformation(password.pwm.error.ErrorInformation) AuditRecordFactory(password.pwm.svc.event.AuditRecordFactory) ChaiUser(com.novell.ldapchai.ChaiUser) List(java.util.List) ArrayList(java.util.ArrayList) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ChaiException(com.novell.ldapchai.exception.ChaiException) PwmSession(password.pwm.http.PwmSession) Map(java.util.Map) HashMap(java.util.HashMap) RestResultBean(password.pwm.ws.server.RestResultBean)

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