public class Session extends Object implements Blacklistable, AMSession
Session
class represents a session. It contains session
related information such as session ID, session type (user/application),
client ID (user ID or application ID), session idle time, time left on the
session, and session state. It also allows applications to add listener for
session events.SessionID
,
SessionListener
Modifier and Type | Field and Description |
---|---|
static String |
CACHED_BASE_POLLING_PROPERTY |
protected Hashtable<String,String> |
sessionProperties
All session related properties are stored as key-value pair in this
table.
|
protected SessionState |
sessionState
Four possible values for the state of the session:
Invalid
Valid
Inactive
Destroyed
|
Constructor and Description |
---|
Session(SessionID sid)
Constructor used by this package only.
|
Modifier and Type | Method and Description |
---|---|
void |
addInternalSessionListener()
Add listener to Internal Session.
|
void |
addSessionListener(SessionListener listener)
Adds a session listener for session change events.
|
void |
addSessionListener(SessionListener listener,
boolean force)
Adds a session listener for session change events.
|
String |
dereferenceRestrictedTokenID(Session session,
String restrictedId)
Given a restricted token, returns the SSOTokenID of the master token
can only be used if the requester is an app token
This functionality is only available in server mode.
|
void |
destroySession(Session session)
Destroys a session.
|
long |
getBlacklistExpiryTime()
The time (in milliseconds from the UTC epoch) until this session can be removed from a session blacklist.
|
String |
getClientDomain()
Returns the client domain in the session.
|
String |
getClientID()
Returns the client ID in the session.
|
String |
getCookieStr() |
boolean |
getCookieSupport()
Returns true if cookies are supported else false.
|
SessionID |
getID()
Returns the session ID.
|
long |
getIdleTime()
Returns the session idle time in seconds.
|
long |
getLatestRefreshTime()
Gets the time at which the Session was last refreshed from the master copy (in seconds).
|
long |
getMaxCachingTime()
Returns the maximum session caching time in minutes.
|
long |
getMaxIdleTime()
Returns the maximum session idle time in minutes.
|
long |
getMaxSessionTime()
Returns the maximum session time in minutes.
|
String |
getProperty(String name)
Gets the property stored in this session.
|
String |
getPropertyWithoutValidation(String name)
Gets the property stored in this session.
|
AtomicBoolean |
getRemoved() |
TokenRestriction |
getRestriction() |
static Session |
getSession(SessionID sid) |
SessionID |
getSessionID() |
URL |
getSessionServiceURL()
Gets the Session Service URL for this session object.
|
String |
getStableStorageID()
Returns a stable ID that can be used as a unique identifier when storing this session.
|
SessionState |
getState(boolean reset)
Returns the state of the session.
|
long |
getTimeLeft()
Returns the time left for this session in seconds.
|
SessionType |
getType()
Returns the session type.
|
SearchResults<Session> |
getValidSessions(String server,
String pattern)
Gets all valid sessions from the specified session server.
|
static void |
invokeListeners(SessionEvent sessionEvent)
Invokes all listeners on the Session associated with the event.
|
boolean |
isRestricted()
Returns true if the SSOTokenID associated with this SSOToken is a
restricted token, false otherwise.
|
boolean |
isTimedOut()
Returns true if the session has timed out.
|
void |
logout()
Logs out a session.
|
boolean |
maxCachingTimeReached()
Used to find out if the maximum caching time has reached or not.
|
void |
refresh(boolean reset)
Gets the latest session from session server and updates the local cache
of this session.
|
void |
setContext(Object context) |
void |
setCookieMode(Boolean cookieMode)
Set the cookie Mode based on whether the request has cookies or not.
|
void |
setCookieStr(String str) |
protected void |
setID(SessionID sessionID)
Updates the ID of the session.
|
void |
setProperty(String name,
String value)
Sets a property for this session.
|
protected void |
setRestriction(TokenRestriction restriction)
Sets a token restriction on this session.
|
void |
setState(SessionState state) |
void |
timeout()
Set the timeout time for this Session if it wasn't already set.
|
String |
toString() |
void |
update(SessionInfo info)
Updates the session from the session information server.
|
public static final String CACHED_BASE_POLLING_PROPERTY
protected SessionState sessionState
public Session(SessionID sid)
public AtomicBoolean getRemoved()
public SessionID getSessionID()
public String getCookieStr()
public void setCookieStr(String str)
public void setContext(Object context)
public SessionID getID()
protected void setID(SessionID sessionID)
sessionID
- the new session ID for the session.public SessionType getType()
public String getClientID()
public String getClientDomain()
public long getMaxSessionTime()
public long getMaxIdleTime()
public boolean isTimedOut() throws SessionException
true
if session timed out,
false
otherwiseSessionException
public long getMaxCachingTime()
public long getIdleTime() throws SessionException
SessionException
- if the session reached its maximum session
time, or the session was destroyed, or there was an error
during communication with session service.public long getTimeLeft() throws SessionException
SessionException
- is thrown if the session reached its
maximum session time, or the session was destroyed, or
there was an error during communication with session
service.public long getBlacklistExpiryTime() throws BlacklistException
getBlacklistExpiryTime
in interface Blacklistable
BlacklistException
- if the session has already expired or an error occurs.public long getLatestRefreshTime()
public SessionState getState(boolean reset) throws SessionException
reset
- This parameter indicates that whether the Session Service
needs to reset the latest access time on this session.INVALID, VALID, INACTIVE, and DESTROYED
.SessionException
- is thrown if the session reached its
maximum session time, or the session was destroyed, or
there was an error during communication with session
service.public void setState(SessionState state)
public String getProperty(String name) throws SessionException
name
- The property name.SessionException
- is thrown if the session reached its
maximum session time, or the session was destroyed, or
there was an error during communication with session
service.public String dereferenceRestrictedTokenID(Session session, String restrictedId) throws SessionException
session
- Must be an app tokenrestrictedId
- The SSOTokenID of the restricted tokenSSOException
- If the master token cannot be dereferencedSessionException
public boolean isRestricted() throws SessionException
SSOException
- If we are unable to determine if the session is
restrictedSessionException
public String getPropertyWithoutValidation(String name)
name
- The property name.public void setProperty(String name, String value) throws SessionException
name
- The property name.value
- The property value.SessionException
- if the session reached its maximum session
time, or the session was destroyed, or there was an error
during communication with session service, or if the property
name or value was null.public boolean maxCachingTimeReached()
public URL getSessionServiceURL() throws SessionException
SessionException
- when cannot get Session URL.public void destroySession(Session session) throws SessionException
session
- The session to be destroyed.SessionException
- if there was an error during
communication with session service, or the corresponding
session reached its maximum session/idle time, or the
session was destroyed.public void logout() throws SessionException
SessionException
- if there was an error during communication
with session service. If the session logged out already,
no exception will be thrown.public void addSessionListener(SessionListener listener) throws SessionException
listener
- Session Listener object.SessionException
- if the session state is not valid.public void addSessionListener(SessionListener listener, boolean force) throws SessionException
listener
- Session Listener object.force
- whether to ignore whether a Session is in the Invalid state. If false will throw an exception if
the Session is Invalid.SessionException
- if the session state is not valid.public SearchResults<Session> getValidSessions(String server, String pattern) throws SessionException
server
- The session server name. If the server name contains protocol
and port, the protocol and port will be used. Otherwise, the
server protocol and port is default to the same protocol and
port of the calling session.SessionException
- if there was an error during
communication with session service.public static void invokeListeners(SessionEvent sessionEvent)
sessionEvent
- Non null Session Event.public void refresh(boolean reset) throws SessionException
reset
- The flag to indicate whether to reset the latest session
access time in the session server.SessionException
- if the session reached its
maximum session time, or the session was destroyed, or
there was an error during communication with session
service.public void update(SessionInfo info) throws SessionException
info
- Session Information.SessionException
protected void setRestriction(TokenRestriction restriction)
restriction
- the restriction to apply to this session.UnsupportedOperationException
- if this session type does not support token restrictions.public void timeout()
public void addInternalSessionListener()
public boolean getCookieSupport()
cookieSupport
value is first determined from the Session ID
object , if that is null then it is determined based on the cookie mode
value set in the Session object else cookieSupport
value is
retrieved from the session property cookieSupport
. If
cookie Support value is not determined then the the default "false" is
assumed.public void setCookieMode(Boolean cookieMode)
createSSOToken(request)
method in
SSOTokenManager
.cookieMode
- whether request has cookies or not.public TokenRestriction getRestriction() throws SessionException
SessionException
public String getStableStorageID()
getStableStorageID
in interface Blacklistable
public static Session getSession(SessionID sid) throws SessionException
SessionException
Copyright © 2010–2025 Open Identity Platform Community. All rights reserved.