Search in sources :

Example 1 with PwmPasswordRule

use of password.pwm.config.profile.PwmPasswordRule in project pwm by pwm-project.

the class PublicUserInfoBean method fromUserInfoBean.

public static PublicUserInfoBean fromUserInfoBean(final UserInfo userInfoBean, final Configuration config, final Locale locale, final MacroMachine macroMachine) throws PwmUnrecoverableException {
    final PublicUserInfoBean publicUserInfoBean = new PublicUserInfoBean();
    publicUserInfoBean.userDN = (userInfoBean.getUserIdentity() == null) ? "" : userInfoBean.getUserIdentity().getUserDN();
    publicUserInfoBean.ldapProfile = (userInfoBean.getUserIdentity() == null) ? "" : userInfoBean.getUserIdentity().getLdapProfileID();
    publicUserInfoBean.userID = userInfoBean.getUsername();
    publicUserInfoBean.userGUID = publicUserInfoBean.getUserGUID();
    publicUserInfoBean.userEmailAddress = userInfoBean.getUserEmailAddress();
    publicUserInfoBean.userEmailAddress2 = userInfoBean.getUserEmailAddress2();
    publicUserInfoBean.userEmailAddress3 = userInfoBean.getUserEmailAddress3();
    publicUserInfoBean.userSmsNumber = userInfoBean.getUserSmsNumber();
    publicUserInfoBean.userSmsNumber2 = userInfoBean.getUserSmsNumber2();
    publicUserInfoBean.userSmsNumber3 = userInfoBean.getUserSmsNumber3();
    publicUserInfoBean.passwordExpirationTime = userInfoBean.getPasswordExpirationTime();
    publicUserInfoBean.passwordLastModifiedTime = userInfoBean.getPasswordLastModifiedTime();
    publicUserInfoBean.passwordStatus = userInfoBean.getPasswordStatus();
    publicUserInfoBean.accountExpirationTime = userInfoBean.getAccountExpirationTime();
    publicUserInfoBean.lastLoginTime = userInfoBean.getLastLdapLoginTime();
    publicUserInfoBean.requiresNewPassword = userInfoBean.isRequiresNewPassword();
    publicUserInfoBean.requiresResponseConfig = userInfoBean.isRequiresResponseConfig();
    publicUserInfoBean.requiresUpdateProfile = userInfoBean.isRequiresUpdateProfile();
    publicUserInfoBean.requiresOtpConfig = userInfoBean.isRequiresOtpConfig();
    publicUserInfoBean.requiresInteraction = userInfoBean.isRequiresInteraction();
    publicUserInfoBean.passwordPolicy = new HashMap<>();
    for (final PwmPasswordRule rule : PwmPasswordRule.values()) {
        publicUserInfoBean.passwordPolicy.put(rule.name(), userInfoBean.getPasswordPolicy().getValue(rule));
    }
    publicUserInfoBean.passwordRules = PasswordRequirementsTag.getPasswordRequirementsStrings(userInfoBean.getPasswordPolicy(), config, locale, macroMachine);
    if (userInfoBean.getCachedAttributeValues() != null && !userInfoBean.getCachedAttributeValues().isEmpty()) {
        publicUserInfoBean.attributes = Collections.unmodifiableMap(userInfoBean.getCachedAttributeValues());
    }
    return publicUserInfoBean;
}
Also used : PwmPasswordRule(password.pwm.config.profile.PwmPasswordRule)

Example 2 with PwmPasswordRule

use of password.pwm.config.profile.PwmPasswordRule in project pwm by pwm-project.

the class PwmPasswordRuleValidator method invokeExternalRuleMethods.

