|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.net.URLConnection
java.net.HttpURLConnection
javax.net.ssl.HttpsURLConnection
nl.nikhef.slcshttps.trust.HttxURLConnection
public class HttxURLConnection
This class extends a HttpsURLConnection
that can use a TrustManager
that not only can check the certificate chain but also the
hostname against the server certificate.
More details can be found in the package
description
.
In addition it can also warn the user when his/her client certificate is
about to expire or has already expired. Communication about this is handled
by an implementation of HttxURLConnection.HttxClientCommunicator
. An implementation
using just stdio
is given by HttxURLConnection.StdioComm
. It can be
configured using the following system properties:
true
or false
, whether
to warn for (almost) expired client certificates. Can also be set using
setExpire(String)
.
setExpireWarnTime(String)
.
"stdio"
or "popup"
, when unset, "stdio"
is used. Can also
be set using setCommunicator(String)
.
HttxURLConnection
is implemented as a delegate class
for HttpsURLConnection
since that class is abstract while its
actual implementation is kept internal in the JDK API. Note that undocumented
overriding methods just call the corresponding overridden method of the
implementation, see the overridden methods for documentation.
Nested Class Summary | |
---|---|
static interface |
HttxURLConnection.HttxClientCommunicator
Interface for HttxURLConnection communication about client
certificate expiration. |
(package private) static class |
HttxURLConnection.StdioComm
This Implementation uses only stdio/stderr for I/O. |
Field Summary | |
---|---|
private static boolean |
clientExpireAcknowl
Whether a warning has been given about expiry. |
private static Date |
clientExpireDate
Expiry time of client side certificate ( null for unset),
can be set using setClientExpireDate(Date) . |
private static boolean |
clientExpireWarn
Whether we want warnings, set at class initialization using the property "nl.nikhef.slcshttps.httxclientwarn" or using setExpire(String) . |
private static boolean |
clientExpireWarnAcknowl
Whether a warning has been given about imminent expiry. |
private static long |
clientExpireWarnTime
Time in milliseconds before expiry to warn the user, use 0 for warning only after actual expiry, set at class initialization using the property "nl.nikhef.slcshttps.httxclientwarntime" or using setExpireWarnTime(String) . |
private static HttxURLConnection.HttxClientCommunicator |
comm
The HttxURLConnection.HttxClientCommunicator used for communication about client
certificate expiry, can be set using setCommunicator(String) . |
private static String |
COMMPROP
Name of property that sets the type of communicator: "nl.nikhef.slcshttps.comm", can be overridden using setCommunicator(String) . |
private static String |
commString
describes the type of communicator in use, initialized using the value of property "nl.nikhef.slcshttps.comm" by setCommunicator(String) . |
private static SSLSocketFactory |
defaultSSLSocketFactory
Default SSLSocketFactory , is initialized with an empty set of
KeyManager and a TrustManagerImpl . |
private static String |
EXPIREPROP
Name of property that determines whether to warn: "nl.nikhef.slcshttps.httxclientwarn", default is true, see also EXPIRETIMEPROP , can be overridden using setExpire(String) . |
private static String |
EXPIRETIMEPROP
Name of property that determines when to give an 'about-to-expire' warning: "nl.nikhef.slcshttps.httxclientwarntime", value is number of seconds; when it is unspecified or invalid, 0 is assumed and only a warning upon actual expiry is given, see also EXPIREPROP , can be overridden using
setExpireWarnTime(String) . |
private String |
hostName
hostname part of the URL . |
private static HostnameVerifier |
hostVerifier
Default HostnameVerifier , is initialized to a trivial one, since
all functionality is in the TrustManagerImpl . |
private HttpURLConnection |
httpImpl
Masked HttpURLConnection or HttpsURLConnection . |
private int |
portNumber
portnumber of the URL . |
private boolean |
ssl
whether this is a HTTPS or HTTP connection. |
private URL |
url
URL of the connection. |
Fields inherited from class javax.net.ssl.HttpsURLConnection |
---|
hostnameVerifier |
Fields inherited from class java.net.URLConnection |
---|
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, useCaches |
Constructor Summary | |
---|---|
HttxURLConnection(HttpURLConnection httpConnection)
Constructs a HttxURLConnection from given HttpURLConnection or HttpsURLConnection (a subclass of the
former). |
|
HttxURLConnection(URL url)
Constructs a HttxURLConnection to url . |
Methods inherited from class java.net.URLConnection |
---|
getDefaultRequestProperty, setDefaultRequestProperty |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private HttpURLConnection httpImpl
HttpURLConnection
or HttpsURLConnection
.
private static SSLSocketFactory defaultSSLSocketFactory
SSLSocketFactory
, is initialized with an empty set of
KeyManager
and a TrustManagerImpl
.
private static boolean clientExpireWarn
setExpire(String)
.
private static long clientExpireWarnTime
setExpireWarnTime(String)
.
private static final String EXPIREPROP
EXPIRETIMEPROP
, can be overridden using setExpire(String)
.
private static final String EXPIRETIMEPROP
EXPIREPROP
, can be overridden using
setExpireWarnTime(String)
.
private static final String COMMPROP
setCommunicator(String)
.
private static Date clientExpireDate
null
for unset),
can be set using setClientExpireDate(Date)
.
private static boolean clientExpireWarnAcknowl
private static boolean clientExpireAcknowl
private static String commString
setCommunicator(String)
.
private static HttxURLConnection.HttxClientCommunicator comm
HttxURLConnection.HttxClientCommunicator
used for communication about client
certificate expiry, can be set using setCommunicator(String)
.
private static HostnameVerifier hostVerifier
HostnameVerifier
, is initialized to a trivial one, since
all functionality is in the TrustManagerImpl
.
private URL url
URL
of the connection.
private String hostName
URL
.
private int portNumber
URL
.
private boolean ssl
Constructor Detail |
---|
public HttxURLConnection(HttpURLConnection httpConnection) throws IOException
HttxURLConnection
from given HttpURLConnection
or HttpsURLConnection
(a subclass of the
former). If this is a SSL connection (i.e. Https) it sets the hostname
and portnumber of the URL into the static TrustManagerImpl
fields. The preferred way is to call the static method openConnection(URL)
. We like to have the constructor public instead of
protected: we do not have the option to cast the object
returned by URL.openConnection()
since that will be a JDK
internal implementation of e.g. HttpsURLConnection
; however,
we can use the constructor to construct a new
HttxURLConnection
from such an object.
httpConnection
- HttpURLConnection
to construct a
HttxURLConnection from.
- Throws:
IOException
- in case of error, including expired client
certificate.- See Also:
openConnection(URL)
public HttxURLConnection(URL url) throws IOException
HttxURLConnection
to url
.
The preferred way is to call the static method
openConnection(URL)
.
url
- URL
to open a connection to.
IOException
HttxURLConnection(HttpURLConnection)
,
openConnection(URL)
Method Detail |
---|
public static HttxURLConnection openConnection(URL url) throws IOException
HttxURLConnection
for given
url
. This is the preferred method to open the connection.
url
- URL
to open a connection to.
url
IOException
- upon errorpublic void connect() throws IOException
HttxURLConnection
. Note that it is not
necessary to explicitly call URLConnection.connect()
, it
will automatically connect when starting I/O to it. This method will set
(again) the hostname and portnumber of the TrustManagerImpl
,
which will not happen when it is connected automatically.
connect
in class URLConnection
IOException
- upon errorpublic void disconnect()
HttxURLConnection
, which also resets
the hostname and portnumber for the TrustManagerImpl
.
disconnect
in class HttpURLConnection
public static void setDefaultSSLSocketFactory(SSLSocketFactory sslSocketFactory)
SSLSocketFactory
for
HttxURLConnection
. Note that this does not set the
default SSLSocketFactory
for HttpsURLConnection
.
sslSocketFactory
- will be set as default.getDefaultSSLSocketFactory()
public static SSLSocketFactory getDefaultSSLSocketFactory()
SSLSocketFactory
for
HttxURLConnection
. Note that this is different from the
default SSLSocketFactory
for HttpsURLConnection
.
SSLSocketFactory
setDefaultSSLSocketFactory(SSLSocketFactory)
public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
setHostnameVerifier
in class HttpsURLConnection
hostnameVerifier
- ignored.getHostnameVerifier().
public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier)
hostnameVerifier
- ignored.getDefaultHostnameVerifier().
public HostnameVerifier getHostnameVerifier()
HostnameVerifier
for
HttxURLConnection
. This is actually the same as returned by
getDefaultHostnameVerifier()
since we do not implement setter
methods.
getHostnameVerifier
in class HttpsURLConnection
HttxURLConnection
.getDefaultHostnameVerifier().
,
setHostnameVerifier(HostnameVerifier).
public static HostnameVerifier getDefaultHostnameVerifier()
HostnameVerifier
for
HttxURLConnection
. This is actually the same as returned by
getHostnameVerifier()
since we do not implement setter methods.
HttxURLConnection
.getDefaultHostnameVerifier().
,
setDefaultHostnameVerifier(HostnameVerifier).
public static boolean checkClientExpire()
public static void setClientExpireDate(Date date)
Date
of the client side certificate,
null
for no certificate. This also resets the acknowledgment
flags.
date
- expiry date of client certificate.getClientExpireDate()
public static Date getClientExpireDate()
Date
of the client side certificate,
null
for no certificate.
setClientExpireDate(Date)
public static void setExpire(String setString)
setString
- String
representation of a boolean, whether
to check and warn about expiry of client certificate. If
null
or invalid, use the default true
.getExpire()
,
EXPIREPROP
public static boolean getExpire()
setExpire(String)
,
EXPIREPROP
public static void setExpireWarnTime(String timeString)
timeString
is null
or is not a
valid number (which includes negative numbers), it will be set to 0,
meaning no special 'about-to-expire' warning will be given, only a
'already-expired'.
timeString
- String
representation of the time in
seconds before expiry time when a warning should be given.getExpireWarnTime()
,
EXPIRETIMEPROP
public static long getExpireWarnTime()
setExpireWarnTime(String)
,
EXPIRETIMEPROP
public static String setCommunicator(String commInput)
HttxURLConnection.HttxClientCommunicator
based on
commInput
. Valid values are:"stdio"
- use stdin/stdout/stderr
"popup"
- use (swing) popups
null
- use default "stdio"
commInput
- String
describing the wished type of
communicator to be used.
String
describing the actual type being used.getCommunicator()
public static String getCommunicator()
HttxURLConnection.HttxClientCommunicator
used for user
interaction.
setCommunicator(String)
public void setSSLSocketFactory(SSLSocketFactory arg0)
setSSLSocketFactory
in class HttpsURLConnection
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException
getServerCertificates
in class HttpsURLConnection
SSLPeerUnverifiedException
public SSLSocketFactory getSSLSocketFactory()
getSSLSocketFactory
in class HttpsURLConnection
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
getPeerPrincipal
in class HttpsURLConnection
SSLPeerUnverifiedException
public Principal getLocalPrincipal()
getLocalPrincipal
in class HttpsURLConnection
public Certificate[] getLocalCertificates()
getLocalCertificates
in class HttpsURLConnection
public String getCipherSuite()
getCipherSuite
in class HttpsURLConnection
public static void setFileNameMap(FileNameMap arg0)
URLConnection.setFileNameMap(FileNameMap)
.
arg0
- FileNameMap
getFileNameMap()
,
URLConnection.setFileNameMap(FileNameMap)
public static FileNameMap getFileNameMap()
URLConnection.getFileNameMap()
.
setFileNameMap(FileNameMap)
,
URLConnection.getFileNameMap()
public static void setDefaultAllowUserInteraction(boolean arg0)
URLConnection.setDefaultAllowUserInteraction(boolean)
.
arg0
- boolean
getDefaultAllowUserInteraction()
,
URLConnection.setDefaultAllowUserInteraction(boolean)
public static boolean getDefaultAllowUserInteraction()
URLConnection.getDefaultAllowUserInteraction()
.
setDefaultAllowUserInteraction(boolean)
,
URLConnection.getDefaultAllowUserInteraction()
public static void setFollowRedirects(boolean arg0)
HttpURLConnection.setFollowRedirects(boolean)
.
arg0
- booleangetFollowRedirects()
,
HttpURLConnection.setFollowRedirects(boolean)
public static boolean getFollowRedirects()
HttpURLConnection.getFollowRedirects()
.
setFollowRedirects(boolean)
,
HttpURLConnection.getFollowRedirects()
public static void setContentHandlerFactory(ContentHandlerFactory arg0)
URLConnection.setContentHandlerFactory(ContentHandlerFactory)
.
arg0
- ContentHandlerFactory
URLConnection.setContentHandlerFactory(ContentHandlerFactory)
public static String guessContentTypeFromStream(InputStream arg0) throws IOException
URLConnection.guessContentTypeFromStream(InputStream)
.
arg0
- InputStream
IOException
URLConnection.guessContentTypeFromStream(InputStream)
public static String guessContentTypeFromName(String arg0)
URLConnection.guessContentTypeFromName(String)
.
arg0
- String
with name.
URLConnection.guessContentTypeFromName(String)
public int hashCode()
hashCode
in class Object
public boolean equals(Object arg0)
equals
in class Object
public String toString()
toString
in class URLConnection
public void setUseCaches(boolean arg0)
setUseCaches
in class URLConnection
public void setRequestProperty(String arg0, String arg1)
setRequestProperty
in class URLConnection
public void setReadTimeout(int arg0)
setReadTimeout
in class URLConnection
public void setIfModifiedSince(long arg0)
setIfModifiedSince
in class URLConnection
public void setDoOutput(boolean arg0)
setDoOutput
in class URLConnection
public void setDoInput(boolean arg0)
setDoInput
in class URLConnection
public void setDefaultUseCaches(boolean arg0)
setDefaultUseCaches
in class URLConnection
public void setConnectTimeout(int arg0)
setConnectTimeout
in class URLConnection
public void setAllowUserInteraction(boolean arg0)
setAllowUserInteraction
in class URLConnection
public boolean getUseCaches()
getUseCaches
in class URLConnection
public URL getURL()
getURL
in class URLConnection
public String getRequestProperty(String arg0)
getRequestProperty
in class URLConnection
public Map<String,List<String>> getRequestProperties()
getRequestProperties
in class URLConnection
public int getReadTimeout()
getReadTimeout
in class URLConnection
public OutputStream getOutputStream() throws IOException
getOutputStream
in class URLConnection
IOException
public long getLastModified()
getLastModified
in class URLConnection
public InputStream getInputStream() throws IOException
getInputStream
in class URLConnection
IOException
public long getIfModifiedSince()
getIfModifiedSince
in class URLConnection
public Map<String,List<String>> getHeaderFields()
getHeaderFields
in class URLConnection
public int getHeaderFieldInt(String arg0, int arg1)
getHeaderFieldInt
in class URLConnection
public String getHeaderField(String arg0)
getHeaderField
in class URLConnection
public long getExpiration()
getExpiration
in class URLConnection
public boolean getDoOutput()
getDoOutput
in class URLConnection
public boolean getDoInput()
getDoInput
in class URLConnection
public boolean getDefaultUseCaches()
getDefaultUseCaches
in class URLConnection
public long getDate()
getDate
in class URLConnection
public String getContentType()
getContentType
in class URLConnection
public int getContentLength()
getContentLength
in class URLConnection
public String getContentEncoding()
getContentEncoding
in class URLConnection
public Object getContent(Class[] arg0) throws IOException
getContent
in class URLConnection
IOException
public Object getContent() throws IOException
getContent
in class URLConnection
IOException
public int getConnectTimeout()
getConnectTimeout
in class URLConnection
public boolean getAllowUserInteraction()
getAllowUserInteraction
in class URLConnection
public void addRequestProperty(String arg0, String arg1)
addRequestProperty
in class URLConnection
public boolean usingProxy()
usingProxy
in class HttpURLConnection
public void setRequestMethod(String arg0) throws ProtocolException
setRequestMethod
in class HttpURLConnection
ProtocolException
public void setInstanceFollowRedirects(boolean arg0)
setInstanceFollowRedirects
in class HttpURLConnection
public void setFixedLengthStreamingMode(int arg0)
setFixedLengthStreamingMode
in class HttpURLConnection
public void setChunkedStreamingMode(int arg0)
setChunkedStreamingMode
in class HttpURLConnection
public String getResponseMessage() throws IOException
getResponseMessage
in class HttpURLConnection
IOException
public int getResponseCode() throws IOException
getResponseCode
in class HttpURLConnection
IOException
public String getRequestMethod()
getRequestMethod
in class HttpURLConnection
public Permission getPermission() throws IOException
getPermission
in class HttpURLConnection
IOException
public boolean getInstanceFollowRedirects()
getInstanceFollowRedirects
in class HttpURLConnection
public String getHeaderFieldKey(int arg0)
getHeaderFieldKey
in class HttpURLConnection
public long getHeaderFieldDate(String arg0, long arg1)
getHeaderFieldDate
in class HttpURLConnection
public String getHeaderField(int arg0)
getHeaderField
in class HttpURLConnection
public InputStream getErrorStream()
getErrorStream
in class HttpURLConnection
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
nl.nikhef.slcshttps | Mischa Sallé - msalle(AT)nikhef.nl |