public class SimpleAuthenticator extends AbstractAuthenticator
Authenticator that authenticates clear text passwords
contained within the userPassword attribute in DIT. If the
password is stored with a one-way encryption applied (e.g. SHA), the password
is hashed the same way before comparison.
We use a cache to speedup authentication, where the Dn/password are stored.| Modifier and Type | Field and Description |
|---|---|
private org.apache.commons.collections.map.LRUMap |
credentialCache
A cache to store passwords.
|
private static int |
DEFAULT_CACHE_SIZE
Declare a default for this cache.
|
private static boolean |
IS_DEBUG
A speedup for logger in debug mode
|
LOG| Constructor and Description |
|---|
SimpleAuthenticator()
Creates a new instance.
|
SimpleAuthenticator(org.apache.directory.api.ldap.model.name.Dn baseDn)
Creates a new instance.
|
SimpleAuthenticator(int cacheSize)
Creates a new instance, with an initial cache size
|
SimpleAuthenticator(int cacheSize,
org.apache.directory.api.ldap.model.name.Dn baseDn)
Creates a new instance, with an initial cache size
|
| Modifier and Type | Method and Description |
|---|---|
LdapPrincipal |
authenticate(BindOperationContext bindContext)
Looks up userPassword attribute of the entry whose name is the
value of
Context#SECURITY_PRINCIPAL environment variable, and
authenticates a user with the plain-text password. |
protected java.lang.String |
createDigestedPassword(java.lang.String algorithm,
byte[] password)
Creates a digested password.
|
protected java.lang.String |
getAlgorithmForHashedPassword(byte[] password)
Get the algorithm of a password, which is stored in the form "{XYZ}...".
|
private LdapPrincipal |
getStoredPassword(BindOperationContext bindContext)
Get the password either from cache or from backend.
|
void |
invalidateCache(org.apache.directory.api.ldap.model.name.Dn bindDn)
Remove the principal form the cache.
|
private byte[][] |
lookupUserPassword(BindOperationContext bindContext)
Local function which request the password from the backend
|
checkPwdPolicy, destroy, doDestroy, doInit, getAuthenticatorType, getBaseDn, getDirectoryService, init, isValid, setBaseDnprivate static final boolean IS_DEBUG
private final org.apache.commons.collections.map.LRUMap credentialCache
private static final int DEFAULT_CACHE_SIZE
public SimpleAuthenticator()
public SimpleAuthenticator(org.apache.directory.api.ldap.model.name.Dn baseDn)
AbstractAuthenticatorpublic SimpleAuthenticator(int cacheSize)
cacheSize - the size of the credential cachepublic SimpleAuthenticator(int cacheSize,
org.apache.directory.api.ldap.model.name.Dn baseDn)
cacheSize - the size of the credential cacheprivate LdapPrincipal getStoredPassword(BindOperationContext bindContext) throws org.apache.directory.api.ldap.model.exception.LdapException
principalDN - The Dn from which we want the passwordjava.lang.Exception - If we have a problem during the lookup operationorg.apache.directory.api.ldap.model.exception.LdapExceptionpublic LdapPrincipal authenticate(BindOperationContext bindContext) throws org.apache.directory.api.ldap.model.exception.LdapException
Looks up userPassword attribute of the entry whose name is the
value of Context#SECURITY_PRINCIPAL environment variable, and
authenticates a user with the plain-text password.
bindContext - The Bind contextorg.apache.directory.api.ldap.model.exception.LdapExceptionprivate byte[][] lookupUserPassword(BindOperationContext bindContext) throws org.apache.directory.api.ldap.model.exception.LdapException
bindContext - the Bind operation contextjava.lang.Exception - if there are problems accessing backendorg.apache.directory.api.ldap.model.exception.LdapExceptionprotected java.lang.String getAlgorithmForHashedPassword(byte[] password)
throws java.lang.IllegalArgumentException
password - a byte[]java.lang.IllegalArgumentException - if the algorithm cannot be identifiedprotected java.lang.String createDigestedPassword(java.lang.String algorithm,
byte[] password)
throws java.lang.IllegalArgumentException
algorithm - an algorithm which is supported by
java.security.MessageDigest, e.g. SHApassword - password value, a byte[]java.lang.IllegalArgumentException - if password is neither a String nor a byte[], or algorithm is
not known to java.security.MessageDigest classpublic void invalidateCache(org.apache.directory.api.ldap.model.name.Dn bindDn)
invalidateCache in interface AuthenticatorinvalidateCache in class AbstractAuthenticatorbindDn - the already normalized distinguished name of the bind principal