public class HttpsDirectoryClientJSSE extends java.lang.Object implements LdapDirectory
HttpsDirectoryClientJSSE class uses the HttpURLConnection
class to make a connection to the HttpDirectoryServlet. This class will work
with both HTTP and HTTPS based URL's. The type will be selected automatically
based on the protocol specified in the urlString in the constructor.
This class differs from HttpsDirectoryClient because it uses the URLConnection class to make the network connection instead of using a Socket directly. This will allow the use of the JVM's default URLStreamHandler when making the connection (if desired).
For HTTP based URL's, the SSLSocketFactory and HostnameVerfier parameters may be set to null.
For HTTPS based URL's, the SSLSocketFactory and HostnameVerifier parameters may be used to configure the SSL connection (depending on the URLStreamHandler that is in use). If no SSLSocketFactory is used, the default SSLSocketFactory from the HttpsURLConnection class will be used. If no HostnameVerifier is supplied, the default HostnameVerifier from the HttpsURLConnection class will be used.
To use tunneling:
HttpDirectoryServlet class.
The documentation for the HttpDirectoryServlet
class describes how to install this class.HttpDirectoryServlet,
HttpDirectoryClient| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_TIMEOUT
The default timeout value used for the http connection and read timeout values.
|
| Constructor and Description |
|---|
HttpsDirectoryClientJSSE(HttpsDirectoryClientJSSE copy)
This is the copy constructor.
|
HttpsDirectoryClientJSSE(java.lang.String urlString)
Creates an
HttpsDirectoryClientJSSE using an HttpsURLConnection
object. |
HttpsDirectoryClientJSSE(java.lang.String urlString,
javax.net.ssl.SSLSocketFactory factory,
javax.net.ssl.HostnameVerifier hostnameVerifier,
java.net.URLStreamHandler streamHandler)
Creates an
HttpsDirectoryClient using an HttpsURLConnection
object. |
| Modifier and Type | Method and Description |
|---|---|
byte[][] |
getAttr(java.lang.String dn,
java.lang.String attributeToFind)
Implements the
getAttr method of the LdapDirectory
interface. |
X509CRL[] |
getCRLs(java.lang.String distributionPoint,
boolean wantARL)
Implements the
getCRLs() method of the LdapDirectory
interface. |
java.net.URL |
getURL()
Return the base URL used to make the URLConnection
|
boolean |
isAvailable()
Determines whether the remote servlet is available.
|
void |
setClientCredentials(java.security.cert.X509Certificate verificationCertificate,
java.security.cert.X509Certificate caCertificate,
java.security.PrivateKey signingKey)
This method is never used by this implementation.
|
void |
setConnectionTimeout(int timeout)
Sets the connection timeout used when making the connection to the
HTTP servlet
|
void |
setReadTimeout(int timeout)
Sets the read timeout used when reading data from
the HTTP servlet.
|
public static final int DEFAULT_TIMEOUT
public HttpsDirectoryClientJSSE(java.lang.String urlString,
javax.net.ssl.SSLSocketFactory factory,
javax.net.ssl.HostnameVerifier hostnameVerifier,
java.net.URLStreamHandler streamHandler)
throws java.net.MalformedURLException,
java.net.UnknownHostException,
java.io.IOException
HttpsDirectoryClient using an HttpsURLConnection
object. To configure the SSL parameters used by the HttpsURLConnection created
by this object, an SSLSocketFactory and HostnameVerifier may be supplied.
The port will be obtained from the URL string, or if it does
not exist it will use port 80 for http or 443 for https
If a null SSLSocketFactory is supplied, the default SSLSocketFactory setup for use with the HttpsURLConnection will be used.
If a null HostnameVerifier is supplied, the default HostnameVerifier setup for use with the HttpsURLConnection will be used.
If a null URLStreamHandler is supplied, the default URLStreamStreamHandler for the specified protocol will be used.
urlString - the URL string of the Directory servlet.
specifies the port.SSLSocketFactory - The SSLSocketFactory that will be used to create the sockets used
by this classhostnameVerifier - The HostnameVerifier used to verify the hostname used when an SSL
connection is used.streamHandler - The URLStreamHandler that will be used to perform the protocol
side of the connection.java.net.MalformedURLException - if urlString is not a valid URL.java.net.UnknownHostException - if the host specified in urlString cannot be contacted.java.io.IOException - if there is an IO problem after connecting to the host.public HttpsDirectoryClientJSSE(java.lang.String urlString)
throws java.net.MalformedURLException,
java.net.UnknownHostException,
java.io.IOException
HttpsDirectoryClientJSSE using an HttpsURLConnection
object. To configure the SSL parameters used by the HttpsURLConnection created
by this object, the default SSLSocketFactory and HostnameVerifier will be used.
The port will be obtained from the URL string, or if it does
not exist it will use port 80 for http or 443 for httpsurlString - the URL string of the Directory servlet.java.net.MalformedURLException - if urlString is not a valid URL.java.net.UnknownHostException - if the host specified in urlString cannot be contacted.java.io.IOException - if there is an IO problem after connecting to the host.public HttpsDirectoryClientJSSE(HttpsDirectoryClientJSSE copy)
copy - The HttpsDirectoryClientJSSE to copypublic java.net.URL getURL()
public byte[][] getAttr(java.lang.String dn,
java.lang.String attributeToFind)
throws javax.naming.NamingException
getAttr method of the LdapDirectory
interface.
This method sends an HTML GET request to the proxy servlet,
requesting a Directory search. The search specifies a particular attribute
at a particular Directory entry, which is specified by a distinguished name (DN).
The getAttr method reads the servlet's response and returns the
attribute as an array of byte arrays.
Given a DN and a desired attribute (using X.509 names such as userCertificate, dn, cn, email, and so on), this method returns a byte array containing the attributes certificate, CRL, DN, and email address.
The following code fragment is an example of typical usage. In this case each element of the result is a byte array representation of one of the user's certificates.
getAttr( "cn=Roger Ramjet, o=Lompoc, c=US", "userCertificate" );
getAttr in interface LdapDirectorydn - the distinguished nameattributeToFind - the attribute to findjavax.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 at the servlet, 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
getCRLs() method of the LdapDirectory
interface.
This methos sends an HTML GET request to the proxy servlet,
requesting a Directory search for CRLs or ARLs at a particular distribution point.
It reads the servlet's response and returns an array of CRLs or ARLs.
getCRLs in interface LdapDirectorydistributionPoint - the DN as defined in a certificatewantARL - a boolean flag indicating that an ARL is requiredjavax.naming.NamingException - thrown if the search failsjava.security.cert.CRLException - thrown for other errorspublic boolean isAvailable()
This does not guarantee that the servlet can communicate with the directory.
isAvailable in interface LdapDirectorypublic 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 setConnectionTimeout(int timeout)
timeout - The timeout value in secondspublic void setReadTimeout(int timeout)
timeout - The timeout value in seconds