public List<ErrorInformation> invokeExternalRuleMethods(final Configuration config, final PwmPasswordPolicy pwmPasswordPolicy, final PasswordData password, final UserInfo userInfo) throws PwmUnrecoverableException {
    final List<ErrorInformation> returnedErrors = new ArrayList<>();
    final String restURL = config.readSettingAsString(PwmSetting.EXTERNAL_PWCHECK_REST_URLS);
    final boolean haltOnError = Boolean.parseBoolean(config.readAppProperty(AppProperty.WS_REST_CLIENT_PWRULE_HALTONERROR));
    final Map<String, Object> sendData = new LinkedHashMap<>();
    if (restURL == null || restURL.isEmpty()) {
        return Collections.emptyList();
    }
    {
        final String passwordStr = password == null ? "" : password.getStringValue();
        sendData.put("password", passwordStr);
    }
    if (pwmPasswordPolicy != null) {
        final LinkedHashMap<String, Object> policyData = new LinkedHashMap<>();
        for (final PwmPasswordRule rule : PwmPasswordRule.values()) {
            policyData.put(rule.name(), pwmPasswordPolicy.getValue(rule));
        }
        sendData.put("policy", policyData);
    }
    if (userInfo != null) {
        final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity());
        final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), locale, macroMachine);
        sendData.put("userInfo", publicUserInfoBean);
    }
    final String jsonRequestBody = JsonUtil.serializeMap(sendData);
    try {
        final String responseBody = RestClientHelper.makeOutboundRestWSCall(pwmApplication, locale, restURL, jsonRequestBody);
        final Map<String, Object> responseMap = JsonUtil.deserialize(responseBody, new TypeToken<Map<String, Object>>() {
        });
        if (responseMap.containsKey(REST_RESPONSE_KEY_ERROR) && Boolean.parseBoolean(responseMap.get(REST_RESPONSE_KEY_ERROR).toString())) {
            if (responseMap.containsKey(REST_RESPONSE_KEY_ERROR_MSG)) {
                final String errorMessage = responseMap.get(REST_RESPONSE_KEY_ERROR_MSG).toString();
                LOGGER.trace("external web service reported error: " + errorMessage);
                returnedErrors.add(new ErrorInformation(PwmError.PASSWORD_CUSTOM_ERROR, errorMessage, errorMessage, null));
            } else {
                LOGGER.trace("external web service reported error without specifying an errorMessage");
                returnedErrors.add(new ErrorInformation(PwmError.PASSWORD_CUSTOM_ERROR));
            }
        } else {
            LOGGER.trace("external web service did not report an error");
        }
    } catch (PwmOperationalException e) {
        final String errorMsg = "error executing external rule REST call: " + e.getMessage();
        LOGGER.error(errorMsg);
        if (haltOnError) {
            throw new PwmUnrecoverableException(e.getErrorInformation(), e);
        }
        throw new IllegalStateException("http response error code: " + e.getMessage());
    }
    return returnedErrors;
}
Also used : ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PublicUserInfoBean(password.pwm.bean.pub.PublicUserInfoBean) LinkedHashMap(java.util.LinkedHashMap) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) PwmPasswordRule(password.pwm.config.profile.PwmPasswordRule) MacroMachine(password.pwm.util.macro.MacroMachine) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with PwmPasswordRule

use of password.pwm.config.profile.PwmPasswordRule in project pwm by pwm-project.

the class Configuration method initPasswordPolicy.

