AttributeValuePasswordValidator.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* This class provides an OpenDS password validator that may be used to ensure
* that proposed passwords are not contained in another attribute in the user's
* entry.
*/
public class AttributeValuePasswordValidator
implements ConfigurationChangeListener<
{
// The current configuration for this password validator.
/**
* Creates a new instance of this attribute value password validator.
*/
public AttributeValuePasswordValidator()
{
super();
// No implementation is required here. All initialization should be
// performed in the initializePasswordValidator() method.
}
/**
* {@inheritDoc}
*/
public void initializePasswordValidator(
{
}
/**
* {@inheritDoc}
*/
public void finalizePasswordValidator()
{
}
/**
* 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.
*/
Attribute a)
{
for (int i = 0; i < passwordLength; i++)
{
for (int j = i + minSubstringLength; j <= passwordLength; j++)
{
for (ByteString val : a)
{
{
return true;
}
}
}
}
return false;
}
/**
* {@inheritDoc}
*/
{
// Get a handle to the current configuration.
// Get the string representation (both forward and reversed) for the
// password.
// Check to see if we should verify the whole password or the substrings.
if (config.isCheckSubstrings())
{
// We apply the minimal substring length only if the provided value
// is smaller then the actual password length
{
}
}
// If we should check a specific set of attributes, then do that now.
// Otherwise, check all user attributes.
{
}
for (AttributeType t : matchAttributes)
{
{
continue;
}
{
(config.isCheckSubstrings() &&
{
return false;
}
}
}
// If we've gotten here, then the password is acceptable.
return true;
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
// If we've gotten this far, then we'll accept the change.
return true;
}
/**
* {@inheritDoc}
*/
{
return new ConfigChangeResult();
}
}