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

kenneth_suter
15.34.2007 80c58327faaa4873369f6bb949e62792c2f708e0
opends/src/server/org/opends/server/core/PasswordPolicyConfigManager.java
@@ -25,6 +25,7 @@
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.core;
import org.opends.messages.Message;
@@ -42,8 +43,8 @@
import org.opends.server.types.InitializationException;
import org.opends.server.types.ResultCode;
import static org.opends.server.messages.ConfigMessages.*;
import static org.opends.server.messages.MessageHandler.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.server.util.StaticUtils.*;
@@ -103,18 +104,16 @@
    // there are no policies defined, so that's a problem.
    if (passwordPoliciesName.length == 0)
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_NO_POLICIES;
      String message = getMessage(msgID);
      throw new ConfigException(msgID, message);
      Message message = ERR_CONFIG_PWPOLICY_NO_POLICIES.get();
      throw new ConfigException(message);
    }
    // Get the DN of the default password policy from the core configuration.
    if( null == DirectoryServer.getDefaultPasswordPolicyDN())
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_NO_DEFAULT_POLICY;
      String message = getMessage(msgID);
      throw new ConfigException(msgID, message);
      Message message = ERR_CONFIG_PWPOLICY_NO_DEFAULT_POLICY.get();
      throw new ConfigException(message);
    }
@@ -135,25 +134,22 @@
      }
      catch (ConfigException ce)
      {
        int msgID = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
        String message = getMessage(msgID, String
            .valueOf(passwordPolicyConfiguration.dn()), ce.getMessage());
        throw new ConfigException(msgID, message, ce);
        Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
            String.valueOf(passwordPolicyConfiguration.dn()), ce.getMessage());
        throw new ConfigException(message, ce);
      }
      catch (InitializationException ie)
      {
        int    msgID   = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
        String message = getMessage(msgID, String
            .valueOf(passwordPolicyConfiguration.dn()), ie.getMessage());
        throw new InitializationException(msgID, message, ie);
        Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
            String.valueOf(passwordPolicyConfiguration.dn()), ie.getMessage());
        throw new InitializationException(message, ie);
      }
      catch (Exception e)
      {
        int    msgID   = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
        String message = getMessage(msgID, String
            .valueOf(passwordPolicyConfiguration.dn()),
            stackTraceToSingleLineString(e));
        throw new InitializationException(msgID, message, e);
        Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.
            get(String.valueOf(passwordPolicyConfiguration.dn()),
                stackTraceToSingleLineString(e));
        throw new InitializationException(message, e);
      }
    }
@@ -162,10 +158,10 @@
    // registered, then fail.
    if (null == DirectoryServer.getDefaultPasswordPolicy())
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_MISSING_DEFAULT_POLICY;
      DN defaultPolicyDN = DirectoryServer.getDefaultPasswordPolicyDN();
      String message = getMessage(msgID, String.valueOf(defaultPolicyDN));
      throw new ConfigException(msgID, message);
      Message message = ERR_CONFIG_PWPOLICY_MISSING_DEFAULT_POLICY.get(
              String.valueOf(defaultPolicyDN));
      throw new ConfigException(message);
    }
  }
@@ -175,7 +171,7 @@
   * {@inheritDoc}
   */
  public boolean isConfigurationAddAcceptable(PasswordPolicyCfg configuration,
                                       List<String> unacceptableReason)
                                       List<Message> unacceptableReason)
  {
    // See if we can create a password policy from the provided configuration
    // entry.  If so, then it's acceptable.
@@ -185,25 +181,25 @@
    }
    catch (ConfigException ce)
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      String message = getMessage(msgID, String.valueOf(configuration.dn()),
      Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
                                  ce.getMessage());
      unacceptableReason.add(message);
      return false;
    }
    catch (InitializationException ie)
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      String message = getMessage(msgID, String.valueOf(configuration.dn()),
      Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
                                  ie.getMessage());
      unacceptableReason.add(message);
      return false;
    }
    catch (Exception e)
    {
      int    msgID   = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      String message = getMessage(msgID, String.valueOf(configuration.dn()),
                                  stackTraceToSingleLineString(e));
      Message message = ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
              stackTraceToSingleLineString(e));
      unacceptableReason.add(message);
      return false;
    }
