mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
10.03.2007 959c9ded0c297d00500678a0c80d7d6d8a5265fe
opends/src/server/org/opends/server/core/PasswordGeneratorConfigManager.java
@@ -30,6 +30,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -125,7 +126,8 @@
        try
        {
          PasswordGenerator<? extends PasswordGeneratorCfg>
               generator = loadGenerator(className, generatorConfiguration);
               generator = loadGenerator(className, generatorConfiguration,
                                         true);
          passwordGenerators.put(generatorConfiguration.dn(), generator);
          DirectoryServer.registerPasswordGenerator(generatorConfiguration.dn(),
              generator);
@@ -155,7 +157,7 @@
      String className = configuration.getGeneratorClass();
      try
      {
        loadGenerator(className, null);
        loadGenerator(className, configuration, false);
      }
      catch (InitializationException ie)
      {
@@ -225,7 +227,7 @@
         passwordGenerator = null;
    try
    {
      passwordGenerator = loadGenerator(className, configuration);
      passwordGenerator = loadGenerator(className, configuration, true);
    }
    catch (InitializationException ie)
    {
@@ -260,7 +262,7 @@
      String className = configuration.getGeneratorClass();
      try
      {
        loadGenerator(className, null);
        loadGenerator(className, configuration, false);
      }
      catch (InitializationException ie)
      {
@@ -299,7 +301,7 @@
    String className = configuration.getGeneratorClass();
    try
    {
      passwordGenerator = loadGenerator(className, configuration);
      passwordGenerator = loadGenerator(className, configuration, true);
    }
    catch (InitializationException ie)
    {
@@ -365,6 +367,8 @@
   * @param  configuration  The configuration to use to initialize the
   *                        password generator, or {@code null} if the
   *                        password generator should not be initialized.
   * @param  initialize     Indicates whether the password generator instance
   *                        should be initialized.
   *
   * @return  The possibly initialized password generator.
   *
@@ -373,7 +377,8 @@
   */
  private PasswordGenerator<? extends PasswordGeneratorCfg>
               loadGenerator(String className,
                             PasswordGeneratorCfg configuration)
                             PasswordGeneratorCfg configuration,
                             boolean initialize)
          throws InitializationException
  {
    try
@@ -388,13 +393,43 @@
           (PasswordGenerator<? extends PasswordGeneratorCfg>)
           generatorClass.newInstance();
      if (configuration != null)
      if (initialize)
      {
        Method method =
          generator.getClass().getMethod("initializePasswordGenerator",
                  configuration.definition().getServerConfigurationClass());
        method.invoke(generator, configuration);
      }
      else
      {
        Method method =
             generator.getClass().getMethod("isConfigurationAcceptable",
                                            PasswordGeneratorCfg.class,
                                            List.class);
        List<String> unacceptableReasons = new ArrayList<String>();
        Boolean acceptable = (Boolean) method.invoke(generator, configuration,
                                                     unacceptableReasons);
        if (! acceptable)
        {
          StringBuilder buffer = new StringBuilder();
          if (! unacceptableReasons.isEmpty())
          {
            Iterator<String> iterator = unacceptableReasons.iterator();
            buffer.append(iterator.next());
            while (iterator.hasNext())
            {
              buffer.append(".  ");
              buffer.append(iterator.next());
            }
          }
          int    msgID   = MSGID_CONFIG_PWGENERATOR_CONFIG_NOT_ACCEPTABLE;
          String message = getMessage(msgID, String.valueOf(configuration.dn()),
                                      buffer.toString());
          throw new InitializationException(msgID, message);
        }
      }
      return generator;
    }