class SslConnection extends Utilities implements Connection
Utilities.SSLContextInfo
Modifier and Type | Field and Description |
---|---|
private String |
activeCipherSuite
The currently active cipher suite
|
private ClientAuthManager |
authManager
The authentication manager.
|
(package private) CallContext |
callContext
The call context specified when the connection was made
|
(package private) boolean |
closed
True if the connection has been closed.
|
private static Logger |
logger
Client logger
|
private long |
maxClientSessionDuration
The maximum time a client session should be used before expiring --
non-final to facilitate testing.
|
(package private) int |
port
The server port
|
(package private) String |
serverHost
The server host
|
private SSLSession |
session
The current session
|
(package private) SocketFactory |
socketFactory
The socket factory for creating plain sockets, or null to use default
sockets.
|
private SSLContext |
sslContext
The SSLContext -- only shared by connections with the same host, port,
suite, and principals.
|
(package private) SSLSocket |
sslSocket
The socket
|
(package private) SSLSocketFactory |
sslSocketFactory
The factory for creating SSL sockets.
|
ANY_KEY_ALGORITHM, clientLogger, DSA_KEY_ALGORITHM, getSubjectPermission, initLogger, INTEGRITY_PREFERRED, INTEGRITY_REQUIRED, RSA_KEY_ALGORITHM, serverLogger, UNKNOWN_PRINCIPAL
Constructor and Description |
---|
SslConnection(CallContext callContext,
String serverHost,
int port,
SocketFactory socketFactory)
Creates a connection.
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
checkConnectPermission()
Determine whether the caller has "connect" SocketPermission for the
connection's underlying socket.
|
private boolean |
checkSessionExpired()
Checks if the session currently active on the connection has been active
for longer than maxClientSessionDuration and, if so, invalidates the
session.
|
void |
close()
Closes this connection.
|
private void |
closeSocket()
Closes the socket for this connection.
|
private static int |
computeTimeout(long connectionTime) |
private Socket |
connectToHost(String host,
int port,
long connectionTime)
Returns a socket connected to the specified host and port,
according to the specified constraints.
|
private Socket |
connectToSocketAddress(SocketAddress socketAddress,
long connectionTime)
Returns a socket connected to the specified address, with a
timeout governed by the specified absolute connection time.
|
(package private) Socket |
createPlainSocket(String host,
int port)
Creates a plain socket to use for communication with the specified host
and port.
|
(package private) void |
establishCallContext()
Establishes a cipher suite on this connection as specified by the call
context.
|
(package private) void |
establishNewSocket()
Attempts to create a new socket for the call context and cipher suites.
|
(package private) void |
establishSuites()
Attempts to establish the call context and suites on the current socket.
|
SocketChannel |
getChannel()
Returns a socket channel that performs I/O on this connection,
or
null if no socket channel is available. |
InputStream |
getInputStream()
Returns an input stream that reads data from this connection.
|
OutputStream |
getOutputStream()
Returns an output stream that writes data to this connection.
|
protected String |
getProxyHost()
Return HTTP proxy host if present, an empty string otherwise.
|
InvocationConstraints |
getUnfulfilledConstraints(OutboundRequestHandle handle)
Implements
OutboundRequest.getUnfulfilledConstraints for a request with
the specified handle. |
private Socket |
newSocket()
Returns a new unconnected socket, using this endpoint's
socket factory if non-null.
|
void |
populateContext(OutboundRequestHandle handle,
Collection context)
Populates the supplied collection with context information
representing a request with the specified handle.
|
IOException |
readResponseData(OutboundRequestHandle handle,
InputStream stream)
Reads from the specified stream any per-response data required
by this connection for a request with the specified handle.
|
String |
toString()
Returns a string representation of this object.
|
(package private) boolean |
useFor(CallContext otherCallContext)
Returns true if this connection is compatible with the specified call
context.
|
void |
writeRequestData(OutboundRequestHandle handle,
OutputStream stream)
Writes to the specified stream any per-request data required by
this connection for a request with the specified handle.
|
checkValidity, contains, doesEncryption, doesServerAuthentication, equals, firstX509Cert, getCertFactory, getCipherAlgorithm, getClassName, getClientPrincipals, getClientPrincipals, getClientSSLContextInfo, getKeyAlgorithm, getKeyExchangeAlgorithm, getPermittedKeyAlgorithms, getServerPrincipals, getServerSSLContextInfo, getSupportedCipherSuites, hasStrongCipherAlgorithm, logThrow, maintainsIntegrity, permittedKeyAlgorithm, position, releaseClientSSLContextInfo, safeEquals, subjectString, toString
private final long maxClientSessionDuration
private static final Logger logger
final String serverHost
final int port
final SocketFactory socketFactory
final CallContext callContext
private final SSLContext sslContext
final SSLSocketFactory sslSocketFactory
private final ClientAuthManager authManager
volatile SSLSocket sslSocket
private volatile String activeCipherSuite
private volatile SSLSession session
volatile boolean closed
SslConnection(CallContext callContext, String serverHost, int port, SocketFactory socketFactory)
callContext
- the call context to establishserverHost
- the server host to connect toport
- the server port to connect tosocketFactory
- the socket factory, or null to use default socketsfinal void establishCallContext() throws IOException
UnsupportedSecurityException
- if the requested constraints cannot
be supportedIOException
- if an I/O failure occursSecurityException
- if the current access control context does not
have the proper AuthenticationPermissionprivate void closeSocket()
void establishNewSocket() throws IOException
SSLException
- if the suites cannot be supportedIOException
- if an I/O failure occursfinal void establishSuites() throws IOException
SSLException
- if the requested suites cannot be supportedIOException
- if an I/O failure occursfinal Socket createPlainSocket(String host, int port) throws IOException
IOException
private static int computeTimeout(long connectionTime) throws IOException
IOException
private Socket connectToHost(String host, int port, long connectionTime) throws IOException
IOException
private Socket connectToSocketAddress(SocketAddress socketAddress, long connectionTime) throws IOException
IOException
private Socket newSocket() throws IOException
IOException
public String toString()
public InputStream getInputStream() throws IOException
Connection
getInputStream
in interface Connection
IOException
- if an I/O exception occurspublic OutputStream getOutputStream() throws IOException
Connection
getOutputStream
in interface Connection
IOException
- if an I/O exception occurspublic SocketChannel getChannel()
Connection
null
if no socket channel is available. If a
non-null
socket channel is returned, it is
connected.getChannel
in interface Connection
null
public void populateContext(OutboundRequestHandle handle, Collection context)
Connection
OutboundRequest.populateContext
for such requests; the context
may also be populated by the connection manager.populateContext
in interface Connection
handle
- the handle for the requestcontext
- the context collection to populatepublic InvocationConstraints getUnfulfilledConstraints(OutboundRequestHandle handle)
Connection
OutboundRequest.getUnfulfilledConstraints
for a request with
the specified handle.getUnfulfilledConstraints
in interface Connection
handle
- the handle for the requestpublic void writeRequestData(OutboundRequestHandle handle, OutputStream stream)
Connection
This method is invoked by ConnectionManager
with the request output stream of the OutboundRequest
that it creates for the request. This method can be used, for
example, to convey per-request information about delegation,
client authentication, or client privileges.
There may be multiple requests in progress concurrently over
this connection, and data written to the specified stream may
be buffered and multiplexed with data from other requests
before being written to this connection's underlying output
stream. Therefore, this method should only write data to the
specified stream and must not read any data from this
connection's underlying input stream; data can, however, be
subsequently read with readResponseData
.
writeRequestData
in interface Connection
handle
- the handle for the requeststream
- the request output stream of the requestpublic IOException readResponseData(OutboundRequestHandle handle, InputStream stream)
Connection
This method returns null
if the information
read (if any) indicates that the constraints are satisfied, and
it returns an exception if the constraints could not be
satisfied. If an exception is returned rather than thrown, the
delivery status of a corresponding OutboundRequest
will
be false
.
This method is invoked by ConnectionManager
with the response input stream of the
OutboundRequest
that it creates for the request
and the same handle that was passed to writeRequestData
. This method can be used to read information
produced by ServerConnection.processRequestData
in response to the
information sent by writeRequestData
.
There may be multiple requests in progress concurrently over this connection, and data read from the specified stream may have been buffered and multiplexed with data from other requests being read from this connection's underlying input stream. Therefore, this method should only read data from the specified stream and must not write any data to this connection's underlying output stream.
readResponseData
in interface Connection
handle
- the handle for the requeststream
- the response input stream of the requestnull
if the constraints are satisfied, or
an exception if the constraints could not be satisfiedpublic void close() throws IOException
Connection
close
in interface Connection
IOException
- if an I/O exception occursfinal boolean useFor(CallContext otherCallContext)
private boolean checkSessionExpired()
protected String getProxyHost()
boolean checkConnectPermission()
SecurityException
- if the underlying socket exists but
the caller does not have permission to use it.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.