Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.javax.net.ssl.provider
Class JDBCSessionContext  view JDBCSessionContext download JDBCSessionContext.java

java.lang.Object
  extended bygnu.javax.net.ssl.provider.SessionContext
      extended bygnu.javax.net.ssl.provider.JDBCSessionContext
All Implemented Interfaces:
javax.net.ssl.SSLSessionContext

class JDBCSessionContext
extends SessionContext

The SQL table this class stores sessions in, called SESSIONS, looks like this:

 TABLE SESSIONS (
   ID             VARBINARY(32) PRIMARY KEY UNIQUE NOT NULL,
   CREATED        TIMESTAMP NOT NULL,
   LAST_ACCESSED  TIMESTAMP NOT NULL,
   PROTOCOL       VARCHAR(7) NOT NULL,
   SUITE          VARCHAR(255) NOT NULL,
   PEER_HOST      TEXT NOT NULL,
   PEER_CERT_TYPE VARCHAR(32),
   PEER_CERTS     BLOB,
   CERT_TYPE      VARCHAR(32),
   CERTS          BLOB,
   SECRET         VARBINARY(48) NOT NULL
 )
 

Note that the master secret for sessions is not protected before being inserted into the database; it is up to the system to protect the stored data from unauthorized access.


Field Summary
protected  int cacheSize
          The number of sessions to cache.
protected  java.sql.Connection connection
           
protected  java.sql.PreparedStatement deleteSession
           
protected  java.sql.PreparedStatement insert
           
protected  java.sql.PreparedStatement selectById
           
protected  java.sql.PreparedStatement selectTimestamp
           
protected  java.util.HashMap sessions
          The map of Session.ID objects to Sessions.
protected  int timeout
          The session timeout, in seconds.
protected  java.sql.PreparedStatement updateTimestamp
           
 
Constructor Summary
(package private) JDBCSessionContext()
           
 
Method Summary
(package private)  boolean addSession(Session.ID id, Session s)
          Adds a session to this context.
private  byte[] certs(java.security.cert.Certificate[] certs)
           
(package private)  boolean containsSessionID(Session.ID sessionId)
          Returns whether or not a session with the given ID is cached by this context.
 java.util.Enumeration getIds()
          Returns an enumeration of all saved session IDs.
 javax.net.ssl.SSLSession getSession(byte[] sessionId)
          Gets the session specified by its ID, or null if there is no session, or if it has expired.
 int getSessionCacheSize()
          Returns the maximum number of sessions that may be cached by this session context.
 int getSessionTimeout()
          Returns the period of time (in seconds) that a session may be cached for before becoming invalid.
(package private)  void notifyAccess(Session session)
          Notifies this context of an access event on a session.
protected  boolean removeSession(Session.ID sessionId)
          Removes a session from this context.
 void setSessionCacheSize(int cacheSize)
          Sets the maximum number of sessions that may be cached by this session context.
 void setSessionTimeout(int timeout)
          Sets the period of time (in seconds) that a session may be cached for before becoming invalid.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

connection

protected java.sql.Connection connection

selectById

protected java.sql.PreparedStatement selectById

insert

protected java.sql.PreparedStatement insert

selectTimestamp

protected java.sql.PreparedStatement selectTimestamp

updateTimestamp

protected java.sql.PreparedStatement updateTimestamp

deleteSession

protected java.sql.PreparedStatement deleteSession

sessions

protected final java.util.HashMap sessions
The map of Session.ID objects to Sessions.


cacheSize

protected int cacheSize
The number of sessions to cache.


timeout

protected int timeout
The session timeout, in seconds.

Constructor Detail

JDBCSessionContext

JDBCSessionContext()
             throws java.sql.SQLException
Method Detail

getIds

public java.util.Enumeration getIds()
Description copied from interface: javax.net.ssl.SSLSessionContext
Returns an enumeration of all saved session IDs. Every element in the returned enumeration is a byte array.

Specified by:
getIds in interface javax.net.ssl.SSLSessionContext
Overrides:
getIds in class SessionContext

getSession

public javax.net.ssl.SSLSession getSession(byte[] sessionId)
Description copied from interface: javax.net.ssl.SSLSessionContext
Gets the session specified by its ID, or null if there is no session, or if it has expired.

Specified by:
getSession in interface javax.net.ssl.SSLSessionContext
Overrides:
getSession in class SessionContext

addSession

boolean addSession(Session.ID id,
                   Session s)
Description copied from class: SessionContext
Adds a session to this context. This method:
  1. Will do nothing if the cache already contains the given ID.
  2. Will do nothing if the cache limit has been reached (and is not zero).
  3. Will remove any invalid sessions in the cache before trying to insert the new one.
  4. Will remove any expired sessions before trying to insert the new one.

Overrides:
addSession in class SessionContext

containsSessionID

boolean containsSessionID(Session.ID sessionId)
Description copied from class: SessionContext
Returns whether or not a session with the given ID is cached by this context.

Overrides:
containsSessionID in class SessionContext

removeSession

protected boolean removeSession(Session.ID sessionId)
Description copied from class: SessionContext
Removes a session from this context.

Overrides:
removeSession in class SessionContext

notifyAccess

void notifyAccess(Session session)
Description copied from class: SessionContext
Notifies this context of an access event on a session.

Overrides:
notifyAccess in class SessionContext

certs

private byte[] certs(java.security.cert.Certificate[] certs)

getSessionCacheSize

public int getSessionCacheSize()
Description copied from interface: javax.net.ssl.SSLSessionContext
Returns the maximum number of sessions that may be cached by this session context.

Specified by:
getSessionCacheSize in interface javax.net.ssl.SSLSessionContext

setSessionCacheSize

public void setSessionCacheSize(int cacheSize)
Description copied from interface: javax.net.ssl.SSLSessionContext
Sets the maximum number of sessions that may be cached by this session context. A cache size of 0 means no limit.

Specified by:
setSessionCacheSize in interface javax.net.ssl.SSLSessionContext

getSessionTimeout

public int getSessionTimeout()
Description copied from interface: javax.net.ssl.SSLSessionContext
Returns the period of time (in seconds) that a session may be cached for before becoming invalid.

Specified by:
getSessionTimeout in interface javax.net.ssl.SSLSessionContext

setSessionTimeout

public void setSessionTimeout(int timeout)
Description copied from interface: javax.net.ssl.SSLSessionContext
Sets the period of time (in seconds) that a session may be cached for before becoming invalid. A timeout of 0 means that sessions never expire.

Specified by:
setSessionTimeout in interface javax.net.ssl.SSLSessionContext

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).