protected PwmPasswordPolicy initPasswordPolicy(final String profile, final Locale locale) {
    final Map<String, String> passwordPolicySettings = new LinkedHashMap<>();
    for (final PwmPasswordRule rule : PwmPasswordRule.values()) {
        if (rule.getPwmSetting() != null || rule.getAppProperty() != null) {
            final String value;
            final PwmSetting pwmSetting = rule.getPwmSetting();
            switch(rule) {
                case DisallowedAttributes:
                case DisallowedValues:
                case CharGroupsValues:
                    value = StringHelper.stringCollectionToString(JavaTypeConverter.valueToStringArray(storedConfiguration.readSetting(pwmSetting, profile)), "\n");
                    break;
                case RegExMatch:
                case RegExNoMatch:
                    value = StringHelper.stringCollectionToString(JavaTypeConverter.valueToStringArray(storedConfiguration.readSetting(pwmSetting, profile)), ";;;");
                    break;
                case ChangeMessage:
                    value = JavaTypeConverter.valueToLocalizedString(storedConfiguration.readSetting(pwmSetting, profile), locale);
                    break;
                case ADComplexityLevel:
                    value = JavaTypeConverter.valueToEnum(pwmSetting, storedConfiguration.readSetting(pwmSetting, profile), ADPolicyComplexity.class).toString();
                    break;
                case AllowMacroInRegExSetting:
                    value = readAppProperty(AppProperty.ALLOW_MACRO_IN_REGEX_SETTING);
                    break;
                default:
                    value = String.valueOf(storedConfiguration.readSetting(pwmSetting, profile).toNativeObject());
            }
            passwordPolicySettings.put(rule.getKey(), value);
        }
    }
    // set case sensitivity
    final String caseSensitivitySetting = JavaTypeConverter.valueToString(storedConfiguration.readSetting(PwmSetting.PASSWORD_POLICY_CASE_SENSITIVITY));
    if (!"read".equals(caseSensitivitySetting)) {
        passwordPolicySettings.put(PwmPasswordRule.CaseSensitive.getKey(), caseSensitivitySetting);
    }
    // set pwm-specific values
    final PwmPasswordPolicy passwordPolicy = PwmPasswordPolicy.createPwmPasswordPolicy(passwordPolicySettings);
    passwordPolicy.setProfileID(profile);
    {
        final List<UserPermission> queryMatch = (List<UserPermission>) storedConfiguration.readSetting(PwmSetting.PASSWORD_POLICY_QUERY_MATCH, profile).toNativeObject();
        passwordPolicy.setUserPermissions(queryMatch);
    }
    passwordPolicy.setRuleText(JavaTypeConverter.valueToLocalizedString(storedConfiguration.readSetting(PwmSetting.PASSWORD_POLICY_RULE_TEXT, profile), locale));
    return passwordPolicy;
}
Also used : PwmPasswordRule(password.pwm.config.profile.PwmPasswordRule) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) List(java.util.List) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) UserPermission(password.pwm.config.value.data.UserPermission)

Example 4 with PwmPasswordRule

use of password.pwm.config.profile.PwmPasswordRule in project pwm by pwm-project.

the class HelpdeskDetailInfoBean method makePasswordPolicyRules.

private static Map<String, String> makePasswordPolicyRules(final UserInfo userInfo, final Locale locale, final Configuration configuration) throws PwmUnrecoverableException {
    final Map<String, String> passwordRules = new LinkedHashMap<>();
    if (userInfo.getPasswordPolicy() != null) {
        for (final PwmPasswordRule rule : PwmPasswordRule.values()) {
            if (userInfo.getPasswordPolicy().getValue(rule) != null) {
                if (ChaiPasswordRule.RuleType.BOOLEAN == rule.getRuleType()) {
                    final boolean value = Boolean.parseBoolean(userInfo.getPasswordPolicy().getValue(rule));
                    final String sValue = LocaleHelper.booleanString(value, locale, configuration);
                    passwordRules.put(rule.getLabel(locale, configuration), sValue);
                } else {
                    passwordRules.put(rule.getLabel(locale, configuration), userInfo.getPasswordPolicy().getValue(rule));
                }
            }
        }
    }
    return Collections.unmodifiableMap(passwordRules);
}
Also used : PwmPasswordRule(password.pwm.config.profile.PwmPasswordRule) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PwmPasswordRule (password.pwm.config.profile.PwmPasswordRule)4 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 Map (java.util.Map)1 PublicUserInfoBean (password.pwm.bean.pub.PublicUserInfoBean)1 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)1 UserPermission (password.pwm.config.value.data.UserPermission)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 MacroMachine (password.pwm.util.macro.MacroMachine)1