Implementation of Realm that works with a directory server accessed via the Java Naming and Directory Interface (JNDI) APIs. The following constraints are imposed on the data structure in the underlying directory server:
DirContext that is accessed via the connectionURL property.connectURL an attempt will be made to use the
alternateURL if it exists.userPattern property.userPattern property is not specified, a unique element can be located by
searching the directory context. In this case:
userSearch pattern specifies the search filter after substitution of the username.userBase property can be set to the element that is the base of the subtree containing users. If
not specified, the search base is the top-level context.userSubtree property can be set to true if you wish to search the entire subtree of
the directory context. The default value of false requests a search of only the current level.userPassword property is not specified.userPassword property is
specified, in which case:
userPassword property.
RealmBase.digest() method (using the standard digest support included in
RealmBase).
RealmBase.digest()) are equal to the retrieved value for the user password attribute.DirContext that is accessed via the connectionURL property. This element has the
following characteristics:
roleSearch property.roleSearch pattern optionally includes pattern replacements "{0}" for the distinguished name,
and/or "{1}" for the username, and/or "{2}" the value of an attribute from the user's directory entry (the attribute
is specified by the userRoleAttribute property), of the authenticated user for which roles will be
retrieved.roleBase property can be set to the element that is the base of the search for matching roles.
If not specified, the entire context will be searched.roleSubtree property can be set to true if you wish to search the entire subtree of
the directory context. The default value of false requests a search of only the current level.roleName property) containing the
name of the role represented by this element.userRoleName property.commonRole property to the name of this role. The role doesn't have to exist in the directory.roleNested to
true. The default value is false, so role searches will not find nested roles.<security-role-ref> element in the web application deployment
descriptor allows applications to refer to roles programmatically by names other than those used in the directory
server itself.Warning
- There is a reported bug against the Netscape provider code (com.netscape.jndi.ldap.LdapContextFactory) with respect to successfully authenticated a non-existing user. The report is here: https://bz.apache.org/bugzilla/show_bug.cgi?id=11210 . With luck, Netscape has updated their provider code and this is not an issue.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | JNDIRealm.
Class holding the connection to the directory plus the associated non thread safe message formats. |
| protected static class | JNDIRealm.
A protected class representing a User |
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | adCompat
Should we ignore PartialResultExceptions when iterating over NamingEnumerations? |
| protected String | alternateURL
An alternate URL, to which, we should connect if connectionURL fails. |
| protected String | authentication
The type of authentication to use |
| private String | cipherSuites
Comma separated list of cipher suites to use for StartTLS. |
| private String[] | cipherSuitesArray
The list of enabled cipher suites used for establishing tls connections. |
| protected String | commonRole
Add this role to every authenticated user |
| protected int | connectionAttempt
The number of connection attempts. |
| protected String | connectionName
The connection username for the server we will contact. |
| protected String | connectionPassword
The connection password for the server we will contact. |
| protected SynchronizedStack | connectionPool
Connection pool. |
| protected int | connectionPoolSize
The pool size limit. |
| protected String | connectionTimeout
The timeout, in milliseconds, to use when trying to create a connection to the directory. |
| protected String | connectionURL
The connection URL for the server we will contact. |
| protected String | contextFactory
The JNDI context factory used to acquire our InitialContext. |
| public static final String | DEREF_ALIASES
Constant that holds the name of the environment property for specifying the manner in which aliases should be dereferenced. |
| protected String | derefAliases
How aliases should be dereferenced during search operations. |
| private boolean | |
| private HostnameVerifier | hostnameVerifier
Verifier for hostnames in a StartTLS secured connection. |
| private String | hostNameVerifierClassName
Name of the class of the |
| protected String | protocol
The protocol that will be used in the communication with the directory server. |
| protected String | readTimeout
The timeout, in milliseconds, to use when trying to read from a connection to the directory. |
| protected String | referrals
How should we handle referrals? |
| protected String | roleBase
The base element for role searches. |
| protected String | roleName
The name of the attribute containing roles held elsewhere |
| protected boolean | roleNested
Should we look for nested group in order to determine roles? |
| protected String | roleSearch
The message format used to select roles for a user, with "{0}" marking the spot where the distinguished name of the user goes. |
| protected boolean | roleSearchAsUser
When searching for user roles, should the search be performed as the user currently being authenticated? |
| protected boolean | roleSubtree
Should we search the entire subtree for matching memberships? |
| protected JNDIRealm. | singleConnection
Non pooled connection to our directory server. |
| protected final Lock | singleConnectionLock
The lock to ensure single connection thread safety. |
| protected long | sizeLimit
The sizeLimit (also known as the countLimit) to use when the realm is configured with |
| protected String | spnegoDelegationQop
The QOP that should be used for the connection to the LDAP server after authentication. |
| private String | sslProtocol
The ssl Protocol which will be used by StartTLS. |
| private SSLSocketFactory | sslSocketFactory
|
| private String | sslSocketFactoryClassName
Name of the class of the |
| protected int | timeLimit
The timeLimit (in milliseconds) to use when the realm is configured with |
| private StartTlsResponse | |
| protected boolean | useContextClassLoader
Whether to use context ClassLoader or default ClassLoader. |
| protected boolean | useDelegatedCredential
Should delegated credentials from the SPNEGO authenticator be used if available |
| protected String | userBase
The base element for user searches. |
| protected String | userPassword
The attribute name used to retrieve the user password. |
| protected String | userPattern
The message format used to form the distinguished name of a user, with "{0}" marking the spot where the specified username goes. |
| protected String[] | userPatternArray
A string of LDAP user patterns or paths, ":"-separated These will be used to form the distinguished name of a user, with "{0}" marking the spot where the specified username goes. |
| protected String | userRoleAttribute
The name of the attribute inside the users directory entry where the value will be taken to search for roles This attribute is not used during a nested search |
| protected String | userRoleName
The name of an attribute in the user's entry containing roles for that user |
| protected String | userSearch
The message format used to search for a user, with "{0}" marking the spot where the username goes. |
| private boolean | userSearchAsUser
When searching for users, should the search be performed as the user currently being authenticated? |
| protected boolean | userSubtree
Should we search the entire subtree for matching users? |
| private boolean | useStartTls
Whether to use TLS for connections |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private ArrayList | Returns: the list of attribute valuesAttribute name attrId, Attributes Attributes containing the new values attrs, ArrayList<String> ArrayList containing values found so far values)Add values of a specified attribute to a list |
| public Principal | authenticate(String
Username of the Principal to look up username, String Password or other credentials to use in
authenticating this username credentials)Overrides org. Implements org. Try to authenticate using the specified username and credentials. |
| public Principal | Returns: the associated principal, ornull if there is none.The directory context connection,Username of the Principal to look up username, String Password or other credentials to use in authenticating this username credentials)Return the Principal associated with the specified username and credentials, if there is one; otherwise return
|
| public Principal | authenticate(String
Username of the Principal to look up username)Overrides org. Implements org. Try to authenticate with the specified username. |
| public Principal | authenticate(String
Username of the Principal to look up username, String Digest which has been submitted by the client clientDigest, String Unique (or supposedly unique) token which has been used
for this request nonce, String the nonce counter nc, String the client chosen nonce cnonce, String the "quality of protection" ( qop, String nc and cnonce
will only be used, if qop is not null).Realm name realm, String Second digest calculated as digest(Method + ":" + uri) digestA2, String The message digest algorithm to use algorithm)Overrides org. Overrides default org. Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616. |
| public Principal | authenticate(X509Certificate[]
Array of client certificates, with the first one in
the array being the certificate of the client itself. certs)Overrides org. Implements org. Try to authenticate using a chain of |
| public Principal | authenticate(GSSContext
The gssContext processed by the gssContext, boolean Authenticator.Should the realm attempt to store the delegated
credentials in the returned Principal? storeCred)Overrides org. Implements org. Try to authenticate using a |
| public Principal | authenticate(GSSName
The gssName, GSSCredential GSSName of the principal to look upThe gssCredential)GSSCredential of the principal, may be
nullOverrides org. Implements org. Try to authenticate using a |
| protected boolean | Returns: true if the credentials are validatedThe directory context context, JNDIRealm.The User to be authenticated user,Authentication credentials credentials)Check credentials by binding to the directory as the user |
| protected boolean | Returns: true if the credentials are validatedThe directory context context, JNDIRealm.The User to be authenticated user,The credentials presented by the user credentials)Check whether the given User can be authenticated with the given credentials. |
| protected void | close(JNDIRealm.
The directory context to be closed connectionClose any open connection to the directory server for this Realm. |
| protected void | |
| protected boolean | Returns: true if the credentials are validatedThe directory context context, JNDIRealm.The User to be authenticated info,Authentication credentials credentials)Check whether the credentials presented by the user match those retrieved from the directory. |
| private Object | |
| protected static String | |
| protected JNDIRealm. | |
| private DirContext | |
| private SSLSocketFactory | |
| private SSLSocketFactory | |
| private DirContext | Returns: configuredLdapContextEnvironment to use for context creation env)Create a tls enabled LdapContext and set the StartTlsResponse tls instance variable. |
| protected String | Returns: The string representation of the attribute valueThe original attribute value input)Implements the necessary escaping to represent an attribute value as a String as per RFC 4514. |
| protected String | Returns: String the escaped/encoded resultstring to escape according to RFC 2254 guidelines inString)Given an LDAP search string, returns the string with certain characters escaped according to RFC 2254 guidelines. |
| protected JNDIRealm. | Returns: the connectionOpen (if necessary) and return a connection to the configured directory server for this Realm. |
| public boolean | |
| public String | |
| private String | Returns: the attribute valueAttribute name attrId, Attributes Attributes containing the required value attrs)Return a String representing the value of the specified attribute. |
| public String | |
| private String[] | Returns: list of the allowed cipher suites when connections are made using StartTLS
|
| public String | |
| public String | |
| public String | |
| public int | Returns: the connection pool size, or the default value 1 if pooling is disabled
|
| public String | |
| public String | |
| public String | |
| public String | |
| protected Hashtable | Returns: java.util.Hashtable the configuration for the directory context.Create our directory context configuration. |
| protected String | Returns: String containing the distinguished nameOur DirContext context, String The base DN base, SearchResult The search result result)Returns the distinguished name of a search result. |
| public boolean | |
| public HostnameVerifier | Returns: theHostnameVerifier to use for peer certificate verification when opening connections using
StartTLS.
|
| public String | Returns: name of theHostnameVerifier class used for connections using StartTLS, or the empty string, if
the default verifier should be used.
|
| protected String | Returns: the password associated with the given principal's user name.The user name username)Implements abstract org. Get the password for the specified user. |
| protected Principal | Returns: the Principal associated with the given certificate.The user name username)Implements abstract org. Get the principal associated with the specified certificate. |
| protected Principal | getPrincipal(GSSName
The GSS name gssName, GSSCredential the GSS credential of the principal gssCredential)Overrides org. Get the principal associated with the specified |
| protected Principal | |
| protected Principal | Returns: the Principal associated with the given certificate.The directory context connection,The user name username, GSSCredential The credentials gssCredential)Get the principal associated with the specified certificate. |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | |
| public boolean | |
| protected List | Returns: the list of role namesThe directory context we are searching connection,The User to be checked userReturn a List of roles associated with the given User. |
| public String | |
| public boolean | |
| public long | |
| public String | |
| private SSLSocketFactory | |
| private String[] | |
| public int | |
| protected JNDIRealm. | Returns: the User objectThe directory context connection,Username to be looked up username)Return a User object containing information about the user with the specified username, if found in the
directory; otherwise return |
| protected JNDIRealm. | Returns: the User objectThe directory context connection,Username to be looked up username, String User credentials (optional) credentials)Return a User object containing information about the user with the specified username, if found in the
directory; otherwise return |
| protected JNDIRealm. | Returns: the User objectThe directory context connection,Username to be looked up username, String User credentials (optional) credentials, int Index into userPatternFormatArray curUserPattern)Return a User object containing information about the user with the specified username, if found in the
directory; otherwise return |
| public String | |
| protected JNDIRealm. | Returns: the User objectThe directory context context, String The username username, String[] String[]containing names of attributes to attrIds, String Distinguished name of the user retrieve. dn)Use the distinguished name to locate the directory entry for the user with the specified username and return a
User object; otherwise return |
| protected JNDIRealm. | Returns: the User objectThe directory context connection,The username username, String User credentials (optional) credentials, String[] String[]containing names of attributes to attrIds, int Index into userPatternFormatArray curUserPattern)Use the |
| protected JNDIRealm. | Returns: the User objectThe directory context connection,The username username, String[] String[]containing names of attributes to retrieve. attrIds)Search the directory to return a User object containing information about the user with the specified username,
if found in the directory; otherwise return |
| public String | |
| public String | |
| public String | |
| public String | |
| public String | |
| public boolean | |
| public boolean | |
| public boolean | isAvailable()
Overrides default org. Return the availability of the realm for authentication. |
| public boolean | |
| public boolean | Returns: The value of useContextClassLoaderReturns whether to use the context or default ClassLoader. |
| public boolean | |
| public boolean | |
| protected void | open(JNDIRealm.
The directory server connection wrapper connectionCreate a new connection to the directory server. |
| protected String[] | Returns: a parsed string array- a string LDAP search paths surrounded by parentheses userPatternString)Given a string containing LDAP patterns for user locations (separated by parentheses in a pseudo-LDAP search string format - "(location1)(location2)", returns an array of those paths. |
| protected void | release(JNDIRealm.
The directory context to release connectionRelease our use of this connection so that it can be recycled. |
| private void | restoreEnvironmentParameter(DirContext context, String parameterName, Hashtable<?, ?> preservedEnvironment)
|
| private NamingEnumeration | Returns: enumeration with all found entriescontext to search on context, JNDIRealm.user to bind on user,base to start the search from base, String filter to use for the search filter, SearchControls controls to use for the search controls, boolean true when the search should be done as user, or false for using the default
credentialsPerform the search on the context as the |
| public void | setAdCompat(boolean
true to ignore partial resultsHow do we handle PartialResultExceptions? |
| public void | setAlternateURL(String
New value of property alternateURL. alternateURL)Setter for property alternateURL. |
| public void | |
| public void | setCipherSuites(String
comma separated list of allowed cipher suites suites)Set the allowed cipher suites when opening a connection using StartTLS. |
| public void | |
| public void | setConnectionName(String
The new connection username connectionName)Set the connection username for this Realm. |
| public void | setConnectionPassword(String
The new connection password connectionPassword)Set the connection password for this Realm. |
| public void | |
| public void | |
| public void | |
| public void | setContextFactory(String
The new context factory contextFactory)Set the JNDI context factory for this Realm. |
| public void | setDerefAliases(String
New value of property derefAliases. derefAliases)Set the value for derefAliases to be used when searching the directory. |
| public void | |
| public void | setHostnameVerifierClassName(String
class name of the verifierClassName)HostnameVerifier to be constructedSet the |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setRoleName(String
The new role name attribute name roleName)Set the role name attribute name for this Realm. |
| public void | setRoleNested(boolean
The nested group search flag roleNested)Set the "search subtree for roles" flag. |
| public void | setRoleSearch(String
The new role search pattern roleSearch)Set the message format pattern for selecting roles in this Realm. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setSslProtocol(String
one of the allowed ssl protocol names protocol)Set the ssl protocol to be used for connections using StartTLS. |
| public void | setSslSocketFactoryClassName(String
class name of the factory to be constructed factoryClassName)Set the |
| public void | |
| public void | setUseContextClassLoader(boolean
True means use context ClassLoader useContext)Sets whether to use the context or default ClassLoader. |
| public void | |
| public void | |
| public void | setUserPassword(String
The new password attribute userPassword)Set the password attribute used to retrieve the user password. |
| public void | setUserPattern(String
The new user pattern userPattern)Set the message format pattern for selecting users in this Realm. |
| public void | |
| public void | setUserRoleName(String
The new userRole name attribute name userRoleName)Set the user role name attribute name for this Realm. |
| public void | setUserSearch(String
The new user search pattern userSearch)Set the message format pattern for selecting users in this Realm. |
| public void | |
| public void | |
| public void | setUseStartTls(boolean
true when StartTLS should be used. Default is false.Flag whether StartTLS should be used when connecting to the ldap server |
| protected void | startInternal()
Overrides org. Prepare for the beginning of active use of the public methods of this component and implement the requirements of
|
| protected void | stopInternal()
Overrides org. Gracefully terminate the active use of the public methods of this component and implement the requirements of
|
| private void | userCredentialsAdd(DirContext
DirContext to configure context, String Distinguished name of user dn, String Credentials of user credentials)Configure the context to use the provided credentials for authentication. |
| private void | userCredentialsRemove(DirContext
DirContext to configure context)Configure the context to use |