Make a couple of changes to help improve server performance:
- Update the server code to replace simple uses of ReentrantLock involving
{lock, doSomething, unlock} in the same method to use the synchronized
keyword instead of a ReentrantLock object. Using the synchronized keyword is
actually a little faster, and also simplifies the code since it's no longer
necessary to use a finally block to ensure that the lock is released.
- Update the AsynchronousTextWriter to use the LinkedBlockingQueue.drainTo()
method to attempt to get multiple messages at once, rather than always using
poll() to get one message at a time.
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.config; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.api.ConfigAddListener; |
| | | import org.opends.server.api.ConfigChangeListener; |
| | | import org.opends.server.api.ConfigDeleteListener; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.DN; |
| | |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | | |
| | |
| | | private Entry entry; |
| | | |
| | | // The lock used to provide threadsafe access to this configuration entry. |
| | | private ReentrantLock entryLock; |
| | | private Object entryLock; |
| | | |
| | | |
| | | |
| | |
| | | addListeners = new CopyOnWriteArrayList<ConfigAddListener>(); |
| | | changeListeners = new CopyOnWriteArrayList<ConfigChangeListener>(); |
| | | deleteListeners = new CopyOnWriteArrayList<ConfigDeleteListener>(); |
| | | entryLock = new ReentrantLock(); |
| | | entryLock = new Object(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public void setEntry(Entry entry) |
| | | { |
| | | entryLock.lock(); |
| | | |
| | | try |
| | | synchronized (entryLock) |
| | | { |
| | | this.entry = entry; |
| | | } |
| | | finally |
| | | { |
| | | entryLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | ConfigEntry conflictingChild; |
| | | |
| | | entryLock.lock(); |
| | | |
| | | try |
| | | synchronized (entryLock) |
| | | { |
| | | conflictingChild = children.putIfAbsent(childEntry.getDN(), childEntry); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | conflictingChild = null; |
| | | } |
| | | finally |
| | | { |
| | | entryLock.unlock(); |
| | | } |
| | | |
| | | if (conflictingChild != null) |
| | | { |
| | |
| | | public ConfigEntry removeChild(DN childDN) |
| | | throws ConfigException |
| | | { |
| | | entryLock.lock(); |
| | | |
| | | try |
| | | synchronized (entryLock) |
| | | { |
| | | ConfigEntry childEntry = children.get(childDN); |
| | | if (childEntry == null) |
| | | try |
| | | { |
| | | Message message = ERR_CONFIG_ENTRY_NO_SUCH_CHILD.get( |
| | | childDN.toString(), entry.getDN().toString()); |
| | | throw new ConfigException(message); |
| | | } |
| | | ConfigEntry childEntry = children.get(childDN); |
| | | if (childEntry == null) |
| | | { |
| | | Message message = ERR_CONFIG_ENTRY_NO_SUCH_CHILD.get( |
| | | childDN.toString(), entry.getDN().toString()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (childEntry.hasChildren()) |
| | | if (childEntry.hasChildren()) |
| | | { |
| | | Message message = ERR_CONFIG_ENTRY_CANNOT_REMOVE_NONLEAF.get( |
| | | childDN.toString(), entry.getDN().toString()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | children.remove(childDN); |
| | | return childEntry; |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | Message message = ERR_CONFIG_ENTRY_CANNOT_REMOVE_NONLEAF.get( |
| | | childDN.toString(), entry.getDN().toString()); |
| | | throw new ConfigException(message); |
| | | throw ce; |
| | | } |
| | | |
| | | children.remove(childDN); |
| | | return childEntry; |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | throw ce; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = ERR_CONFIG_ENTRY_CANNOT_REMOVE_CHILD. |
| | | get(String.valueOf(childDN), String.valueOf(entry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | finally |
| | | { |
| | | entryLock.unlock(); |
| | | Message message = ERR_CONFIG_ENTRY_CANNOT_REMOVE_CHILD. |
| | | get(String.valueOf(childDN), String.valueOf(entry.getDN()), |
| | | stackTraceToSingleLineString(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.channels.FileLock; |
| | | import java.util.HashMap; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.server.api.Backend; |
| | | |
| | | 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.CoreMessages.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | new HashMap<String,Integer>(); |
| | | |
| | | // The lock providing threadsafe access to the lock map data. |
| | | private static ReentrantLock mapLock = new ReentrantLock(); |
| | | private static Object mapLock = new Object(); |
| | | |
| | | |
| | | |
| | |
| | | public static boolean acquireSharedLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // Check to see if there's already an exclusive lock on the file. If so, |
| | | // then we can't get a shared lock on it. |
| | |
| | | return true; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public static boolean acquireExclusiveLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // Check to see if there's already an exclusive lock on the file. If so, |
| | | // then we can't get another exclusive lock on it. |
| | |
| | | return true; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public static boolean releaseLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // See if we hold an exclusive lock on the file. If so, then release it |
| | | // and get remove it from the lock table. |
| | |
| | | failureReason.append(ERR_FILELOCKER_UNLOCK_UNKNOWN_FILE.get(lockFile)); |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.concurrent.locks.Lock; |
| | | 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.CramMD5SASLMechanismHandlerCfg; |
| | | import org.opends.server.admin.std.server.SASLMechanismHandlerCfg; |
| | |
| | | import org.opends.server.core.BindOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.PasswordPolicyState; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.ByteString; |
| | | 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.LockManager; |
| | | 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.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | |
| | | // The lock that will be used to provide threadsafe access to the message |
| | | // digest. |
| | | private ReentrantLock digestLock; |
| | | private Object digestLock; |
| | | |
| | | // The random number generator that we will use to create the server |
| | | // challenge. |
| | |
| | | |
| | | |
| | | // Initialize the variables needed for the MD5 digest creation. |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | randomGenerator = new SecureRandom(); |
| | | |
| | | try |
| | |
| | | |
| | | |
| | | // Grab a lock to protect the MD5 digest generation. |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | // If the password is longer than the HMAC-MD5 block length, then use an |
| | | // MD5 digest of the password rather than the password itself. |
| | |
| | | // Return an MD5 digest of the resulting array. |
| | | return md5Digest.digest(oPadAndHash); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | import java.util.zip.ZipOutputStream; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import javax.crypto.Mac; |
| | | |
| | | import org.opends.messages.Message; |
| | |
| | | |
| | | // The write lock used to ensure that only one thread can apply a |
| | | // configuration update at any given time. |
| | | private ReentrantLock configLock; |
| | | private Object configLock; |
| | | |
| | | // The path to the configuration file. |
| | | private String configFile; |
| | |
| | | throws InitializationException |
| | | { |
| | | // Initialize the config lock. |
| | | configLock = new ReentrantLock(); |
| | | configLock = new Object(); |
| | | |
| | | |
| | | // Determine whether we should try to start using the last known good |
| | |
| | | |
| | | // Grab the config lock to ensure that only one config update may be in |
| | | // progress at any given time. |
| | | configLock.lock(); |
| | | |
| | | try |
| | | synchronized (configLock) |
| | | { |
| | | // Make sure that the target DN does not already exist. If it does, then |
| | | // fail. |
| | |
| | | throw new DirectoryException(resultCode, message); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | configLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // Grab the config lock to ensure that only one config update may be in |
| | | // progress at any given time. |
| | | configLock.lock(); |
| | | |
| | | try |
| | | synchronized (configLock) |
| | | { |
| | | // Get the target entry. If it does not exist, then fail. |
| | | ConfigEntry entry = configEntries.get(entryDN); |
| | |
| | | throw new DirectoryException(resultCode, message); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | configLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // Grab the config lock to ensure that only one config update may be in |
| | | // progress at any given time. |
| | | configLock.lock(); |
| | | |
| | | |
| | | try |
| | | synchronized (configLock) |
| | | { |
| | | // Get the DN of the target entry for future reference. |
| | | DN entryDN = e.getDN(); |
| | |
| | | throw new DirectoryException(resultCode, message); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | configLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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.CryptPasswordStorageSchemeCfg; |
| | |
| | | +"ABCDEFGHIJKLMNOPQRSTUVWXYZ").getBytes(); |
| | | |
| | | private final Random randomSaltIndex = new Random(); |
| | | private final ReentrantLock saltLock = new ReentrantLock(); |
| | | private final Object saltLock = new Object(); |
| | | private final Crypt crypt = new Crypt(); |
| | | |
| | | |
| | |
| | | * @return a random 2-byte salt |
| | | */ |
| | | private byte[] randomSalt() { |
| | | saltLock.lock(); |
| | | |
| | | try { |
| | | synchronized (saltLock) |
| | | { |
| | | byte[] salt = new byte[2]; |
| | | int sb1 = randomSaltIndex.nextInt(SALT_CHARS.length); |
| | | int sb2 = randomSaltIndex.nextInt(SALT_CHARS.length); |
| | |
| | | salt[1] = SALT_CHARS[sb2]; |
| | | |
| | | return salt; |
| | | } finally { |
| | | saltLock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.locks.Lock; |
| | | 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.DigestMD5SASLMechanismHandlerCfg; |
| | | import org.opends.server.admin.std.server.SASLMechanismHandlerCfg; |
| | |
| | | import org.opends.server.core.BindOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.PasswordPolicyState; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.types.AuthenticationInfo; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DisconnectReason; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | |
| | | |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LockManager; |
| | | import org.opends.server.types.Privilege; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.util.Base64; |
| | | |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.messages.ExtensionMessages.*; |
| | | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | |
| | | // The lock that will be used to provide threadsafe access to the message |
| | | // digest. |
| | | private ReentrantLock digestLock; |
| | | private Object digestLock; |
| | | |
| | | // The random number generator that we will use to create the nonce. |
| | | private SecureRandom randomGenerator; |
| | |
| | | |
| | | |
| | | // Initialize the variables needed for the MD5 digest creation. |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | randomGenerator = new SecureRandom(); |
| | | |
| | | try |
| | |
| | | private String generateNonce() |
| | | { |
| | | byte[] nonceBytes = new byte[16]; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | { |
| | | randomGenerator.nextBytes(nonceBytes); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | |
| | | randomGenerator.nextBytes(nonceBytes); |
| | | return Base64.encode(nonceBytes); |
| | | } |
| | | |
| | |
| | | String qop, String charset) |
| | | throws UnsupportedEncodingException |
| | | { |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | // First, get a hash of "username:realm:password". |
| | | StringBuilder a1String1 = new StringBuilder(); |
| | |
| | | kdString.append(a2HashHex); |
| | | return md5Digest.digest(kdString.toString().getBytes(charset)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | String qop, String charset) |
| | | throws UnsupportedEncodingException |
| | | { |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | // First, get a hash of "username:realm:password". |
| | | StringBuilder a1String1 = new StringBuilder(); |
| | |
| | | kdString.append(a2HashHex); |
| | | return md5Digest.digest(kdString.toString().getBytes(charset)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.MD5PasswordStorageSchemeCfg; |
| | |
| | | private MessageDigest messageDigest; |
| | | |
| | | // The lock used to provide threadsafe access to the message digest. |
| | | private ReentrantLock digestLock; |
| | | private Object digestLock; |
| | | |
| | | |
| | | |
| | |
| | | throw new InitializationException(message, e); |
| | | } |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | byte[] digestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | 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); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get( |
| | | CLASS_NAME, getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | } |
| | | |
| | | return ByteStringFactory.create(Base64.encode(digestBytes)); |
| | |
| | | |
| | | byte[] digestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | 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); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get( |
| | | CLASS_NAME, getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | } |
| | | |
| | | buffer.append(Base64.encode(digestBytes)); |
| | |
| | | { |
| | | byte[] userPWDigestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | userPWDigestBytes = messageDigest.digest(plaintextPassword.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | userPWDigestBytes = messageDigest.digest(plaintextPassword.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | byte[] storedPWDigestBytes; |
| | |
| | | * 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(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.SHA1PasswordStorageSchemeCfg; |
| | |
| | | private MessageDigest messageDigest; |
| | | |
| | | // The lock used to provide threadsafe access to the message digest. |
| | | private ReentrantLock digestLock; |
| | | private Object digestLock; |
| | | |
| | | |
| | | |
| | |
| | | throw new InitializationException(message, e); |
| | | } |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | byte[] digestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | 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); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get( |
| | | CLASS_NAME, getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | } |
| | | |
| | | return ByteStringFactory.create(Base64.encode(digestBytes)); |
| | |
| | | |
| | | byte[] digestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | digestBytes = messageDigest.digest(plaintext.value()); |
| | | } |
| | | 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); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | Message message = ERR_PWSCHEME_CANNOT_ENCODE_PASSWORD.get( |
| | | CLASS_NAME, getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | } |
| | | |
| | | buffer.append(Base64.encode(digestBytes)); |
| | |
| | | { |
| | | byte[] userPWDigestBytes; |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | userPWDigestBytes = messageDigest.digest(plaintextPassword.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | userPWDigestBytes = messageDigest.digest(plaintextPassword.value()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | byte[] storedPWDigestBytes; |
| | |
| | | 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.SaltedMD5PasswordStorageSchemeCfg; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | random = new Random(); |
| | | } |
| | | |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length, |
| | | saltBytes.length); |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | throw new InitializationException(message, e); |
| | | } |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | random = new Random(); |
| | | } |
| | | |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length, |
| | | saltBytes.length); |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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.SaltedSHA256PasswordStorageSchemeCfg; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | random = new Random(); |
| | | } |
| | | |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length, |
| | | saltBytes.length); |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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.SaltedSHA384PasswordStorageSchemeCfg; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | random = new Random(); |
| | | } |
| | | |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length, |
| | | saltBytes.length); |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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.SaltedSHA512PasswordStorageSchemeCfg; |
| | |
| | | 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; |
| | |
| | | throw new InitializationException(message, e); |
| | | } |
| | | |
| | | digestLock = new ReentrantLock(); |
| | | digestLock = new Object(); |
| | | random = new Random(); |
| | | } |
| | | |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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. |
| | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | System.arraycopy(saltBytes, 0, plainPlusSaltBytes, plainBytes.length, |
| | | saltBytes.length); |
| | | |
| | | digestLock.lock(); |
| | | |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | return Arrays.equals(digestBytes, |
| | | messageDigest.digest(plainPlusSaltBytes)); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | 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.TraditionalWorkQueueCfg; |
| | | import org.opends.server.api.WorkQueue; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.monitors.TraditionalWorkQueueMonitor; |
| | | import org.opends.server.types.AbstractOperation; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.ConfigChangeResult; |
| | | import org.opends.server.types.DebugLogLevel; |
| | |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import org.opends.server.types.AbstractOperation; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | |
| | | |
| | | |
| | |
| | | private LinkedBlockingQueue<AbstractOperation> opQueue; |
| | | |
| | | // The lock used to provide threadsafe access for the queue. |
| | | private ReentrantLock queueLock; |
| | | private Object queueLock; |
| | | |
| | | |
| | | |
| | |
| | | killThreads = false; |
| | | opsSubmitted = new AtomicLong(0); |
| | | queueFullRejects = new AtomicLong(0); |
| | | queueLock = new ReentrantLock(); |
| | | queueLock = new Object(); |
| | | |
| | | |
| | | // Register to be notified of any configuration changes. |
| | |
| | | // so, then return null and the thread will exit. |
| | | if (killThreads) |
| | | { |
| | | queueLock.lock(); |
| | | |
| | | try |
| | | synchronized (queueLock) |
| | | { |
| | | int currentThreads = workerThreads.size(); |
| | | if (currentThreads > numWorkerThreads) |
| | | try |
| | | { |
| | | if (workerThreads.remove(Thread.currentThread())) |
| | | int currentThreads = workerThreads.size(); |
| | | if (currentThreads > numWorkerThreads) |
| | | { |
| | | currentThreads--; |
| | | } |
| | | if (workerThreads.remove(Thread.currentThread())) |
| | | { |
| | | currentThreads--; |
| | | } |
| | | |
| | | if (currentThreads <= numWorkerThreads) |
| | | { |
| | | killThreads = false; |
| | | } |
| | | if (currentThreads <= numWorkerThreads) |
| | | { |
| | | killThreads = false; |
| | | } |
| | | |
| | | workerThread.setStoppedByReducedThreadNumber(); |
| | | return null; |
| | | workerThread.setStoppedByReducedThreadNumber(); |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | queueLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | if ((shutdownRequested) || (numFailures > MAX_RETRY_COUNT)) |
| | |
| | | } |
| | | else if (killThreads) |
| | | { |
| | | queueLock.lock(); |
| | | |
| | | try |
| | | synchronized (queueLock) |
| | | { |
| | | int currentThreads = workerThreads.size(); |
| | | if (currentThreads > numWorkerThreads) |
| | | try |
| | | { |
| | | if (workerThreads.remove(Thread.currentThread())) |
| | | int currentThreads = workerThreads.size(); |
| | | if (currentThreads > numWorkerThreads) |
| | | { |
| | | currentThreads--; |
| | | } |
| | | if (workerThreads.remove(Thread.currentThread())) |
| | | { |
| | | currentThreads--; |
| | | } |
| | | |
| | | if (currentThreads <= numWorkerThreads) |
| | | { |
| | | killThreads = false; |
| | | } |
| | | if (currentThreads <= numWorkerThreads) |
| | | { |
| | | killThreads = false; |
| | | } |
| | | |
| | | workerThread.setStoppedByReducedThreadNumber(); |
| | | return null; |
| | | workerThread.setStoppedByReducedThreadNumber(); |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | queueLock.unlock(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | int currentThreads = workerThreads.size(); |
| | | if (newNumThreads != currentThreads) |
| | | { |
| | | queueLock.lock(); |
| | | |
| | | try |
| | | synchronized (queueLock) |
| | | { |
| | | int threadsToAdd = newNumThreads - currentThreads; |
| | | if (threadsToAdd > 0) |
| | | try |
| | | { |
| | | for (int i=0; i < threadsToAdd; i++) |
| | | int threadsToAdd = newNumThreads - currentThreads; |
| | | if (threadsToAdd > 0) |
| | | { |
| | | TraditionalWorkerThread t = |
| | | new TraditionalWorkerThread(this, lastThreadNumber++); |
| | | workerThreads.add(t); |
| | | t.start(); |
| | | for (int i=0; i < threadsToAdd; i++) |
| | | { |
| | | TraditionalWorkerThread t = |
| | | new TraditionalWorkerThread(this, lastThreadNumber++); |
| | | workerThreads.add(t); |
| | | t.start(); |
| | | } |
| | | |
| | | killThreads = false; |
| | | } |
| | | else |
| | | { |
| | | killThreads = true; |
| | | } |
| | | |
| | | killThreads = false; |
| | | numWorkerThreads = newNumThreads; |
| | | } |
| | | else |
| | | catch (Exception e) |
| | | { |
| | | killThreads = true; |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | |
| | | numWorkerThreads = newNumThreads; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | queueLock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | // checks will be against the new queue. |
| | | if (newMaxCapacity != maxCapacity) |
| | | { |
| | | queueLock.lock(); |
| | | |
| | | try |
| | | synchronized (queueLock) |
| | | { |
| | | LinkedBlockingQueue<AbstractOperation> newOpQueue; |
| | | if (newMaxCapacity > 0) |
| | | try |
| | | { |
| | | newOpQueue = |
| | | new LinkedBlockingQueue<AbstractOperation>(newMaxCapacity); |
| | | } |
| | | else |
| | | { |
| | | newOpQueue = new LinkedBlockingQueue<AbstractOperation>(); |
| | | } |
| | | |
| | | LinkedBlockingQueue<AbstractOperation> oldOpQueue = opQueue; |
| | | opQueue = newOpQueue; |
| | | |
| | | LinkedList<AbstractOperation> pendingOps = |
| | | new LinkedList<AbstractOperation>(); |
| | | oldOpQueue.drainTo(pendingOps); |
| | | |
| | | |
| | | // We have to be careful when adding any existing pending operations |
| | | // because the new capacity could be less than what was already |
| | | // backlogged in the previous queue. If that happens, we may have to |
| | | // loop a few times to get everything in there. |
| | | while (! pendingOps.isEmpty()) |
| | | { |
| | | Iterator<AbstractOperation> iterator = pendingOps.iterator(); |
| | | while (iterator.hasNext()) |
| | | LinkedBlockingQueue<AbstractOperation> newOpQueue; |
| | | if (newMaxCapacity > 0) |
| | | { |
| | | AbstractOperation o = iterator.next(); |
| | | try |
| | | newOpQueue = |
| | | new LinkedBlockingQueue<AbstractOperation>(newMaxCapacity); |
| | | } |
| | | else |
| | | { |
| | | newOpQueue = new LinkedBlockingQueue<AbstractOperation>(); |
| | | } |
| | | |
| | | LinkedBlockingQueue<AbstractOperation> oldOpQueue = opQueue; |
| | | opQueue = newOpQueue; |
| | | |
| | | LinkedList<AbstractOperation> pendingOps = |
| | | new LinkedList<AbstractOperation>(); |
| | | oldOpQueue.drainTo(pendingOps); |
| | | |
| | | |
| | | // We have to be careful when adding any existing pending operations |
| | | // because the new capacity could be less than what was already |
| | | // backlogged in the previous queue. If that happens, we may have to |
| | | // loop a few times to get everything in there. |
| | | while (! pendingOps.isEmpty()) |
| | | { |
| | | Iterator<AbstractOperation> iterator = pendingOps.iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | if (newOpQueue.offer(o, 1000, TimeUnit.MILLISECONDS)) |
| | | AbstractOperation o = iterator.next(); |
| | | try |
| | | { |
| | | iterator.remove(); |
| | | if (newOpQueue.offer(o, 1000, TimeUnit.MILLISECONDS)) |
| | | { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | if (debugEnabled()) |
| | | catch (InterruptedException ie) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, ie); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, ie); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | maxCapacity = newMaxCapacity; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | maxCapacity = newMaxCapacity; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | queueLock.unlock(); |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | queueLock.lock(); |
| | | |
| | | try |
| | | synchronized (queueLock) |
| | | { |
| | | for (TraditionalWorkerThread t : workerThreads) |
| | | { |
| | |
| | | |
| | | return true; |
| | | } |
| | | finally |
| | | { |
| | | queueLock.unlock(); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.api.DirectoryThread; |
| | | import org.opends.server.api.ServerShutdownListener; |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | /** |
| | | * A Text Writer which writes log records asynchronously to |
| | |
| | | /** Queue to store unpublished records. */ |
| | | private final LinkedBlockingQueue<String> queue; |
| | | |
| | | /** The capacity for the queue. */ |
| | | private final int capacity; |
| | | |
| | | private String name; |
| | | private AtomicBoolean stopRequested; |
| | | private WriterThread writerThread; |
| | |
| | | this.writer = writer; |
| | | |
| | | this.queue = new LinkedBlockingQueue<String>(capacity); |
| | | this.capacity = capacity; |
| | | this.writerThread = null; |
| | | this.stopRequested = new AtomicBoolean(false); |
| | | |
| | |
| | | */ |
| | | public void run() |
| | | { |
| | | ArrayList<String> drainList = new ArrayList<String>(capacity); |
| | | |
| | | String message = null; |
| | | while (!stopRequested.get() || !queue.isEmpty()) { |
| | | try |
| | | { |
| | | message = queue.poll(10, TimeUnit.SECONDS); |
| | | if(message != null) |
| | | queue.drainTo(drainList, capacity); |
| | | if (drainList.isEmpty()) |
| | | { |
| | | do |
| | | message = queue.poll(10, TimeUnit.SECONDS); |
| | | if(message != null) |
| | | { |
| | | writer.writeRecord(message); |
| | | message = queue.poll(); |
| | | } |
| | | while(message != null); |
| | | do |
| | | { |
| | | writer.writeRecord(message); |
| | | message = queue.poll(); |
| | | } |
| | | while(message != null); |
| | | |
| | | if(autoFlush) |
| | | if(autoFlush) |
| | | { |
| | | flush(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | for (String record : drainList) |
| | | { |
| | | writer.writeRecord(record); |
| | | } |
| | | drainList.clear(); |
| | | |
| | | if (autoFlush) |
| | | { |
| | | flush(); |
| | | } |
| | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | |
| | | |
| | | // The lock used to provide threadsafe access to the set of operations in |
| | | // progress. |
| | | private ReentrantLock opsInProgressLock; |
| | | private Object opsInProgressLock; |
| | | |
| | | // The lock used to provide threadsafe access when sending data to the client. |
| | | private ReentrantLock transmitLock; |
| | | private Object transmitLock; |
| | | |
| | | // The socket channel with which this client connection is associated. |
| | | private SocketChannel clientChannel; |
| | |
| | | this.securityProvider = null; |
| | | this.clearSecurityProvider = null; |
| | | |
| | | opsInProgressLock = new ReentrantLock(); |
| | | transmitLock = new ReentrantLock(); |
| | | opsInProgressLock = new Object(); |
| | | transmitLock = new Object(); |
| | | |
| | | elementReadState = ELEMENT_READ_STATE_NEED_TYPE; |
| | | elementType = 0x00; |
| | |
| | | |
| | | // Make sure that we can only send one message at a time. This locking will |
| | | // not have any impact on the ability to read requests from the client. |
| | | transmitLock.lock(); |
| | | |
| | | try |
| | | synchronized (transmitLock) |
| | | { |
| | | try |
| | | { |
| | | int bytesWritten = messageBuffer.limit() - messageBuffer.position(); |
| | | if (! secProvider.writeData(messageBuffer)) |
| | | try |
| | | { |
| | | int bytesWritten = messageBuffer.limit() - messageBuffer.position(); |
| | | if (! secProvider.writeData(messageBuffer)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, message); |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, messageElement); |
| | | |
| | | messageBuffer.rewind(); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugData(DebugLogLevel.VERBOSE, messageBuffer); |
| | | } |
| | | |
| | | if (keepStats) |
| | | { |
| | | statTracker.updateMessageWritten(message, bytesWritten); |
| | | } |
| | | } |
| | | catch (@Deprecated Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // We were unable to send the message due to some other internal |
| | | // problem. Disconnect from the client and return. |
| | | disconnect(DisconnectReason.SERVER_ERROR, true, null); |
| | | return; |
| | | } |
| | | |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, message); |
| | | TRACER.debugProtocolElement(DebugLogLevel.VERBOSE, messageElement); |
| | | |
| | | messageBuffer.rewind(); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugData(DebugLogLevel.VERBOSE, messageBuffer); |
| | | } |
| | | |
| | | if (keepStats) |
| | | { |
| | | statTracker.updateMessageWritten(message, bytesWritten); |
| | | } |
| | | } |
| | | catch (@Deprecated Exception e) |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // We were unable to send the message due to some other internal |
| | | // problem. Disconnect from the client and return. |
| | | // FIXME -- Log a message or something |
| | | disconnect(DisconnectReason.SERVER_ERROR, true, null); |
| | | return; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // FIXME -- Log a message or something |
| | | disconnect(DisconnectReason.SERVER_ERROR, true, null); |
| | | return; |
| | | } |
| | | finally |
| | | { |
| | | transmitLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // Set a flag indicating that the connection is being terminated so that no |
| | | // new requests will be accepted. Also cancel all operations in progress. |
| | | opsInProgressLock.lock(); |
| | | |
| | | try |
| | | synchronized (opsInProgressLock) |
| | | { |
| | | disconnectRequested = true; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | disconnectRequested = true; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | opsInProgressLock.unlock(); |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | cancelAllOperations(new CancelRequest(true, message)); |
| | |
| | | |
| | | // We need to grab a lock to ensure that no one else can add operations to |
| | | // the queue while we are performing some preliminary checks. |
| | | opsInProgressLock.lock(); |
| | | |
| | | try |
| | | synchronized (opsInProgressLock) |
| | | { |
| | | // If we're already in the process of disconnecting the client, then |
| | | // reject the operation. |
| | | if (disconnectRequested) |
| | | try |
| | | { |
| | | Message message = WARN_LDAP_CLIENT_DISCONNECT_IN_PROGRESS.get(); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | // If we're already in the process of disconnecting the client, then |
| | | // reject the operation. |
| | | if (disconnectRequested) |
| | | { |
| | | Message message = WARN_LDAP_CLIENT_DISCONNECT_IN_PROGRESS.get(); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message); |
| | | } |
| | | |
| | | |
| | | // See if there is already an operation in progress with the same |
| | | // message ID. If so, then we can't allow it. |
| | | AbstractOperation op = operationsInProgress.get(messageID); |
| | | if (op != null) |
| | | { |
| | | Message message = |
| | | WARN_LDAP_CLIENT_DUPLICATE_MESSAGE_ID.get(messageID); |
| | | throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); |
| | | } |
| | | |
| | | |
| | | // Add the operation to the list of operations in progress for this |
| | | // connection. |
| | | operationsInProgress.put(messageID, operation); |
| | | |
| | | |
| | | // Try to add the operation to the work queue. |
| | | DirectoryServer.enqueueRequest(operation); |
| | | } |
| | | |
| | | |
| | | // See if there is already an operation in progress with the same message |
| | | // ID. If so, then we can't allow it. |
| | | AbstractOperation op = operationsInProgress.get(messageID); |
| | | if (op != null) |
| | | catch (DirectoryException de) |
| | | { |
| | | Message message = WARN_LDAP_CLIENT_DUPLICATE_MESSAGE_ID.get(messageID); |
| | | throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | operationsInProgress.remove(messageID); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | |
| | | throw de; |
| | | } |
| | | |
| | | |
| | | // Add the operation to the list of operations in progress for this |
| | | // connection. |
| | | operationsInProgress.put(messageID, operation); |
| | | |
| | | |
| | | // Try to add the operation to the work queue. |
| | | DirectoryServer.enqueueRequest(operation); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | catch (Exception e) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = |
| | | WARN_LDAP_CLIENT_CANNOT_ENQUEUE.get(getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | |
| | | operationsInProgress.remove(messageID); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | |
| | | throw de; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = |
| | | WARN_LDAP_CLIENT_CANNOT_ENQUEUE.get(getExceptionMessage(e)); |
| | | throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), |
| | | message, e); |
| | | } |
| | | finally |
| | | { |
| | | opsInProgressLock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | public void cancelAllOperations(CancelRequest cancelRequest) |
| | | { |
| | | // Make sure that no one can add any new operations. |
| | | opsInProgressLock.lock(); |
| | | |
| | | try |
| | | synchronized (opsInProgressLock) |
| | | { |
| | | for (AbstractOperation o : operationsInProgress.values()) |
| | | try |
| | | { |
| | | try |
| | | { |
| | | CancelResult cancelResult = o.cancel(cancelRequest); |
| | | if (keepStats && (cancelResult == CancelResult.CANCELED)) |
| | | { |
| | | statTracker.updateAbandonedOperation(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (! (operationsInProgress.isEmpty() && |
| | | getPersistentSearches().isEmpty())) |
| | | { |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | } |
| | | |
| | | operationsInProgress.clear(); |
| | | |
| | | |
| | | for (PersistentSearch persistentSearch : getPersistentSearches()) |
| | | { |
| | | DirectoryServer.deregisterPersistentSearch(persistentSearch); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | opsInProgressLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Attempts to cancel all operations in progress on this connection except the |
| | | * operation with the specified message ID. |
| | | * |
| | | * @param cancelRequest An object providing additional information about how |
| | | * the cancel should be processed. |
| | | * @param messageID The message ID of the operation that should not be |
| | | * canceled. |
| | | */ |
| | | public void cancelAllOperationsExcept(CancelRequest cancelRequest, |
| | | int messageID) |
| | | { |
| | | // Make sure that no one can add any new operations. |
| | | opsInProgressLock.lock(); |
| | | |
| | | try |
| | | { |
| | | for (int msgID : operationsInProgress.keySet()) |
| | | { |
| | | if (msgID == messageID) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | AbstractOperation o = operationsInProgress.get(msgID); |
| | | if (o != null) |
| | | for (AbstractOperation o : operationsInProgress.values()) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | operationsInProgress.remove(msgID); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | } |
| | | if (! (operationsInProgress.isEmpty() && |
| | | getPersistentSearches().isEmpty())) |
| | | { |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | } |
| | | |
| | | operationsInProgress.clear(); |
| | | |
| | | |
| | | for (PersistentSearch persistentSearch : getPersistentSearches()) |
| | | for (PersistentSearch persistentSearch : getPersistentSearches()) |
| | | { |
| | | DirectoryServer.deregisterPersistentSearch(persistentSearch); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | DirectoryServer.deregisterPersistentSearch(persistentSearch); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Attempts to cancel all operations in progress on this connection except the |
| | | * operation with the specified message ID. |
| | | * |
| | | * @param cancelRequest An object providing additional information about how |
| | | * the cancel should be processed. |
| | | * @param messageID The message ID of the operation that should not be |
| | | * canceled. |
| | | */ |
| | | public void cancelAllOperationsExcept(CancelRequest cancelRequest, |
| | | int messageID) |
| | | { |
| | | // Make sure that no one can add any new operations. |
| | | synchronized (opsInProgressLock) |
| | | { |
| | | if (debugEnabled()) |
| | | try |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | for (int msgID : operationsInProgress.keySet()) |
| | | { |
| | | if (msgID == messageID) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | AbstractOperation o = operationsInProgress.get(msgID); |
| | | if (o != null) |
| | | { |
| | | try |
| | | { |
| | | CancelResult cancelResult = o.cancel(cancelRequest); |
| | | if (keepStats && (cancelResult == CancelResult.CANCELED)) |
| | | { |
| | | statTracker.updateAbandonedOperation(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | operationsInProgress.remove(msgID); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | } |
| | | |
| | | |
| | | for (PersistentSearch persistentSearch : getPersistentSearches()) |
| | | { |
| | | DirectoryServer.deregisterPersistentSearch(persistentSearch); |
| | | lastCompletionTime.set(TimeThread.getTime()); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | opsInProgressLock.unlock(); |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.protocols.ldap; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.std.server.MonitorProviderCfg; |
| | | import org.opends.server.api.MonitorProvider; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.messages.ProtocolMessages.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.protocols.ldap.LDAPConstants.*; |
| | | |
| | | |
| | |
| | | // The locks used to provide threadsafe access to this class. In this case, |
| | | // read and write refer to the type of LDAP communication, not access to the |
| | | // protected data. |
| | | private ReentrantLock abandonLock; |
| | | private ReentrantLock connectLock; |
| | | private ReentrantLock disconnectLock; |
| | | private ReentrantLock readLock; |
| | | private ReentrantLock writeLock; |
| | | private Object abandonLock; |
| | | private Object connectLock; |
| | | private Object disconnectLock; |
| | | private Object readLock; |
| | | private Object writeLock; |
| | | |
| | | // The instance name for this monitor provider instance. |
| | | private String instanceName; |
| | |
| | | this.instanceName = instanceName; |
| | | this.parent = parent; |
| | | |
| | | abandonLock = new ReentrantLock(); |
| | | connectLock = new ReentrantLock(); |
| | | disconnectLock = new ReentrantLock(); |
| | | readLock = new ReentrantLock(); |
| | | writeLock = new ReentrantLock(); |
| | | abandonLock = new Object(); |
| | | connectLock = new Object(); |
| | | disconnectLock = new Object(); |
| | | readLock = new Object(); |
| | | writeLock = new Object(); |
| | | |
| | | abandonRequests = 0; |
| | | addRequests = 0; |
| | |
| | | // Quickly grab the locks and store consistent copies of the information. |
| | | // Note that when grabbing multiple locks, it is essential that they are all |
| | | // acquired in the same order to prevent deadlocks. |
| | | abandonLock.lock(); |
| | | |
| | | try |
| | | synchronized (abandonLock) |
| | | { |
| | | connectLock.lock(); |
| | | |
| | | try |
| | | synchronized (connectLock) |
| | | { |
| | | disconnectLock.lock(); |
| | | |
| | | try |
| | | synchronized (disconnectLock) |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | tmpAbandonRequests = abandonRequests; |
| | | tmpAddRequests = addRequests; |
| | |
| | | tmpSearchResultsDone = searchResultsDone; |
| | | tmpUnbindRequests = unbindRequests; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return attrs; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return attrs; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return attrs; |
| | | } |
| | | finally |
| | | { |
| | | disconnectLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return attrs; |
| | | } |
| | | finally |
| | | { |
| | | connectLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | return attrs; |
| | | } |
| | | finally |
| | | { |
| | | abandonLock.unlock(); |
| | | } |
| | | |
| | | |
| | |
| | | // Quickly grab the locks and store consistent copies of the information. |
| | | // Note that when grabbing multiple locks, it is essential that they are all |
| | | // acquired in the same order to prevent deadlocks. |
| | | abandonLock.lock(); |
| | | |
| | | try |
| | | synchronized (abandonLock) |
| | | { |
| | | connectLock.lock(); |
| | | |
| | | try |
| | | synchronized (connectLock) |
| | | { |
| | | disconnectLock.lock(); |
| | | |
| | | try |
| | | synchronized (disconnectLock) |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | abandonRequests = 0; |
| | | addRequests = 0; |
| | |
| | | searchResultsDone = 0; |
| | | unbindRequests = 0; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | disconnectLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | connectLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | abandonLock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public void updateConnect() |
| | | { |
| | | connectLock.lock(); |
| | | |
| | | try |
| | | synchronized (connectLock) |
| | | { |
| | | connectionsEstablished++; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | connectLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public void updateDisconnect() |
| | | { |
| | | disconnectLock.lock(); |
| | | |
| | | try |
| | | synchronized (disconnectLock) |
| | | { |
| | | connectionsClosed++; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | disconnectLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public void updateBytesRead(int bytesRead) |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | this.bytesRead += bytesRead; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public void updateMessageRead(LDAPMessage message) |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | messagesRead++; |
| | | operationsInitiated++; |
| | |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public void updateMessageWritten(LDAPMessage message, int bytesWritten) |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | this.bytesWritten += bytesWritten; |
| | | messagesWritten++; |
| | |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public void updateAbandonedOperation() |
| | | { |
| | | abandonLock.lock(); |
| | | |
| | | try |
| | | synchronized (abandonLock) |
| | | { |
| | | operationsAbandoned++; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | abandonLock.unlock(); |
| | | } |
| | | |
| | | // Update the parent if there is one. |
| | | if (parent != null) |
| | |
| | | */ |
| | | public long getConnectionsEstablished() |
| | | { |
| | | connectLock.lock(); |
| | | |
| | | try |
| | | synchronized (connectLock) |
| | | { |
| | | return connectionsEstablished; |
| | | } |
| | | finally |
| | | { |
| | | connectLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getConnectionsClosed() |
| | | { |
| | | disconnectLock.lock(); |
| | | |
| | | try |
| | | synchronized (disconnectLock) |
| | | { |
| | | return connectionsClosed; |
| | | } |
| | | finally |
| | | { |
| | | disconnectLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getBytesRead() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return bytesRead; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getBytesWritten() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return bytesWritten; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getMessagesRead() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return messagesRead; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getMessagesWritten() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return messagesWritten; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getOperationsInitiated() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return operationsInitiated; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getOperationsCompleted() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return operationsCompleted; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getOperationsAbandoned() |
| | | { |
| | | abandonLock.lock(); |
| | | |
| | | try |
| | | synchronized (abandonLock) |
| | | { |
| | | return operationsAbandoned; |
| | | } |
| | | finally |
| | | { |
| | | abandonLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getAbandonRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return abandonRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getAddRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return addRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getAddResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return addResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getBindRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return bindRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getBindResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return bindResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getCompareRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return compareRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getCompareResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return compareResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getDeleteRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return deleteRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getDeleteResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return deleteResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getExtendedRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return extendedRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getExtendedResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return extendedResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getModifyRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return modifyRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getModifyResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return modifyResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getModifyDNRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return modifyDNRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getModifyDNResponses() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return modifyDNResponses; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getSearchRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return searchRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getSearchResultEntries() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return searchResultEntries; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getSearchResultReferences() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return searchResultReferences; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getSearchResultsDone() |
| | | { |
| | | writeLock.lock(); |
| | | |
| | | try |
| | | synchronized (writeLock) |
| | | { |
| | | return searchResultsDone; |
| | | } |
| | | finally |
| | | { |
| | | writeLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public long getUnbindRequests() |
| | | { |
| | | readLock.lock(); |
| | | |
| | | try |
| | | synchronized (readLock) |
| | | { |
| | | return unbindRequests; |
| | | } |
| | | finally |
| | | { |
| | | readLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.TimeZone; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.server.admin.std.server.EqualityMatchingRuleCfg; |
| | | import org.opends.server.api.EqualityMatchingRule; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | |
| | | /** |
| | | * The lock that will be used to provide threadsafe access to the date |
| | | * formatter. |
| | | */ |
| | | private static ReentrantLock dateFormatLock; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The date formatter that will be used to convert dates into generalized time |
| | | * values. Note that all interaction with it must be synchronized. |
| | | */ |
| | | private static SimpleDateFormat dateFormat; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The time zone used for UTC time. |
| | | */ |
| | | private static TimeZone utcTimeZone; |
| | | |
| | | |
| | | |
| | | /* |
| | | * Create the date formatter that will be used to construct and parse |
| | | * normalized generalized time values. |
| | | */ |
| | | static |
| | | { |
| | | utcTimeZone = TimeZone.getTimeZone("UTC"); |
| | | |
| | | dateFormat = new SimpleDateFormat(DATE_FORMAT_GENERALIZED_TIME); |
| | | dateFormat.setLenient(false); |
| | | dateFormat.setTimeZone(utcTimeZone); |
| | | |
| | | dateFormatLock = new ReentrantLock(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.TimeZone; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.server.admin.std.server.OrderingMatchingRuleCfg; |
| | | import org.opends.server.api.OrderingMatchingRule; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | |
| | | |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class defines the generalizedTimeOrderingMatch matching rule defined in |
| | | * X.520 and referenced in RFC 2252. |
| | |
| | | */ |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * The serial version identifier required to satisfy the compiler because this |
| | | * class implements the <CODE>java.io.Serializable</CODE> interface. This |
| | |
| | | |
| | | |
| | | /** |
| | | * The lock that will be used to provide threadsafe access to the date |
| | | * formatter. |
| | | */ |
| | | private static ReentrantLock dateFormatLock; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The date formatter that will be used to convert dates into generalized time |
| | | * values. Note that all interaction with it must be synchronized. |
| | | */ |
| | | private static SimpleDateFormat dateFormat; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The time zone used for UTC time. |
| | | */ |
| | | private static TimeZone utcTimeZone; |
| | | |
| | | |
| | | |
| | | /* |
| | | * Create the date formatter that will be used to construct and parse |
| | | * normalized generalized time values. |
| | | */ |
| | | static |
| | | { |
| | | utcTimeZone = TimeZone.getTimeZone("UTC"); |
| | | |
| | | dateFormat = new SimpleDateFormat(DATE_FORMAT_GENERALIZED_TIME); |
| | | dateFormat.setLenient(false); |
| | | dateFormat.setTimeZone(utcTimeZone); |
| | | |
| | | dateFormatLock = new ReentrantLock(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new instance of this generalizedTimeMatch matching rule. |
| | | */ |
| | | public GeneralizedTimeOrderingMatchingRule() |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.schema; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.TimeZone; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.server.admin.std.server.AttributeSyntaxCfg; |
| | | import org.opends.server.api.ApproximateMatchingRule; |
| | | import org.opends.server.api.AttributeSyntax; |
| | |
| | | import org.opends.server.api.SubstringMatchingRule; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | |
| | | |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.messages.SchemaMessages.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.messages.SchemaMessages.*; |
| | | import org.opends.messages.MessageBuilder; |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | |
| | | * The lock that will be used to provide threadsafe access to the date |
| | | * formatter. |
| | | */ |
| | | private static ReentrantLock dateFormatLock; |
| | | private static Object dateFormatLock; |
| | | |
| | | |
| | | |
| | |
| | | dateFormat.setLenient(false); |
| | | dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); |
| | | |
| | | dateFormatLock = new ReentrantLock(); |
| | | dateFormatLock = new Object(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public static String format(Date d) |
| | | { |
| | | dateFormatLock.lock(); |
| | | |
| | | try |
| | | synchronized (dateFormatLock) |
| | | { |
| | | return dateFormat.format(d); |
| | | } |
| | | finally |
| | | { |
| | | dateFormatLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public static String format(long t) |
| | | { |
| | | dateFormatLock.lock(); |
| | | |
| | | try |
| | | synchronized (dateFormatLock) |
| | | { |
| | | return dateFormat.format(new Date(t)); |
| | | } |
| | | finally |
| | | { |
| | | dateFormatLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | String valueString; |
| | | |
| | | dateFormatLock.lock(); |
| | | |
| | | try |
| | | synchronized (dateFormatLock) |
| | | { |
| | | valueString = dateFormat.format(new Date(time)); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This should never happen. |
| | | valueString = null; |
| | | } |
| | | finally |
| | | { |
| | | dateFormatLock.unlock(); |
| | | } |
| | | |
| | | return new AttributeValue(new ASN1OctetString(valueString), |
| | | new ASN1OctetString(valueString)); |
| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.schema; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.TimeZone; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.server.admin.std.server.AttributeSyntaxCfg; |
| | | import org.opends.server.api.ApproximateMatchingRule; |
| | | import org.opends.server.api.AttributeSyntax; |
| | |
| | | import org.opends.server.api.SubstringMatchingRule; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.types.DirectoryException; |
| | | |
| | | |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.messages.SchemaMessages.*; |
| | | import org.opends.messages.MessageBuilder; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | |
| | | * The lock that will be used to provide threadsafe access to the date |
| | | * formatter. |
| | | */ |
| | | private static ReentrantLock dateFormatLock; |
| | | private static Object dateFormatLock; |
| | | |
| | | |
| | | |
| | |
| | | dateFormat.setLenient(false); |
| | | dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); |
| | | |
| | | dateFormatLock = new ReentrantLock(); |
| | | dateFormatLock = new Object(); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | String valueString; |
| | | |
| | | dateFormatLock.lock(); |
| | | |
| | | try |
| | | synchronized (dateFormatLock) |
| | | { |
| | | valueString = dateFormat.format(d); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This should never happen. |
| | | valueString = null; |
| | | } |
| | | finally |
| | | { |
| | | dateFormatLock.unlock(); |
| | | } |
| | | |
| | | return new AttributeValue(new ASN1OctetString(valueString), |
| | | new ASN1OctetString(valueString)); |
| | |
| | | String valueString = normalizedValue.stringValue(); |
| | | try |
| | | { |
| | | dateFormatLock.lock(); |
| | | |
| | | try |
| | | synchronized (dateFormatLock) |
| | | { |
| | | return dateFormat.parse(valueString); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // We'll let this be handled by the outer loop. |
| | | throw e; |
| | | } |
| | | finally |
| | | { |
| | | dateFormatLock.unlock(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | /* All Rights Reserved */ |
| | | package org.opends.server.util; |
| | | |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | |
| | | /** |
| | | * UNIX Crypt cipher, ported from the Sun OpenSolaris project. |
| | |
| | | } |
| | | } |
| | | |
| | | private ReentrantLock digestLock = new ReentrantLock(); |
| | | private Object digestLock = new Object(); |
| | | |
| | | /** |
| | | * Encode the supplied password in unix crypt form with the provided |
| | |
| | | * */ |
| | | public byte[] crypt(byte[] pw, byte[] salt) |
| | | { |
| | | digestLock.lock(); |
| | | int[] r; |
| | | try |
| | | synchronized (digestLock) |
| | | { |
| | | r = _crypt(pw, salt); |
| | | } |
| | | finally |
| | | { |
| | | digestLock.unlock(); |
| | | } |
| | | |
| | | //TODO: crypt always returns same size array? So don't mess |
| | | // around calculating the number of zeros at the end. |