From cdbc97a66ca18d9f74b58c3fbca253f17d4dcd55 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 02 Feb 2016 10:57:43 +0000
Subject: [PATCH] Code cleanups: - remove isEmpty() checks when lists are iterated immediately after - extracted methods - removed {@inheritDoc} javadocs

---
 opendj-server-legacy/src/main/java/org/opends/server/plugins/PasswordPolicyImportPlugin.java |  109 ++++++++++++++++++------------------------------------
 1 files changed, 36 insertions(+), 73 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/plugins/PasswordPolicyImportPlugin.java b/opendj-server-legacy/src/main/java/org/opends/server/plugins/PasswordPolicyImportPlugin.java
index 598abaf..d15aac6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/plugins/PasswordPolicyImportPlugin.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/plugins/PasswordPolicyImportPlugin.java
@@ -35,6 +35,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.forgerock.i18n.LocalizableMessage;
@@ -43,6 +44,7 @@
 import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.opends.server.admin.server.ConfigurationChangeListener;
 import org.opends.server.admin.std.meta.PluginCfgDefn;
 import org.opends.server.admin.std.server.PasswordPolicyImportPluginCfg;
@@ -59,8 +61,13 @@
 import org.opends.server.core.SubentryPasswordPolicy;
 import org.opends.server.schema.AuthPasswordSyntax;
 import org.opends.server.schema.UserPasswordSyntax;
-import org.forgerock.opendj.ldap.schema.AttributeType;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeBuilder;
+import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
+import org.opends.server.types.Entry;
+import org.opends.server.types.LDIFImportConfig;
+import org.opends.server.types.SubEntry;
 
 /**
  * This class implements a Directory Server plugin that performs various
@@ -74,37 +81,22 @@
 {
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
-
-
   /** The attribute type used to specify the password policy for an entry. */
   private AttributeType customPolicyAttribute;
-
-  /**
-   * The set of attribute types defined in the schema with the auth password
-   * syntax.
-   */
+  /** The set of attribute types defined in the schema with the auth password syntax. */
   private AttributeType[] authPasswordTypes;
-
-  /**
-   * The set of attribute types defined in the schema with the user password
-   * syntax.
-   */
+  /** The set of attribute types defined in the schema with the user password syntax. */
   private AttributeType[] userPasswordTypes;
-
   /**
    * The set of password storage schemes to use for the various password
    * policies defined in the server.
    */
-  private HashMap<DN,PasswordStorageScheme<?>[]> schemesByPolicy;
-
+  private Map<DN, PasswordStorageScheme<?>[]> schemesByPolicy;
   /** The default password storage schemes for auth password attributes. */
   private PasswordStorageScheme<?>[] defaultAuthPasswordSchemes;
-
   /** The default password storage schemes for user password attributes. */
   private PasswordStorageScheme<?>[] defaultUserPasswordSchemes;
 
-
-
   /**
    * Creates a new instance of this Directory Server plugin.  Every plugin must
    * implement a default constructor (it is the only one that will be used to
@@ -125,7 +117,6 @@
 
     customPolicyAttribute = DirectoryServer.getAttributeType(OP_ATTR_PWPOLICY_POLICY_DN);
 
-
     // Make sure that the plugin has been enabled for the appropriate types.
     for (PluginType t : pluginTypes)
     {
@@ -140,7 +131,6 @@
       }
     }
 
-
     // Get the set of default password storage schemes for auth password
     // attributes.
     PasswordPolicy defaultPolicy = DirectoryServer.getDefaultPasswordPolicy();
@@ -191,7 +181,6 @@
       }
     }
 
-
     // Get the set of default password storage schemes for user password
     // attributes.
     Set<DN> userSchemeDNs =
@@ -249,17 +238,16 @@
     HashSet<AttributeType> userPWTypes = new HashSet<>();
     for (AttributeType t : DirectoryServer.getAttributeTypes())
     {
-      if (t.getSyntax().getOID().equals(SYNTAX_AUTH_PASSWORD_OID))
+      if (SYNTAX_AUTH_PASSWORD_OID.equals(t.getSyntax().getOID()))
       {
         authPWTypes.add(t);
       }
-      else if (t.getSyntax().getOID().equals(SYNTAX_USER_PASSWORD_OID))
+      else if (SYNTAX_USER_PASSWORD_OID.equals(t.getSyntax().getOID()))
       {
         userPWTypes.add(t);
       }
     }
 
-
     // Get the set of password policies defined in the server and get the
     // attribute types associated with them.
     HashMap<DN,PasswordStorageScheme<?>[]> schemeMap = new HashMap<>();
@@ -277,7 +265,6 @@
       }
     }
 
-
     AttributeType[] authTypesArray = new AttributeType[authPWTypes.size()];
     AttributeType[] userTypesArray = new AttributeType[userPWTypes.size()];
     authPWTypes.toArray(authTypesArray);
@@ -398,32 +385,28 @@
                   builder.add(value);
                 }
               }
+              else if (!UserPasswordSyntax.isEncoded(value))
+              {
+                try
+                {
+                  for (PasswordStorageScheme<?> s : schemes)
+                  {
+                    builder.add(s.encodePasswordWithScheme(value));
+                  }
+                }
+                catch (Exception e)
+                {
+                  logger.traceException(e);
+
+                  logger.error(ERR_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD, policy.getPasswordAttribute()
+                      .getNameOrOID(), entry.getName(), stackTraceToSingleLineString(e));
+                  gotError = true;
+                  break;
+                }
+              }
               else
               {
-                if (!UserPasswordSyntax.isEncoded(value))
-                {
-                  try
-                  {
-                    for (PasswordStorageScheme<?> s : schemes)
-                    {
-                      builder.add(s.encodePasswordWithScheme(value));
-                    }
-                  }
-                  catch (Exception e)
-                  {
-                    logger.traceException(e);
-
-                    logger.error(ERR_PLUGIN_PWPIMPORT_ERROR_ENCODING_PASSWORD,
-                        policy.getPasswordAttribute().getNameOrOID(), entry.getName(),
-                        stackTraceToSingleLineString(e));
-                    gotError = true;
-                    break;
-                  }
-                }
-                else
-                {
-                  builder.add(value);
-                }
+                builder.add(value);
               }
             }
 
@@ -438,19 +421,12 @@
       }
     }
 
-
     // Iterate through the list of auth password attributes.  If any of them
     // are present and their values are not encoded, then encode them with all
     // appropriate schemes.
     for (AttributeType t : authPasswordTypes)
     {
-      attrList = entry.getAttribute(t);
-      if (attrList.isEmpty())
-      {
-        continue;
-      }
-
-      for (Attribute a : attrList)
+      for (Attribute a : entry.getAttribute(t))
       {
         AttributeBuilder builder = new AttributeBuilder(a, true);
         boolean gotError = false;
@@ -488,19 +464,12 @@
       }
     }
 
-
     // Iterate through the list of user password attributes.  If any of them
     // are present and their values are not encoded, then encode them with all
     // appropriate schemes.
     for (AttributeType t : userPasswordTypes)
     {
-      attrList = entry.getAttribute(t);
-      if (attrList.isEmpty())
-      {
-        continue;
-      }
-
-      for (Attribute a : attrList)
+      for (Attribute a : entry.getAttribute(t))
       {
         AttributeBuilder builder = new AttributeBuilder(a, true);
         boolean gotError = false;
@@ -538,7 +507,6 @@
       }
     }
 
-
     return PluginResult.ImportLDIF.continueEntryProcessing();
   }
 
@@ -567,14 +535,12 @@
           // This is the only acceptable type.
           break;
 
-
         default:
           unacceptableReasons.add(ERR_PLUGIN_PWPIMPORT_INVALID_PLUGIN_TYPE.get(pluginType));
           configAcceptable = false;
       }
     }
 
-
     // Get the set of default password storage schemes for auth password
     // attributes.
     Set<DN> authSchemeDNs =
@@ -617,7 +583,6 @@
       }
     }
 
-
     // Get the set of default password storage schemes for user password
     // attributes.
     Set<DN> userSchemeDNs =
@@ -655,7 +620,6 @@
       }
     }
 
-
     return configAcceptable;
   }
 
@@ -717,7 +681,6 @@
       }
     }
 
-
     // Get the set of default password storage schemes for user password
     // attributes.
     PasswordStorageScheme<?>[] defaultUserSchemes;

--
Gitblit v1.10.0