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
SecureRandomwith theSessionIdentifierGeneratorclass. - Session info (username, database) and session date/time creation are
stored in a
HashMapwhose key is the session id. - Session id is sent by client side at each API call. AceQL verifies that
the
HashMapcontains 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 StringgenerateSessionId(String username, String database)The method builds an authentication session id by a call to:
SessionIdentifierGeneratorStringgetDatabase(String sessionId)Loads the database stored for the passed session idintgetSessionTimelifeMinutes()Returns the value ofsession.timelifeMinutesproperty ofaceql-server.properties.StringgetUsername(String sessionId)Loads the username stored for the passed session idvoidremove(String sessionId)Removes storage for the passed session Id.booleanverifySessionId(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:
generateSessionIdin 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:SessionConfiguratorLoads the username stored for the passed session id- Specified by:
getUsernamein interfaceSessionConfigurator- Parameters:
sessionId- the session id- Returns:
- the username stored for the passed session Id
-
getDatabase
Description copied from interface:SessionConfiguratorLoads the database stored for the passed session id- Specified by:
getDatabasein interfaceSessionConfigurator- Parameters:
sessionId- the session id- Returns:
- the database stored for the passed session Id
-
remove
Description copied from interface:SessionConfiguratorRemoves storage for the passed session Id. Method is called by AceQL when client side callslogout- Specified by:
removein 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:
verifySessionIdin 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.timelifeMinutesproperty ofaceql-server.properties. Defaults to 0. If 0, session is infinite.- Specified by:
getSessionTimelifeMinutesin interfaceSessionConfigurator- Returns:
- the sessions lifetime in minutes
- Throws:
IOException- if any I/O error occurs
-