public class SessionHandler extends Object
Constructor and Description |
---|
SessionHandler(Random random)
Constructs a
SessionHandler with 1-hour-long sessions. |
SessionHandler(Random random,
long sessionLifetime)
Constructs a
SessionHandler provided sessionLifetime sessions and using an in-memory database. |
Modifier and Type | Method and Description |
---|---|
protected long |
generateExpiration()
Generates the expiration date using the current real time.
|
protected String |
generateSessionID()
Generates a new session ID encoded in base64.
|
Session |
getSession(String sessionID)
Gets the session associated to the given ID, if any.
|
Session |
newSession()
Creates a new session.
|
void |
refresh(String sessionID)
Refreshes the expiration date of the session identified by
sessionID . |
boolean |
removeSession(String sessionID)
Removes the session identified by
sessionID from the active sessions. |
public SessionHandler(Random random)
SessionHandler
with 1-hour-long sessions.
Use a secure Random
implementation (see java.security.SecureRandom).random
- the random number generator used to create session IDs.public SessionHandler(Random random, long sessionLifetime)
SessionHandler
provided sessionLifetime sessions and using an in-memory database.
Use a secure Random
implementation (see java.security.SecureRandom).random
- the random number generator used to create session IDs.sessionLifetime
- the time before a session is considered invalid in seconds.protected long generateExpiration()
System.currentTimeMillis()
protected String generateSessionID()
@Nullable public Session getSession(String sessionID)
sessionID
- session idnull
if no session has been found for this ID or if the
found session has expired.public Session newSession()
public void refresh(String sessionID)
sessionID
.sessionID
- the identifier of the session.public boolean removeSession(String sessionID)
sessionID
from the active sessions.sessionID
- the identifier of the session.false
if no sessions are referenced by sessionID
, true
otherwise