@@ -222,7 +218,7 @@
      PasswordPolicyCfg configuration)
  {
    DN                configEntryDN       = configuration.dn();
    ArrayList<String> messages            = new ArrayList<String>();
    ArrayList<Message> messages            = new ArrayList<Message>();
    // See if we can create a password policy from the provided configuration
@@ -238,27 +234,27 @@
    }
    catch (ConfigException ce)
    {
      int msgID = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      messages.add(getMessage(msgID, String.valueOf(configuration.dn()),
                              ce.getMessage()));
      messages.add(ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
              ce.getMessage()));
      return new ConfigChangeResult(ResultCode.CONSTRAINT_VIOLATION, false,
                                    messages);
    }
    catch (InitializationException ie)
    {
      int msgID = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      messages.add(getMessage(msgID, String.valueOf(configuration.dn()),
                              ie.getMessage()));
      messages.add(ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
              ie.getMessage()));
      return new ConfigChangeResult(DirectoryServer.getServerErrorResultCode(),
                                    false, messages);
    }
    catch (Exception e)
    {
      int msgID = MSGID_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG;
      messages.add(getMessage(msgID, String.valueOf(configuration.dn()),
                              stackTraceToSingleLineString(e)));
      messages.add(ERR_CONFIG_PWPOLICY_INVALID_POLICY_CONFIG.get(
              String.valueOf(configuration.dn()),
              stackTraceToSingleLineString(e)));
      return new ConfigChangeResult(DirectoryServer.getServerErrorResultCode(),
                                    false, messages);
@@ -271,7 +267,7 @@
   * {@inheritDoc}
   */
  public boolean isConfigurationDeleteAcceptable(
      PasswordPolicyCfg configuration, List<String> unacceptableReason)
      PasswordPolicyCfg configuration, List<Message> unacceptableReason)
  {
    // We'll allow the policy to be removed as long as it isn't the default.
    // FIXME: something like a referential integrity check is needed to ensure
@@ -281,8 +277,8 @@
    if ((defaultPolicyDN != null) &&
        defaultPolicyDN.equals(configuration.dn()))
    {
      int msgID = MSGID_CONFIG_PWPOLICY_CANNOT_DELETE_DEFAULT_POLICY;
      String message = getMessage(msgID, String.valueOf(defaultPolicyDN));
      Message message = WARN_CONFIG_PWPOLICY_CANNOT_DELETE_DEFAULT_POLICY.get(
              String.valueOf(defaultPolicyDN));
      unacceptableReason.add(message);
      return false;
    }
@@ -304,14 +300,13 @@
    // FIXME: something like a referential integrity check is needed to ensure
    //  a policy is not removed when referenced by a user entry (either
    // directly or via a virtual attribute).
    ArrayList<String> messages = new ArrayList<String>(1);
    ArrayList<Message> messages = new ArrayList<Message>(1);
    DN policyDN = configuration.dn();
    DN defaultPolicyDN = DirectoryServer.getDefaultPasswordPolicyDN();
    if ((defaultPolicyDN != null) && defaultPolicyDN.equals(policyDN))
    {
      int msgID = MSGID_CONFIG_PWPOLICY_CANNOT_DELETE_DEFAULT_POLICY;
      messages.add(getMessage(msgID, String.valueOf(defaultPolicyDN)));
      messages.add(WARN_CONFIG_PWPOLICY_CANNOT_DELETE_DEFAULT_POLICY.get(
              String.valueOf(defaultPolicyDN)));
      return new ConfigChangeResult(ResultCode.CONSTRAINT_VIOLATION, false,
                                    messages);
    }
@@ -323,8 +318,8 @@
      configuration.removeChangeListener(config);
    }
    int msgID = MSGID_CONFIG_PWPOLICY_REMOVED_POLICY;
    messages.add(getMessage(msgID, String.valueOf(policyDN)));
    messages.add(INFO_CONFIG_PWPOLICY_REMOVED_POLICY.get(
            String.valueOf(policyDN)));
    return new ConfigChangeResult(ResultCode.SUCCESS, false, messages);
  }