| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.SortedSet; |
| | | import java.util.StringTokenizer; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.server.PasswordGeneratorCfg; |
| | | import org.opends.server.admin.std.server.RandomPasswordGeneratorCfg; |
| | | import org.opends.server.api.PasswordGenerator; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.ByteStringFactory; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | |
| | | import org.opends.server.types.NamedCharacterSet; |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | |
| | |
| | | |
| | | // The lock to use to ensure that the character sets and counts are not |
| | | // altered while a password is being generated. |
| | | private ReentrantLock generatorLock; |
| | | private Object generatorLock; |
| | | |
| | | // The character set format string for this password generator. |
| | | private String formatString; |
| | |
| | | throws ConfigException, InitializationException |
| | | { |
| | | this.configEntryDN = configuration.dn(); |
| | | generatorLock = new ReentrantLock(); |
| | | int msgID ; |
| | | generatorLock = new Object(); |
| | | |
| | | // Get the character sets for use in generating the password. At least one |
| | | // must have been provided. |
| | |
| | | { |
| | | StringBuilder buffer = new StringBuilder(totalLength); |
| | | |
| | | generatorLock.lock(); |
| | | |
| | | try |
| | | synchronized (generatorLock) |
| | | { |
| | | for (int i=0; i < characterSets.length; i++) |
| | | { |
| | | characterSets[i].getRandomCharacters(buffer, characterCounts[i]); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | generatorLock.unlock(); |
| | | } |
| | | |
| | | return ByteStringFactory.create(buffer.toString()); |
| | | } |
| | |
| | | RandomPasswordGeneratorCfg configuration, |
| | | List<Message> unacceptableReasons) |
| | | { |
| | | int msgID; |
| | | |
| | | DN cfgEntryDN = configuration.dn(); |
| | | |
| | | // Get the character sets for use in generating the password. At |
| | |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | boolean adminActionRequired = false; |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | int msgID; |
| | | |
| | | |
| | | // Get the character sets for use in generating the password. At least one |
| | |
| | | // If everything looks OK, then apply the changes. |
| | | if (resultCode == ResultCode.SUCCESS) |
| | | { |
| | | generatorLock.lock(); |
| | | |
| | | try |
| | | synchronized (generatorLock) |
| | | { |
| | | encodedCharacterSets = newEncodedCharacterSets; |
| | | formatString = newFormatString; |
| | |
| | | totalLength += characterCounts[i]; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | generatorLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |