From 47be44124da7f6ad42bed03a24701ca07c00918d Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 12 Sep 2007 00:03:02 +0000
Subject: [PATCH] Make a couple of changes to help improve server performance:

---
 opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java |  173 +++++++++++++++++++++++++--------------------------------
 1 files changed, 77 insertions(+), 96 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
index 91e26d7..dba46f4 100644
--- a/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
+++ b/opends/src/server/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
@@ -31,7 +31,6 @@
 import java.security.MessageDigest;
 import java.util.Arrays;
 import java.util.Random;
-import java.util.concurrent.locks.ReentrantLock;
 
 import org.opends.messages.Message;
 import org.opends.server.admin.std.server.SaltedSHA1PasswordStorageSchemeCfg;
@@ -94,7 +93,7 @@
   private MessageDigest messageDigest;
 
   // The lock used to provide threadsafe access to the message digest.
-  private ReentrantLock digestLock;
+  private Object digestLock;
 
   // The secure random number generator to use to generate the salt values.
   private Random random;
@@ -137,7 +136,7 @@
       throw new InitializationException(message, e);
     }
 
-    digestLock = new ReentrantLock();
+    digestLock = new Object();
     random     = new Random();
   }
 
@@ -169,33 +168,30 @@
 
     byte[] digestBytes;
 
-    digestLock.lock();
-
-    try
+    synchronized (digestLock)
     {
-      // Generate the salt and put in the plain+salt array.
-      random.nextBytes(saltBytes);
-      System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
-                       NUM_SALT_BYTES);
-
-      // Create the hash from the concatenated value.
-      digestBytes = messageDigest.digest(plainPlusSalt);
-    }
-    catch (Exception e)
-    {
-      if (debugEnabled())
+      try
       {
-        TRACER.debugCaught(DebugLogLevel.ERROR, e);
-      }
+        // Generate the salt and put in the plain+salt array.
+        random.nextBytes(saltBytes);
+        System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+                         NUM_SALT_BYTES);
 
-      Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
-          CLASS_NAME, getExceptionMessage(e));
-      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
-                                   message, e);
-    }
-    finally
-    {
-      digestLock.unlock();
+        // Create the hash from the concatenated value.
+        digestBytes = messageDigest.digest(plainPlusSalt);
+      }
+      catch (Exception e)
+      {
+        if (debugEnabled())
+        {
+          TRACER.debugCaught(DebugLogLevel.ERROR, e);
+        }
+
+        Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
+            CLASS_NAME, getExceptionMessage(e));
+        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                     message, e);
+      }
     }
 
     // Append the salt to the hashed value and base64-the whole thing.
@@ -230,33 +226,30 @@
 
     byte[] digestBytes;
 
-    digestLock.lock();
-
-    try
+    synchronized (digestLock)
     {
-      // Generate the salt and put in the plain+salt array.
-      random.nextBytes(saltBytes);
-      System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
-                       NUM_SALT_BYTES);
-
-      // Create the hash from the concatenated value.
-      digestBytes = messageDigest.digest(plainPlusSalt);
-    }
-    catch (Exception e)
-    {
-      if (debugEnabled())
+      try
       {
-        TRACER.debugCaught(DebugLogLevel.ERROR, e);
-      }
+        // Generate the salt and put in the plain+salt array.
+        random.nextBytes(saltBytes);
+        System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+                         NUM_SALT_BYTES);
 
-      Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
-          CLASS_NAME, getExceptionMessage(e));
-      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
-                                   message, e);
-    }
-    finally
-    {
-      digestLock.unlock();
+        // Create the hash from the concatenated value.
+        digestBytes = messageDigest.digest(plainPlusSalt);
+      }
+      catch (Exception e)
+      {
+        if (debugEnabled())
+        {
+          TRACER.debugCaught(DebugLogLevel.ERROR, e);
+        }
+
+        Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
+            CLASS_NAME, getExceptionMessage(e));
+        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                     message, e);
+      }
     }
 
     // Append the salt to the hashed value and base64-the whole thing.
@@ -315,24 +308,21 @@
 
     byte[] userDigestBytes;
 
-    digestLock.lock();
-
-    try
+    synchronized (digestLock)
     {
-      userDigestBytes = messageDigest.digest(plainPlusSalt);
-    }
-    catch (Exception e)
-    {
-      if (debugEnabled())
+      try
       {
-        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+        userDigestBytes = messageDigest.digest(plainPlusSalt);
       }
+      catch (Exception e)
+      {
+        if (debugEnabled())
+        {
+          TRACER.debugCaught(DebugLogLevel.ERROR, e);
+        }
 
-      return false;
-    }
-    finally
-    {
-      digestLock.unlock();
+        return false;
+      }
     }
 
     return Arrays.equals(digestBytes, userDigestBytes);
@@ -378,33 +368,30 @@
 
     byte[] digestBytes;
 
-    digestLock.lock();
-
-    try
+    synchronized (digestLock)
     {
-      // Generate the salt and put in the plain+salt array.
-      random.nextBytes(saltBytes);
-      System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
-                       NUM_SALT_BYTES);
-
-      // Create the hash from the concatenated value.
-      digestBytes = messageDigest.digest(plainPlusSalt);
-    }
-    catch (Exception e)
-    {
-      if (debugEnabled())
+      try
       {
-        TRACER.debugCaught(DebugLogLevel.ERROR, e);
-      }
+        // Generate the salt and put in the plain+salt array.
+        random.nextBytes(saltBytes);
+        System.arraycopy(saltBytes,0, plainPlusSalt, plainBytes.length,
+                         NUM_SALT_BYTES);
 
-      Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
-          CLASS_NAME, getExceptionMessage(e));
-      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
-                                   message, e);
-    }
-    finally
-    {
-      digestLock.unlock();
+        // Create the hash from the concatenated value.
+        digestBytes = messageDigest.digest(plainPlusSalt);
+      }
+      catch (Exception e)
+      {
+        if (debugEnabled())
+        {
+          TRACER.debugCaught(DebugLogLevel.ERROR, e);
+        }
+
+        Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get(
+            CLASS_NAME, getExceptionMessage(e));
+        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
+                                     message, e);
+      }
     }
 
 
@@ -452,17 +439,11 @@
     System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length,
                      saltBytes.length);
 
-    digestLock.lock();
-
-    try
+    synchronized (digestLock)
     {
       return Arrays.equals(digestBytes,
                                 messageDigest.digest(plainPlusSaltBytes));
     }
-    finally
-    {
-      digestLock.unlock();
-    }
   }
 
 

--
Gitblit v1.10.0