RandomPasswordGenerator.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 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class provides an implementation of a Directory Server password
* generator that will create random passwords based on fixed-length strings
* built from one or more character sets.
*/
public class RandomPasswordGenerator
{
// The current configuration for this password validator.
private RandomPasswordGeneratorCfg currentConfig;
// The encoded list of character sets defined for this password generator.
// The DN of the configuration entry for this password generator.
private DN configEntryDN;
// The total length of the password that will be generated.
private int totalLength;
// The numbers of characters of each type that should be used to generate the
// passwords.
private int[] characterCounts;
// The character sets that should be used to generate the passwords.
private NamedCharacterSet[] characterSets;
// The lock to use to ensure that the character sets and counts are not
// altered while a password is being generated.
private Object generatorLock;
// The character set format string for this password generator.
private String formatString;
/**
* {@inheritDoc}
*/
public void initializePasswordGenerator(
{
generatorLock = new Object();
// Get the character sets for use in generating the password. At least one
// must have been provided.
try
{
{
throw new ConfigException(message);
}
for (NamedCharacterSet s : NamedCharacterSet
{
{
throw new ConfigException(message);
}
else
{
}
}
}
catch (ConfigException ce)
{
throw ce;
}
catch (Exception e)
{
logger.traceException(e);
throw new InitializationException(message, e);
}
// Get the value that describes which character set(s) and how many
// characters from each should be used.
try
{
while (tokenizer.hasMoreTokens())
{
try
{
{
}
else
{
}
}
catch (ConfigException ce)
{
throw ce;
}
catch (Exception e)
{
logger.traceException(e);
throw new ConfigException(message, e);
}
}
totalLength = 0;
{
totalLength += characterCounts[i];
}
}
catch (ConfigException ce)
{
throw ce;
}
catch (Exception e)
{
logger.traceException(e);
throw new InitializationException(message, e);
}
configuration.addRandomChangeListener(this) ;
}
/**
* {@inheritDoc}
*/
public void finalizePasswordGenerator()
{
}
/**
* Generates a password for the user whose account is contained in the
* specified entry.
*
* @param userEntry The entry for the user for whom the password is to be
* generated.
*
* @return The password that has been generated for the user.
*
* @throws DirectoryException If a problem occurs while attempting to
* generate the password.
*/
throws DirectoryException
{
synchronized (generatorLock)
{
{
}
}
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
// Get the character sets for use in generating the password. At
// least one
// must have been provided.
try
{
{
}
for (NamedCharacterSet s : NamedCharacterSet
{
{
return false;
}
else
{
}
}
}
catch (ConfigException ce)
{
return false;
}
catch (Exception e)
{
logger.traceException(e);
getExceptionMessage(e));
return false;
}
// Get the value that describes which character set(s) and how many
// characters from each should be used.
try
{
while (tokenizer.hasMoreTokens())
{
try
{
{
return false;
}
}
catch (Exception e)
{
logger.traceException(e);
return false;
}
}
}
catch (Exception e)
{
logger.traceException(e);
getExceptionMessage(e));
return false;
}
// If we've gotten here, then everything looks OK.
return true;
}
/**
* {@inheritDoc}
*/
{
// Get the character sets for use in generating the password. At least one
// must have been provided.
try
{
{
}
else
{
for (NamedCharacterSet s :
{
{
}
else
{
}
}
}
}
catch (ConfigException ce)
{
}
catch (Exception e)
{
logger.traceException(e);
}
// Get the value that describes which character set(s) and how many
// characters from each should be used.
new ArrayList<NamedCharacterSet>();
try
{
while (tokenizer.hasMoreTokens())
{
try
{
{
}
else
{
}
}
catch (Exception e)
{
logger.traceException(e);
}
}
}
catch (Exception e)
{
logger.traceException(e);
}
// If everything looks OK, then apply the changes.
{
synchronized (generatorLock)
{
totalLength = 0;
{
totalLength += characterCounts[i];
}
}
}
return ccr;
}
}