Class DefaultSessionConfigurator
java.lang.Object
org.kawanfw.sql.api.server.session.DefaultSessionConfigurator
- All Implemented Interfaces:
SessionConfigurator
public class DefaultSessionConfigurator extends Object implements SessionConfigurator
Default implementation of session management:
- Session id are generated using a
SecureRandom
with theSessionIdentifierGenerator
class. - Session info (username, database) and session date/time creation are
stored in a
HashMap
whose key is the session id. - Session id is sent by client side at each API call. AceQL verifies that
the
HashMap
contains the username and that the session is not expired to grant access to the APIexecution.
It is not required nor recommended to extend this class or to develop another
SessionConfigurator
implementation.
Do it if you want to implement you own session mechanism and/or want to
manage how session info are stored.
Note that getSessionTimelife()
returns 0 and that sessions never
expires.
Extend this class and override getSessionTimelife()
if you want to
define expirable sessions.
- Author:
- Nicolas de Pomereu
-
Constructor Summary
Constructors Constructor Description DefaultSessionConfigurator()
-
Method Summary
Modifier and Type Method Description String
generateSessionId(String username, String database)
The method builds an authentication session id by a call to:
SessionIdentifierGenerator
String
getDatabase(String sessionId)
Loads the database stored for the passed session idint
getSessionTimelifeMinutes()
Returns the value ofsession.timelifeMinutes
property ofaceql-server.properties
.String
getUsername(String sessionId)
Loads the username stored for the passed session idvoid
remove(String sessionId)
Removes storage for the passed session Id.boolean
verifySessionId(String sessionId)
This implementation: Verify that the sessionId exists Verify that the sessionId is not expired (must be less that 12 hours).
-
Constructor Details
-
DefaultSessionConfigurator
public DefaultSessionConfigurator()
-
-
Method Details
-
generateSessionId
The method builds an authentication session id by a call to:
SessionIdentifierGenerator
- Specified by:
generateSessionId
in interfaceSessionConfigurator
- Parameters:
username
- the username to store for the passed session iddatabase
- the database to store for the passed session id- Returns:
- a unique session id for the (username, database) couple.
-
getUsername
Description copied from interface:SessionConfigurator
Loads the username stored for the passed session id- Specified by:
getUsername
in interfaceSessionConfigurator
- Parameters:
sessionId
- the session id- Returns:
- the username stored for the passed session Id
-
getDatabase
Description copied from interface:SessionConfigurator
Loads the database stored for the passed session id- Specified by:
getDatabase
in interfaceSessionConfigurator
- Parameters:
sessionId
- the session id- Returns:
- the database stored for the passed session Id
-
remove
Description copied from interface:SessionConfigurator
Removes storage for the passed session Id. Method is called by AceQL when client side callslogout
- Specified by:
remove
in interfaceSessionConfigurator
- Parameters:
sessionId
- the session id
-
verifySessionId
This implementation:- Verify that the sessionId exists
- Verify that the sessionId is not expired (must be less that 12 hours).
- Specified by:
verifySessionId
in interfaceSessionConfigurator
- Parameters:
sessionId
- the session id to verify- Returns:
- true if the sessionId is valid
- Throws:
IOException
- if any I/O error occurs
-
getSessionTimelifeMinutes
Returns the value ofsession.timelifeMinutes
property ofaceql-server.properties
. Defaults to 0. If 0, session is infinite.- Specified by:
getSessionTimelifeMinutes
in interfaceSessionConfigurator
- Returns:
- the sessions lifetime in minutes
- Throws:
IOException
- if any I/O error occurs
-