CharacterSetPasswordValidator.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 2011-2015 ForgeRock AS
*/
/**
* This class provides an OpenDJ password validator that may be used to ensure
* that proposed passwords contain at least a specified number of characters
* from one or more user-defined character sets.
*/
public class CharacterSetPasswordValidator
{
// The current configuration for this password validator.
// A mapping between the character sets and the minimum number of characters
// required for each.
// A mapping between the character ranges and the minimum number of characters
// required for each.
/**
* Creates a new instance of this character set password validator.
*/
public CharacterSetPasswordValidator()
{
super();
// No implementation is required here. All initialization should be
// performed in the initializePasswordValidator() method.
}
/**
* {@inheritDoc}
*/
public void initializePasswordValidator(
throws ConfigException
{
// Make sure that each of the character set and range definitions are
// acceptable.
}
/**
* {@inheritDoc}
*/
public void finalizePasswordValidator()
{
}
/**
* {@inheritDoc}
*/
{
// Get a handle to the current configuration.
// Process the provided password.
{
boolean found = false;
{
{
{
}
else
{
}
found = true;
break;
}
}
if (!found)
{
{
int rangeStart = 0;
{
{
{
}
else
{
}
found = true;
break;
}
rangeStart += 3;
}
}
}
{
return false;
}
}
int usedOptionalCharacterSets = 0;
int optionalCharacterSets = 0;
int mandatoryCharacterSets = 0;
{
if (minimumCount > 0)
{
// Mandatory character set.
{
return false;
}
}
else
{
// Optional character set.
if (passwordCount != null)
{
}
}
}
{
if (minimumCount > 0)
{
// Mandatory character set.
{
return false;
}
}
else
{
// Optional character set.
if (passwordCount != null)
{
}
}
}
// Check minimum optional character sets are present.
if (optionalCharacterSets > 0)
{
{
}
else
{
}
{
{
{
{
}
}
}
{
{
{
}
}
}
return false;
}
}
// If we've gotten here, then the password is acceptable.
return true;
}
/**
* Parses the provided configuration and extracts the character set
* definitions and associated minimum counts from them.
*
* @param configuration the configuration for this password validator.
* @param apply <CODE>true</CODE> if the configuration is being applied,
* <CODE>false</CODE> if it is just being validated.
* @throws ConfigException If any of the character set definitions cannot be
* parsed, or if there are any characters present in
* multiple sets.
*/
private void processCharacterSetsAndRanges(
boolean apply)
throws ConfigException
{
int mandatoryCharacterSets = 0;
{
if (colonPos <= 0)
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
int minCount;
try
{
}
catch (Exception e)
{
.get(definition);
throw new ConfigException(message);
}
if (minCount < 0)
{
.get(definition);
throw new ConfigException(message);
}
{
char c = characterSet.charAt(i);
if (usedCharacters.contains(c))
{
}
usedCharacters.add(c);
}
if (minCount > 0)
{
}
}
// Check the ranges
{
if (colonPos <= 0)
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
int minCount;
try
{
}
catch (Exception e)
{
.get(definition);
throw new ConfigException(message);
}
if (minCount < 0)
{
.get(definition);
throw new ConfigException(message);
}
/*
* Ensure we have a number of valid range specifications which are
* each 3 chars long.
* e.g. "a-zA-Z0-9"
*/
int rangeOffset = 0;
{
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
rangeOffset += 3;
}
if (minCount > 0)
{
}
}
// Validate min-character-sets if necessary.
if (optionalCharacterSets > 0
{
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
}
if (apply)
{
this.characterSets = characterSets;
this.characterRanges = characterRanges;
}
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
// Make sure that we can process the defined character sets. If so, then
// we'll accept the new configuration.
try
{
}
catch (ConfigException ce)
{
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
{
// Make sure that we can process the defined character sets. If so, then
// activate the new configuration.
try
{
}
catch (Exception e)
{
}
return ccr;
}
}