JavaTM 2 Platform
Std. Ed. v1.4.0

javax.net.ssl
Interface SSLSession


public interface SSLSession

In SSL, sessions are used to describe an ongoing relationship between two entities. Each SSL connection involves one session at a time, but that session may be used on many connections between those entities, simultaneously or sequentially. The session used on a connection may also be replaced by a different session. Sessions are created, or rejoined, as part of the SSL handshaking protocol. Sessions may be invalidated due to policies affecting security or resource usage, or by an application explicitly calling invalidate. Session management policies are typically used to tune performance.

In addition to the standard session attributes, SSL sessions expose these read-only attributes:

Sessions may be explicitly invalidated. Invalidation may also be done implicitly, when faced with certain kinds of errors.

Since:
1.4

Method Summary
 String getCipherSuite()
          Returns the name of the SSL cipher suite which is used for all connections in the session.
 long getCreationTime()
          Returns the time at which this Session representation was created, in milliseconds since midnight, January 1, 1970 UTC.
 byte[] getId()
          Returns the identifier assigned to this Session.
 long getLastAccessedTime()
          Returns the last time this Session representation was accessed by the session level infrastructure, in milliseconds since midnight, January 1, 1970 UTC.
 Certificate[] getLocalCertificates()
          Returns the certificate(s) that were sent to the peer during handshaking.
 X509Certificate[] getPeerCertificateChain()
          Returns the identity of the peer which was identified as part of defining the session.
 Certificate[] getPeerCertificates()
          Returns the identity of the peer which was established as part of defining the session.
 String getPeerHost()
          Returns the host name of the peer in this session.
 String getProtocol()
          Returns the standard name of the protocol used for all connections in the session.
 SSLSessionContext getSessionContext()
          Returns the context in which this session is bound.
 Object getValue(String name)
          Returns the object bound to the given name in the session's application layer data.
 String[] getValueNames()
          Returns an array of the names of all the application layer data objects bound into the Session.
 void invalidate()
          Invalidates the session.
 void putValue(String name, Object value)
          Binds the specified value object into the session's application layer data with the given name.
 void removeValue(String name)
          Removes the object bound to the given name in the session's application layer data.
 

Method Detail

getId

public byte[] getId()
Returns the identifier assigned to this Session.

Returns:
the Session identifier

getSessionContext

public SSLSessionContext getSessionContext()
Returns the context in which this session is bound.

This context may be unavailable in some environments, in which case this method returns null.

If the context is available and there is a security manager installed, the caller may require permission to access it or a security exception may be thrown. In a Java 2 environment, the security manager's checkPermission method is called with a SSLPermission("getSSLSessionContext") permission.

Returns:
the session context used for this session, or null if the context is unavailable.

getCreationTime

public long getCreationTime()
Returns the time at which this Session representation was created, in milliseconds since midnight, January 1, 1970 UTC.

Returns:
the time this Session was created

getLastAccessedTime

public long getLastAccessedTime()
Returns the last time this Session representation was accessed by the session level infrastructure, in milliseconds since midnight, January 1, 1970 UTC.

Access indicates a new connection being established using session data. Application level operations, such as getting or setting a value associated with the session, are not reflected in this access time.

This information is particularly useful in session management policies. For example, a session manager thread could leave all sessions in a given context which haven't been used in a long time; or, the sessions might be sorted according to age to optimize some task.

Returns:
the last time this Session was accessed

invalidate

public void invalidate()
Invalidates the session.

Future connections will not be able to resume or join this session. However, any existing connection using this session can continue to use the session until the connection is closed.


putValue

public void putValue(String name,
                     Object value)
Binds the specified value object into the session's application layer data with the given name.

Any existing binding using the same name is replaced. If the new (or existing) value implements the SSLSessionBindingListener interface, the object represented by value is notified appropriately.

For security reasons, the same named values may not be visible across different access control contexts.

Parameters:
name - the name to which the data object will be bound. This may not be null.
value - the data object to be bound. This may not be null.
Throws:
IllegalArgumentException - if either argument is null.

getValue

public Object getValue(String name)
Returns the object bound to the given name in the session's application layer data. Returns null if there is no such binding.

For security reasons, the same named values may not be visible across different access control contexts.

Parameters:
name - the name of the binding to find.
Returns:
the value bound to that name, or null if the binding does not exist.
Throws:
IllegalArgumentException - if the argument is null.

removeValue

public void removeValue(String name)
Removes the object bound to the given name in the session's application layer data. Does nothing if there is no object bound to the given name. If the bound existing object implements the SessionBindingListener interface, it is notified appropriately.

For security reasons, the same named values may not be visible across different access control contexts.

Parameters:
name - the name of the object to remove visible across different access control contexts
Throws:
IllegalArgumentException - if the argument is null.

getValueNames

public String[] getValueNames()
Returns an array of the names of all the application layer data objects bound into the Session.

For security reasons, the same named values may not be visible across different access control contexts.

Returns:
a non-null (possibly empty) array of names of the objects bound to this Session.

getPeerCertificates

public Certificate[] getPeerCertificates()
                                  throws SSLPeerUnverifiedException
Returns the identity of the peer which was established as part of defining the session.

Returns:
an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities.
Throws:
SSLPeerUnverifiedException - if the peer's identity has not been verified

getLocalCertificates

public Certificate[] getLocalCertificates()
Returns the certificate(s) that were sent to the peer during handshaking. When multiple certificates are available for use in a handshake, the implementation chooses what it considers the "best" certificate chain available, and transmits that to the other side. This method allows the caller to know which certificate chain was actually used.

Returns:
an ordered array of certificates, with the local certificate first followed by any certificate authorities. If no certificates were sent, then null is returned.

getPeerCertificateChain

public X509Certificate[] getPeerCertificateChain()
                                          throws SSLPeerUnverifiedException
Returns the identity of the peer which was identified as part of defining the session.

Note: this method exists for compatibility with previous releases. New applications should use getPeerCertificates() instead.

Returns:
an ordered array of peer X.509 certificates, with the peer's own certificate first followed by any certificate authorities. (The certificates are in the original JSSE certificate X509Certificate format.)
Throws:
SSLPeerUnverifiedException - if the peer's identity has not been verified

getCipherSuite

public String getCipherSuite()
Returns the name of the SSL cipher suite which is used for all connections in the session.

This defines the level of protection provided to the data sent on the connection, including the kind of encryption used and most aspects of how authentication is done.

Returns:
the name of the session's cipher suite

getProtocol

public String getProtocol()
Returns the standard name of the protocol used for all connections in the session.

This defines the protocol used in the connection.

Returns:
the standard name of the protocol used for all connections in the session.

getPeerHost

public String getPeerHost()
Returns the host name of the peer in this session.

For the server, this is the client's host; and for the client, it is the server's host. The name may not be a fully qualified host name or even a host name at all as it may represent a string encoding of the peer's network address. If such a name is desired, it might be resolved through a name service based on the value returned by this method.

This value is not authenticated and should not be relied upon.

Returns:
the host name of the peer host

JavaTM 2 Platform
Std. Ed. v1.4.0

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.