|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jsecurity.session.mgt.SimpleSession
public class SimpleSession
Simple Session POJO implementation, intended to be used on the business/server tier.
| Field Summary | |
|---|---|
protected static long |
MILLIS_PER_HOUR
|
protected static long |
MILLIS_PER_MINUTE
|
protected static long |
MILLIS_PER_SECOND
|
| Constructor Summary | |
|---|---|
SimpleSession()
|
|
SimpleSession(InetAddress hostAddress)
|
|
| Method Summary | |
|---|---|
protected void |
expire()
|
Object |
getAttribute(Object key)
Returns the object bound to this session identified by the specified key. |
Collection<Object> |
getAttributeKeys()
Returns the keys of all the attributes stored under this session. |
Map<Object,Object> |
getAttributes()
|
InetAddress |
getHostAddress()
Returns the InetAddress of the host that originated this session, or null if the host address is unknown. |
Serializable |
getId()
Returns the unique identifier assigned by the system upon session creation. |
Date |
getLastAccessTime()
Returns the last time the user associated with the session interacted with the system. |
Date |
getStartTimestamp()
Returns the time the session was started; that is, the time the system created the instance. |
Date |
getStopTimestamp()
Returns the time the session was stopped, or null if the session is still active. |
long |
getTimeout()
Returns the time in milliseconds that the session session may remain idle before expiring. |
boolean |
isExpired()
Returns true if this session has expired, false otherwise. |
protected boolean |
isStopped()
|
protected boolean |
isTimedOut()
Determines if this session is expired. |
boolean |
isValid()
|
Object |
removeAttribute(Object key)
Removes (unbinds) the object bound to this session under the specified key name. |
void |
setAttribute(Object key,
Object value)
Binds the specified value to this session, uniquely identified by the specifed key name. |
void |
setAttributes(Map<Object,Object> attributes)
|
void |
setExpired(boolean expired)
|
void |
setHostAddress(InetAddress hostAddress)
|
void |
setId(Serializable id)
|
void |
setLastAccessTime(Date lastAccessTime)
|
void |
setStartTimestamp(Date startTimestamp)
|
void |
setStopTimestamp(Date stopTimestamp)
|
void |
setTimeout(long timeout)
Sets the time in milliseconds that the session may remain idle before expiring. |
void |
stop()
Explicitly stops (invalidates) this session and releases all associated resources. |
void |
touch()
Explicitly updates the lastAccessTime of this session. |
void |
validate()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final long MILLIS_PER_SECOND
protected static final long MILLIS_PER_MINUTE
protected static final long MILLIS_PER_HOUR
| Constructor Detail |
|---|
public SimpleSession()
public SimpleSession(InetAddress hostAddress)
| Method Detail |
|---|
public Serializable getId()
SessionAll return values from this method are expected to have proper toString(),
equals(), and hashCode() implementations. Good candiadates for such
an identifier are UUIDs, Integers, and
Strings.
getId in interface Sessionpublic void setId(Serializable id)
public Date getStartTimestamp()
Session
getStartTimestamp in interface Sessionpublic void setStartTimestamp(Date startTimestamp)
public Date getStopTimestamp()
A session may become stopped under a number of conditions:
destroy()Once stopped, a session may no longer be used. It is locked from all further activity.
public void setStopTimestamp(Date stopTimestamp)
public Date getLastAccessTime()
Session
getLastAccessTime in interface SessionSession.touch()public void setLastAccessTime(Date lastAccessTime)
public boolean isExpired()
public void setExpired(boolean expired)
public long getTimeout()
Session
getTimeout in interface Sessionpublic void setTimeout(long timeout)
Session
setTimeout in interface Sessiontimeout - the time in milliseconds that the session may remain idle before expiring.public InetAddress getHostAddress()
Session
getHostAddress in interface SessionSessionFactory.start(java.net.InetAddress)public void setHostAddress(InetAddress hostAddress)
public Map<Object,Object> getAttributes()
public void setAttributes(Map<Object,Object> attributes)
public void touch()
SessionlastAccessTime of this session. This
method can be used to ensure a session does not time out.
Most programmers won't use this method explicitly and will instead rely calling the other Session methods to update the time transparently, or on a framework during a remote procedure call or upon a web request.
This method is particularly useful however when supporting rich-client applications such as Java Web Start appp, Java or Flash applets, etc. Although rare, it is possible in a rich-client environment that a user continuously interacts with the client-side application without a server-side method call ever being invoked. If this happens over a long enough period of time, the user's server-side session could time-out. Again, such cases are rare since most rich-clients frequently require server-side method invocations.
In this example though, the user's session might still be considered valid because
the user is actively "using" the application, just not communicating with the
server. But because no server-side method calls are invoked, there is no way for the server
to know if the user is sitting idle or not, so it must assume so to maintain session
integrity. The touch method could be invoked by the rich-client application code during those
times to ensure that the next time a server-side method is invoked, the invocation will not
throw an ExpiredSessionException. In short terms, it could be used periodically
to ensure a session does not time out.
How often this rich-client "maintenance" might occur is entirely dependent upon the application and would be based on variables such as session timeout configuration, usage characteristics of the client application, network utilization and application server performance.
touch in interface Sessionpublic void stop()
SessionIf this session has already been authenticated (i.e. the Subject that
owns this session has logged-in), calling this method explicitly might have undesired side effects:
Subject implementation to retain authentication state in the
Session. If the session
is explicitly stopped by application code by calling this method directly, it could clear out any
authentication state that might exist, thereby effectively "unauthenticating" the Subject.
As such, you might consider logging-out the 'owning'
Subject instead of manually calling this method, as a log out is expected to stop the
corresponding session automatically, and also allows framework code to execute additional cleanup logic.
stop in interface Sessionprotected boolean isStopped()
protected void expire()
public boolean isValid()
isValid in interface ValidatingSessionprotected boolean isTimedOut()
public void validate()
throws InvalidSessionException
validate in interface ValidatingSessionInvalidSessionException
public Collection<Object> getAttributeKeys()
throws InvalidSessionException
Session
getAttributeKeys in interface SessionInvalidSessionException - if this session has stopped or expired prior to calling this method.public Object getAttribute(Object key)
Session
getAttribute in interface Sessionkey - the unique name of the object bound to this session
public void setAttribute(Object key,
Object value)
SessionIf the value parameter is null, it has the same effect as if removeAttribute(key) was called.
setAttribute in interface Sessionkey - the name under which the value object will be bound in this sessionvalue - the object to bind in this session.public Object removeAttribute(Object key)
Session
removeAttribute in interface Sessionkey - the name uniquely identifying the object to remove
|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||