public class HttpURLConnection
extends java.net.HttpURLConnection
To initiate authentication with a server (currently only NTLM authentication is supported) there are two methods that may be used.
The first method uses the JAAS Subject based security model.
This is the recommended method.
More specifically, simply call this API with a jespa.security.PasswordCredential in the JAAS Subject.
The credential will be used with the SecurityProvider that handles the type of authentication required by the server if any (such as the NtlmSecurityProvider if the server challanged the client with WWW-Authenticate: NTLM).
See the numerous example programs included with the Jespa package that illustrate how to bootstrap a JAAS credential (such as with the RunAs class) for use with this class.
The second method for initiating authentication with a server is to insert SecurityProvider properties as HTTP request properties using the property name prefixed with "jespa." and with values base 64 encoded.
This method is not exactly a correct use of the HttpURLConnection API however the feature is included because it is easy and of course these properties are not actually included in the HTTP request in any way.
Instead, these special properties will be base 64 decoded, stripped of the "jespa." prefix and passed to the SecurityProvider required for authentication with a particular server (such as the NtlmSecurityProvider if the server challanged the client with WWW-Authenticate: NTLM).
Consider the following example:
HttpURLConnection conn = new HttpURLConnection(url);
conn.setRequestProperty("jespa.service.acctname", base64encode(acctname));
conn.setRequestProperty("jespa.service.password", base64encode(password));
conn.setRequestProperty("jespa.http.tls.sslsocketfactory.classname", base64encode("jespa.http.DummySSLSocketFactory"));
The above example illustrates how to use setRequestProperty to pass SecurityProvider properties to the required SecurityProvider for initiating authentication with a server.
The Jespa package does not include an HttpsURLConnection implementation because this class also transparently handles SSL / TLS if the URL begins with "https://". If you would like to install your own SSLSocketFactory, you can set it using the jespa.http.tls.sslsocketfactory.classname request property. The above example also illustrates how to install an SSLSocketFactory that does not validate the server certificate chain of authority (such as because the operator does not care to import a self-signed server certificate into their Java trustStore).
This class supports numerous other properties like Jepsa "dns." properties.
Currently this implementation does not support proxies or proxy authentication.
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage| Constructor and Description |
|---|
HttpURLConnection(java.net.URL url) |
| Modifier and Type | Method and Description |
|---|---|
void |
addRequestProperty(java.lang.String key,
java.lang.String value) |
void |
connect() |
void |
disconnect() |
java.lang.String |
getHeaderField(int n) |
java.lang.String |
getHeaderField(java.lang.String name) |
java.lang.String |
getHeaderFieldKey(int n) |
java.util.Map |
getHeaderFields() |
java.io.InputStream |
getInputStream() |
java.io.OutputStream |
getOutputStream() |
void |
requestComplete(jespa.http.HttpPeer p,
jespa.http.HttpRequest r) |
void |
setRequestProperty(java.lang.String key,
java.lang.String value) |
boolean |
usingProxy() |
getErrorStream, getFollowRedirects, getHeaderFieldDate, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethodgetAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFieldLong, getIfModifiedSince, getLastModified, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setUseCaches, toStringpublic java.lang.String getHeaderField(java.lang.String name)
getHeaderField in class java.net.URLConnectionpublic java.util.Map getHeaderFields()
getHeaderFields in class java.net.URLConnectionpublic java.lang.String getHeaderField(int n)
getHeaderField in class java.net.HttpURLConnectionpublic java.lang.String getHeaderFieldKey(int n)
getHeaderFieldKey in class java.net.HttpURLConnectionpublic void requestComplete(jespa.http.HttpPeer p,
jespa.http.HttpRequest r)
throws java.io.IOException
java.io.IOExceptionpublic void connect()
throws java.io.IOException
connect in class java.net.URLConnectionjava.io.IOExceptionpublic void disconnect()
disconnect in class java.net.HttpURLConnectionpublic boolean usingProxy()
usingProxy in class java.net.HttpURLConnectionpublic void addRequestProperty(java.lang.String key,
java.lang.String value)
addRequestProperty in class java.net.URLConnectionpublic void setRequestProperty(java.lang.String key,
java.lang.String value)
setRequestProperty in class java.net.URLConnectionpublic java.io.InputStream getInputStream()
throws java.io.IOException
getInputStream in class java.net.URLConnectionjava.io.IOExceptionpublic java.io.OutputStream getOutputStream()
throws java.io.IOException
getOutputStream in class java.net.URLConnectionjava.io.IOException