public class JNDIDirectory extends java.lang.Object implements LdapDirectory
By default, referrals from the principal directory to other directories are
automatically followed using anonymous authentication. If special
configuration of a referred directory is required (non-anonymous
authentication), this can be accomplished by attaching a pre-configured
directory instance that will be used during referral processing by calling
attachReferredDirectory(JNDIDirectory).
The JNDIDirectory class uses the Java Naming and Directory
Interface (JNDI) as the means of retrieving the data.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
LDAP_VERSION_2 |
static java.lang.String |
LDAP_VERSION_3 |
| Constructor and Description |
|---|
JNDIDirectory(javax.naming.directory.DirContext dir)
Deprecated.
This constructor is for backward-compatibility purposes only.
Some of the functionality of this class is not available when this constructor
is used. Toolkit users wishing to use their own
DirContext instance
should write their own LdapDirectory
implementation. |
JNDIDirectory(JNDIDirectory dir)
Copy constructor that creates new object with existing parameters.
|
JNDIDirectory(java.lang.String URL)
Constructs a
JNDIDirectory object using
an URL and parse its path and query values. |
JNDIDirectory(java.lang.String ipAddress,
int port)
Constructs a
JNDIDirectory object using Directory IP
address and port number as arguments. |
| Modifier and Type | Method and Description |
|---|---|
void |
attachReferredDirectory(JNDIDirectory referredDirectory)
Attaches a JNDIDirectory that could be used by this instance to follow LDAP referrals in its principal Directory.
|
void |
close()
Closes all of the referred Directories and the principal Directory.
|
javax.naming.directory.DirContext |
connect()
Connects to the Directory.
|
byte[][] |
getAttr(java.lang.String DN,
java.lang.String attributeToFind)
Search the Directory for a given attribute within a DN entry.
|
AuthenticationType |
getAuthenticationtType() |
int |
getConnectionTimeout()
returns the Directory connection timeout used by the underlying socket implementation.
|
X509CRL[] |
getCRLs(java.lang.String distributionPoint,
boolean wantARL)
Finds the CRLs or ARLs from a distribution point.
|
static LdapDirectory |
getInstance(java.lang.String endPoint,
int port,
java.lang.Object parms)
Returns a LdapDirectory object based on the type of LdapDirectory used.
|
static LdapDirectory |
getInstance(java.lang.String endPoint,
int port,
java.lang.Object parms,
boolean useSMProxy)
Returns a LdapDirectory object based on the type of LdapDirectory used.
|
static LdapDirectory |
getInstance(java.net.URL url)
Retrieves
|
LDAPSConfig |
getLDAPSConfig() |
java.lang.String |
getLdapVersion()
An accessor method that retrieves the LDAP version.
|
int |
getSearchTimeout()
Gets the Directory search timeout.
|
int |
getSoConnectionTimeout()
returns the socket connection timeout used by the underlying socket implementation..
|
java.lang.String |
getURL()
An accessor method that retrieves the URL.
|
boolean |
isAvailable()
Determines whether the Directory is available.
|
void |
resetAuthentication()
Resets the parameters required for authenticating to Microsoft Active Directory.
|
javax.naming.NamingEnumeration |
Search(java.lang.String searchBase,
java.lang.String searchExpr)
Searches the principal Directory for a given entry within a searchbase hierarchy, automatically following LDAP referrals.
|
byte[][] |
Search(java.lang.String searchBase,
java.lang.String searchExpr,
java.lang.String attributeToFind)
Searches the Directory for a given attribute within a searchbase hierarchy.
|
void |
setAuthentication(java.lang.String securityLevel,
java.lang.String userName,
SecureStringBuffer password)
Sets the parameters required for authenticating to Microsoft Active Directory.
|
void |
setAuthenticationType(AuthenticationType at)
Sets custom AuthenticationType parameters
eg.
|
void |
setClientCredentials(java.security.cert.X509Certificate[] chain,
java.security.PrivateKey signingKey)
Set client credentials for authenticating to a server.
|
void |
setClientCredentials(java.security.cert.X509Certificate verificationCertificate,
java.security.cert.X509Certificate caCertificate,
java.security.PrivateKey signingKey)
Not available.
|
void |
setConnectionTimeout(int connectionTimeout)
Sets the Directory connection timeout.
|
void |
setLDAPSConfig(LDAPSConfig config)
Set the LDAPS Configuration parameters.
|
void |
setLdapVersion(java.lang.String ldapVersion)
An accessor method that sets the LDAP version.
|
static void |
setMaxConcurrentSearches(int max)
Deprecated.
no longer required since the search timeout is now controlled
by the "com.sun.jndi.ldap.read.timeout" value. This JNDI read timeout value
has the same effect as the "search" timeout value used by the toolkit. If there
is a problem when a search is done then it will time out based on the value of
the
setSearchTimeout(int). |
void |
setSearchTimeout(int searchTimeout)
Sets the timeout when searching the Directory.
|
void |
setSoConnectionTimeout(int connectionTimeout)
Sets the Directory connection timeout used by the underlying socket implementation.
|
public static final java.lang.String LDAP_VERSION_2
public static final java.lang.String LDAP_VERSION_3
public JNDIDirectory(java.lang.String ipAddress,
int port)
JNDIDirectory object using Directory IP
address and port number as arguments.
A URL in the format ldap://ipAddress:port is constructed
from this information and stored for later use. The application must call
the connect() method before a connection to the URL is
established.
This is the principal Directory for this instance.
ipAddress - the Directory IP address as a string, for example, 1.2.3.4port - the port numberpublic JNDIDirectory(java.lang.String URL)
throws javax.naming.NamingException
JNDIDirectory object using
an URL and parse its path and query values.
A URL in the format ldapscheme://ipAddress:port is required
ldapschemes supported are ldap and ldaps (for secure LDAP using SSL).
The application must call the connect() method before
a connection to the URL is established.
This is the principal Directory for this instance.
URL - The LDAP URLjavax.naming.NamingException@Deprecated public JNDIDirectory(javax.naming.directory.DirContext dir)
DirContext instance
should write their own LdapDirectory
implementation.
The argument,
The Toolkit will not attempt to manage the provided context. If communication
errors occur while using the context, the Toolkit will attempt
to create an equivalent dir is an initialized JNDI DirContext
DirContext object for future searches.
When calling close(), the Toolkit will not attempt to close
dir, the context must be closed explicitly outside of the Toolkit.
dir - a javax.naming.directory.DirContext object.public JNDIDirectory(JNDIDirectory dir)
The argument, dir is an initialized JNDIDirectory
dir - a com.entrust.toolkit.x509.directory.JNDIDirectory object.public static LdapDirectory getInstance(java.lang.String endPoint, int port, java.lang.Object parms) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundExceptionjava.lang.NoSuchMethodExceptionjava.lang.SecurityExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.IllegalArgumentExceptionpublic static LdapDirectory getInstance(java.lang.String endPoint, int port, java.lang.Object parms, boolean useSMProxy) throws java.lang.ClassNotFoundException, java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundExceptionjava.lang.NoSuchMethodExceptionjava.lang.SecurityExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.IllegalArgumentExceptionpublic static LdapDirectory getInstance(java.net.URL url) throws java.lang.SecurityException, java.lang.NoSuchMethodException, java.lang.IllegalArgumentException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.ClassNotFoundException
url - java.lang.SecurityExceptionjava.lang.NoSuchMethodExceptionjava.lang.IllegalArgumentExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.ClassNotFoundExceptionpublic java.lang.String getURL()
public java.lang.String getLdapVersion()
public void setLdapVersion(java.lang.String ldapVersion)
throws javax.naming.NamingException
ldapVersion - the LDAP version that was used to connect to Directory.
Must be JNDIDirectory.LDAP_VERSION_2 or
JNDIDirectory.LDAP_VERSION_3.javax.naming.NamingExceptionpublic void setAuthentication(java.lang.String securityLevel,
java.lang.String userName,
SecureStringBuffer password)
securityLevel - the authentication mode, normally "simple"userName - the Microsoft Windows name of an Active Directory userpassword - a com.entrust.toolkit.util.SecureStringBuffer
that has the Microsoft Windows password of that userpublic void setLDAPSConfig(LDAPSConfig config)
LDAPSTrustManager for the default EntrustSSLSocketFactory.
If a custom SSLSocketFactory has been specified, these certificates
will not be used.JNDIDirectory object then the trusted certificates
required for LDAPS to succeeded will already be configured. However, if
AllowLDAPSReferral is set to false, LDAPS will not be attempted for any referrals.
Note 2: Because JNDI creates an instance of an SSLSocketFactory
using the static getDefault() method, all trusted certificates
must be available from a static location. The certificates stored in the
LDAPSConfig are stored in a static memory cache (as well as locally).
This means every certificate added through the LDAPSConfig object will be
trusted for every subsequent LDAPS connection made with a JNDIDirectory instance.
config - The LDAPSConfig object which contains the SSL Configuration parameterspublic LDAPSConfig getLDAPSConfig()
public void setAuthenticationType(AuthenticationType at)
public AuthenticationType getAuthenticationtType()
public void resetAuthentication()
Your application should call this method when it has finished using the Microsoft
Active Directory. After it returns, this JNDIDirectory instance
can no longer authenticate to that directory.
public void attachReferredDirectory(JNDIDirectory referredDirectory) throws javax.naming.NamingException
referredDirectory - is a Directory referenced by LDAP referrals in the principal Directoryjavax.naming.NamingException - if an attempt to connect to the provided JNDIDirectory failspublic void close()
throws javax.naming.NamingException
JNDIDirectory it attaches to this instance.javax.naming.NamingException - if a naming exception is encounteredpublic boolean isAvailable()
NOTE: This method does not determine the current directory connection status
but rather reports if the javax.naming.directory.DirContext object exists.
If the DirContext object does not exist, a new one will be created using
connect().
isAvailable in interface LdapDirectorytrue if the directory is available,
false otherwise.public void setSearchTimeout(int searchTimeout)
This method uses the JNDI setting "com.sun.jndi.ldap.read.timeout"
to specify the read timeout for an LDAP operation. If the search takes
longer than the timeout it aborts the read attempt and a
NamingException is thrown.
searchTimeout - the search timeout in milliseconds; by default it is 0 which means no
search time outpublic int getSearchTimeout()
public static void setMaxConcurrentSearches(int max)
setSearchTimeout(int).max - the maximum number of concurrent searches allowed; by default it is
0 which means no limit.public void setConnectionTimeout(int connectionTimeout)
The Directory connection timeout indicates the maximum amount of time that will be spent attempting to establish a connection to the Directory. If exceeded, an exception is thrown indicating the timeout occurred.
connectionTimeout - connection process timeout in milliseconds; by default it is 0 which means no limitpublic void setSoConnectionTimeout(int connectionTimeout)
The Directory connection timeout indicates the maximum amount of time that will be spent attempting to establish a socket connection to the Directory. If exceeded, an exception is thrown indicating the timeout occurred.
Note: When this feature is used, the underlying Socket implementation must support
the unconnected socket API Socket.connect(SocketAddress endpoint, int timeout)
and the SSLSocketFactory must support the SSLSocketFactory.createSocket()
connectionTimeout - connection process timeout in milliseconds; by default it is 0 which means no limitpublic int getSoConnectionTimeout()
The Socket connection timeout indicates the maximum amout ot time that will be spent attempting to establish a connection to the Directory. If exceeded, an exception is thrown indicating the timeout occurred.
Note: When this feature is used, the underlying Socket implementation must support
the unconnected socket API Socket.connect(SocketAddress endpoint, int timeout)
and the SSLSocketFactory must support the SSLSocketFactory.createSocket()
public int getConnectionTimeout()
The Directory connection timeout indicates the maximum amount of time that will be spent attempting to establish a socket connection to the Directory. If exceeded, an exception is thrown indicating the timeout occurred.
public javax.naming.directory.DirContext connect()
throws javax.naming.NamingException
This method establishes a new JNDI context. The method uses the IP address and
port number from the constructor, and returns this context so that the
application can use it to create additional JNDIDirectory objects
using the same Directory connection.
DirContext handlejavax.naming.NamingException - thrown if the directory is not accessiblepublic javax.naming.NamingEnumeration Search(java.lang.String searchBase,
java.lang.String searchExpr)
throws javax.naming.NamingException
Search performs a search operation on the JNDI context, using the given searchBase,
searchExpr parameters, and a subtree scope. The results are returned as a NamingEnumeration.
searchBase - the starting point for the searchsearchExpr - the search expressionNamingEnumeration of the search results, in which any LDAP referrals have already been followed, i.e.
invoking NamingException.hasMore() on the returned result will not thow any further
javax.naming.ReferralException.javax.naming.NamingException - thrown if the entry is not found, or if the search expression is not formatted correctlypublic byte[][] Search(java.lang.String searchBase,
java.lang.String searchExpr,
java.lang.String attributeToFind)
throws javax.naming.NamingException
Search performs a search operation on the JNDI
context, using the given searchBase, searchExpr
parameters, and a subtree scope. The results are searched for the specified
attributeToFind and, if found, the method returns the matching
attributes. If the attributeToFind is not found, the method
returns null.
searchBase - the starting point for the searchsearchExpr - the search expressionattributeToFind - the attribute to be extracted from the entryjavax.naming.NamingException - thrown if the entry is not found or the search expression
is malformedpublic byte[][] getAttr(java.lang.String DN,
java.lang.String attributeToFind)
throws javax.naming.NamingException
The desired attributes (usually userCertificate, caCertificate, or
crossCertificatePair), are extracted from the Directory at the location specified by the Distinguished Name,
DN.
The search will be re-tried if there was an error communicating with the Directory on the first search attempt, or if the attribute could not be found using the default LDAP binary syntax.
getAttr in interface LdapDirectoryDN - the distinguished name of the entryattributeToFind - the attribute to be extracted from the entryjavax.naming.NameNotFoundException - if the DN does not exist in the directoryjavax.naming.InvalidNameException - if the DN is not a valid DN, for example o=,c=CAjavax.naming.TimeLimitExceededException - if the search timeout value has been set, and the search takes longer than the value set.javax.naming.CommunicationException - if there is a problem communicating with the directory, or there are too
many concurrent searches happening already and another search cannot be started.javax.naming.NamingException - if an error other than those listed above occurs.public X509CRL[] getCRLs(java.lang.String distributionPoint, boolean wantARL) throws javax.naming.NamingException, java.security.cert.CRLException
This method is required to implement the IX509Directory interface.
It is called during the certificate path validation process to retrieve all
of the revocation lists from a specific CRL Distribution Point.
getCRLs in interface LdapDirectorydistributionPoint - the name of the distribution pointwantARL - a flag indicating whether an ARL (true) or CRL (false) is requiredjavax.naming.NamingException - thrown if the CRL is not found or the search expression is
cot formatted correctlyjava.security.cert.CRLException - if the CRL cannot be parsed.public void setClientCredentials(java.security.cert.X509Certificate verificationCertificate,
java.security.cert.X509Certificate caCertificate,
java.security.PrivateKey signingKey)
setClientCredentials in interface LdapDirectoryverificationCertificate - a verification certificatecaCertificate - the CA certificate that issued verificationCertificatesigningKey - the private signing key that signs messages verified by verificationCertificatepublic void setClientCredentials(java.security.cert.X509Certificate[] chain,
java.security.PrivateKey signingKey)