Fix OPENDJ-665 Attribute Value Password Validator should implement check-substrings
| | |
| | | ds-cfg-java-class: org.opends.server.extensions.AttributeValuePasswordValidator |
| | | ds-cfg-enabled: true |
| | | ds-cfg-test-reversed-password: true |
| | | ds-cfg-check-substrings: true |
| | | |
| | | dn: cn=Character Set,cn=Password Validators,cn=config |
| | | objectClass: top |
| | |
| | | SUP ds-cfg-password-validator |
| | | STRUCTURAL |
| | | MUST ds-cfg-test-reversed-password |
| | | MAY ds-cfg-match-attribute |
| | | MAY ( ds-cfg-match-attribute $ |
| | | ds-cfg-check-substrings $ |
| | | ds-cfg-min-substring-length ) |
| | | X-ORIGIN 'OpenDS Directory Server' ) |
| | | objectClasses: ( 1.3.6.1.4.1.26027.1.2.96 |
| | | NAME 'ds-cfg-character-set-password-validator' |
| | |
| | | ! |
| | | ! |
| | | ! Copyright 2007-2008 Sun Microsystems, Inc. |
| | | ! Portions Copyright 2012 ForgeRock, AS. |
| | | ! --> |
| | | <adm:managed-object name="attribute-value-password-validator" |
| | | plural-name="attribute-value-password-validators" |
| | |
| | | </ldap:attribute> |
| | | </adm:profile> |
| | | </adm:property> |
| | | <adm:property name="check-substrings" mandatory="false"> |
| | | <adm:synopsis> |
| | | Indicates whether this password validator is to match portions of |
| | | the password string against attribute values. |
| | | </adm:synopsis> |
| | | <adm:description> |
| | | If "false" then only match the entire password against attribute values |
| | | otherwise ("true") check whether the password contains attribute values. |
| | | </adm:description> |
| | | <adm:default-behavior> |
| | | <adm:defined> |
| | | <adm:value>true</adm:value> |
| | | </adm:defined> |
| | | </adm:default-behavior> |
| | | <adm:syntax> |
| | | <adm:boolean /> |
| | | </adm:syntax> |
| | | <adm:profile name="ldap"> |
| | | <ldap:attribute> |
| | | <ldap:name>ds-cfg-check-substrings</ldap:name> |
| | | </ldap:attribute> |
| | | </adm:profile> |
| | | </adm:property> |
| | | <adm:property name="min-substring-length" mandatory="false"> |
| | | <adm:synopsis> |
| | | Indicates the minimal length of the substring within the password |
| | | in case substring checking is enabled. |
| | | </adm:synopsis> |
| | | <adm:description> |
| | | If "check-substrings" option is set to true, then this parameter |
| | | defines the length of the smallest word which should be used for |
| | | substring matching. Use with caution because values below 3 might |
| | | disqualify valid passwords. |
| | | </adm:description> |
| | | <adm:default-behavior> |
| | | <adm:defined> |
| | | <adm:value>5</adm:value> |
| | | </adm:defined> |
| | | </adm:default-behavior> |
| | | <adm:syntax> |
| | | <adm:integer /> |
| | | </adm:syntax> |
| | | <adm:profile name="ldap"> |
| | | <ldap:attribute> |
| | | <ldap:name>ds-cfg-min-substring-length</ldap:name> |
| | | </ldap:attribute> |
| | | </adm:profile> |
| | | </adm:property> |
| | | <adm:property name="test-reversed-password" mandatory="true"> |
| | | <adm:synopsis> |
| | | Indicates whether this password validator should test the reversed |
| | |
| | | user-friendly-plural-name=Attribute Value Password Validators |
| | | synopsis=The Attribute Value Password Validator attempts to determine whether a proposed password is acceptable for use by determining whether that password is contained in any attribute within the user's entry. |
| | | description=It can be configured to look in all attributes or in a specified subset of attributes. |
| | | property.check-substrings.synopsis=Indicates whether this password validator is to match portions of the password string against attribute values. |
| | | property.check-substrings.description=If "false" then only match the entire password against attribute values otherwise ("true") check whether the password contains attribute values. |
| | | property.enabled.synopsis=Indicates whether the password validator is enabled for use. |
| | | property.java-class.synopsis=Specifies the fully-qualified name of the Java class that provides the password validator implementation. |
| | | property.match-attribute.synopsis=Specifies the name(s) of the attribute(s) whose values should be checked to determine whether they match the provided password. If no values are provided, then the server checks if the proposed password matches the value of any attribute in the user's entry. |
| | | property.match-attribute.default-behavior.alias.synopsis=All attributes in the user entry will be checked. |
| | | property.min-substring-length.synopsis=Indicates the minimal length of the substring within the password in case substring checking is enabled. |
| | | property.min-substring-length.description=If "check-substrings" option is set to true, then this parameter defines the length of the smallest word which should be used for substring matching. Use with caution because values below 3 might disqualify valid passwords. |
| | | property.test-reversed-password.synopsis=Indicates whether this password validator should test the reversed value of the provided password as well as the order in which it was given. |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012 ForgeRock, AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | |
| | | |
| | | |
| | | /** |
| | | * Search for substrings of the password in an Attribute. The search is |
| | | * case-insensitive. |
| | | * |
| | | * @param password the password |
| | | * @param minSubstringLength the minimum substring length to check |
| | | * @param a the attribute to search |
| | | * @return true if an attribute value matches a substring of the password, |
| | | * false otherwise. |
| | | */ |
| | | private boolean containsSubstring(String password, int minSubstringLength, |
| | | Attribute a) |
| | | { |
| | | final int passwordLength = password.length(); |
| | | |
| | | for (int i = 0; i < passwordLength; i++) |
| | | { |
| | | for (int j = i + minSubstringLength; j <= passwordLength; j++) |
| | | { |
| | | Attribute substring = Attributes.create(a.getAttributeType(), |
| | | password.substring(i, j)); |
| | | for (AttributeValue val : a) |
| | | { |
| | | if (substring.contains(val)) |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | |
| | | String password = newPassword.toString(); |
| | | String reversed = new StringBuilder(password).reverse().toString(); |
| | | |
| | | // Check to see if we should verify the whole password or the substrings. |
| | | int minSubstringLength = password.length(); |
| | | if (config.isCheckSubstrings()) |
| | | { |
| | | // We apply the minimal substring length only if the provided value |
| | | // is smaller then the actual password length |
| | | if (config.getMinSubstringLength() < password.length()) |
| | | { |
| | | minSubstringLength = config.getMinSubstringLength(); |
| | | } |
| | | } |
| | | |
| | | // If we should check a specific set of attributes, then do that now. |
| | | // Otherwise, check all user attributes. |
| | |
| | | for (Attribute a : attrList) |
| | | { |
| | | if (a.contains(vf) || |
| | | (config.isTestReversedPassword() && a.contains(vr))) |
| | | (config.isTestReversedPassword() && a.contains(vr)) || |
| | | (config.isCheckSubstrings() && |
| | | containsSubstring(password, minSubstringLength, a))) |
| | | { |
| | | |
| | | invalidReason.append(ERR_ATTRVALUE_VALIDATOR_PASSWORD_IN_ENTRY.get()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012 ForgeRock, AS. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | "ds-cfg-java-class: org.opends.server.extensions." + |
| | | "AttributeValuePasswordValidator", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-test-reversed-password: false"); |
| | | "ds-cfg-test-reversed-password: false", |
| | | "", |
| | | "dn: cn=Attribute Value,cn=Password Validators,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-password-validator", |
| | | "objectClass: ds-cfg-attribute-value-password-validator", |
| | | "cn: Attribute Value", |
| | | "ds-cfg-java-class: org.opends.server.extensions." + |
| | | "AttributeValuePasswordValidator", |
| | | "ds-cfg-check-substrings: false", |
| | | "ds-cfg-enabled: true"); |
| | | |
| | | Object[][] array = new Object[entries.size()][1]; |
| | | for (int i=0; i < array.length; i++) |
| | |
| | | }, |
| | | |
| | | // Default configuration, with a password that matches the reverse of an |
| | | // existing attribute value with reverwse matching enabled |
| | | // existing attribute value with reverse matching enabled |
| | | new Object[] |
| | | { |
| | | TestCaseUtils.makeEntry( |
| | |
| | | }, |
| | | |
| | | // Default configuration, with a password that matches the reverse of an |
| | | // existing attribute value with reverwse matching disabled |
| | | // existing attribute value with reverse matching disabled |
| | | new Object[] |
| | | { |
| | | TestCaseUtils.makeEntry( |
| | |
| | | "test.user", |
| | | true |
| | | }, |
| | | |
| | | // Default configuration, with a password that contains a substring |
| | | // from one of the attributes in the entry. |
| | | new Object[] |
| | | { |
| | | TestCaseUtils.makeEntry( |
| | | "dn: cn=Attribute Value,cn=Password Validators,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: ds-cfg-password-validator", |
| | | "objectClass: ds-cfg-attribute-value-password-validator", |
| | | "cn: Attribute Value", |
| | | "ds-cfg-java-class: org.opends.server.extensions." + |
| | | "AttributeValuePasswordValidator", |
| | | "ds-cfg-enabled: true", |
| | | "ds-cfg-check-substrings: true", |
| | | "ds-cfg-test-reversed-password: true"), |
| | | "test.user99", |
| | | false |
| | | }, |
| | | }; |
| | | } |
| | | |