Package com.logicaldoc.core.security
Class SessionManager
- java.lang.Object
- 
- java.util.AbstractMap<K,V>
- 
- java.util.concurrent.ConcurrentHashMap<String,Session>
- 
- com.logicaldoc.core.security.SessionManager
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- ConcurrentMap<String,Session>,- Map<String,Session>
 
 public class SessionManager extends ConcurrentHashMap<String,Session> Repository of all current user sessions.- Since:
- 4.6
- Author:
- Marco Meschieri - LogicalDOC
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMapConcurrentHashMap.KeySetView<K extends Object,V extends Object>
 - 
Nested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static StringCOOKIE_SIDstatic StringPARAM_SID
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(SessionListener listener)ClientbuildClient(javax.servlet.http.HttpServletRequest req)Create a client identified using a concatenation of Basic authentication credentials and remote IP.intcountOpened()Counts the total number of opened sessionsintcountOpened(long tenantId)Counts the total number of opened sessions per tenantSessioncreateSession(User user, Client client)Creates a new session by authenticated the given user and stores it in the pool of opened sessionsvoiddestroy()static SessionManagerget()Sessionget(Object sid)SessiongetByClientId(String clientId)Gets the session of the given clientstatic StringgetCurrentSid()Retrieves the session ID of the current thread executionjavax.servlet.http.HttpSessiongetServletSession(String sid)SessiongetSession(javax.servlet.http.HttpServletRequest request)Gets the Session with the identifier returned bygetSessionId(HttpServletRequest)SessionDAOgetSessionDao()StringgetSessionId(javax.servlet.http.HttpServletRequest request)Gets the Session ID specification from the current request following this lookup strategy: Session attributePARAM_SIDRequest attributePARAM_SIDRequest parameterPARAM_SIDCookieCOOKIE_SIDSpring SecurityContextHolderList<Session>getSessions()Returns the list of sessions of the current node ordered by ascending status and creation date.intgetStatus(String sid)booleanisOpen(String sid)Checks if a session is valid or not.voidkill(String sid)Kills an existing sessionSessionnewSession(String username, String password, Client client)Creates a new session by authenticated the given user and stores it in the pool of opened sessionsSessionnewSession(String username, String password, String key, Client client)Creates a new session by authenticating the given user and stores it in the pool of opened sessionsSessionremove(Object sid)voidremoveListener(SessionListener listener)voidremoveSid(javax.servlet.http.HttpServletRequest request)Removes the Sid from the http requestvoidrenew(String sid)Renews an opened sessionvoidsaveSid(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid)Saves the session identifier in the request and session attributePARAM_SIDand CookieCOOKIE_SIDvoidsetAuthenticationChain(AuthenticationChain authenticationChain)voidsetSessionDao(SessionDAO sessionDao)- 
Methods inherited from class java.util.concurrent.ConcurrentHashMapclear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, values
 
- 
 
- 
- 
- 
Field Detail- 
COOKIE_SIDpublic static final String COOKIE_SID - See Also:
- Constant Field Values
 
 - 
PARAM_SIDpublic static final String PARAM_SID - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getpublic static final SessionManager get() 
 - 
newSessionpublic Session newSession(String username, String password, String key, Client client) throws AuthenticationException Creates a new session by authenticating the given user and stores it in the pool of opened sessions- Parameters:
- username- the username
- password- the passowrd
- key- the secret key
- client- client informations
- Returns:
- the session created after the successful login
- Throws:
- AuthenticationException- raised in case of failed login
 
 - 
newSessionpublic Session newSession(String username, String password, Client client) throws AuthenticationException Creates a new session by authenticated the given user and stores it in the pool of opened sessions- Parameters:
- username- the username
- password- the passowrd
- client- client informations
- Returns:
- the session created after the successful login
- Throws:
- AuthenticationException- raised in case of failed login
 
 - 
createSessionpublic Session createSession(User user, Client client) throws AuthenticationException Creates a new session by authenticated the given user and stores it in the pool of opened sessions- Parameters:
- user- the user
- client- client informations
- Returns:
- the session created after the successful login
- Throws:
- AuthenticationException
 
 - 
killpublic void kill(String sid) Kills an existing session- Parameters:
- sid- identifier of the session to kill
 
 - 
renewpublic void renew(String sid) Renews an opened session- Parameters:
- sid- The session to be renewed
 
 - 
getStatuspublic int getStatus(String sid) 
 - 
isOpenpublic boolean isOpen(String sid) Checks if a session is valid or not. A valid session is a one that exists and is in state OPEN- Parameters:
- sid- The session identifier
- Returns:
- true only if the session exists and is OPEN
 
 - 
getByClientIdpublic Session getByClientId(String clientId) Gets the session of the given client- Parameters:
- clientId- identifier of the client
- Returns:
- the session
 
 - 
countOpenedpublic int countOpened() Counts the total number of opened sessions- Returns:
- number of opened sessions
 
 - 
countOpenedpublic int countOpened(long tenantId) Counts the total number of opened sessions per tenant- Parameters:
- tenantId- identifier of the tenant
- Returns:
- number of opened sessions
 
 - 
getSessionspublic List<Session> getSessions() Returns the list of sessions of the current node ordered by ascending status and creation date.- Returns:
- list of sessions
 
 - 
getSessionpublic Session getSession(javax.servlet.http.HttpServletRequest request) Gets the Session with the identifier returned bygetSessionId(HttpServletRequest)- Parameters:
- request- the HTTP request
- Returns:
- the found session, can be null
 
 - 
getSessionIdpublic String getSessionId(javax.servlet.http.HttpServletRequest request) Gets the Session ID specification from the current request following this lookup strategy:- Session attribute PARAM_SID
- Request attribute PARAM_SID
- Request parameter PARAM_SID
- Cookie COOKIE_SID
- Spring SecurityContextHolder
 - Parameters:
- request- The current request to inspect
- Returns:
- The SID if any
 
- Session attribute 
 - 
saveSidpublic void saveSid(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String sid)Saves the session identifier in the request and session attributePARAM_SIDand CookieCOOKIE_SID- Parameters:
- request- the HTTP request
- response- the HTTP response
- sid- identifier of the session
 
 - 
removeSidpublic void removeSid(javax.servlet.http.HttpServletRequest request) Removes the Sid from the http request- Parameters:
- request- the HTTP request
 
 - 
getCurrentSidpublic static String getCurrentSid() Retrieves the session ID of the current thread execution- Returns:
- the identifier of the session
 
 - 
getServletSessionpublic javax.servlet.http.HttpSession getServletSession(String sid) 
 - 
buildClientpublic Client buildClient(javax.servlet.http.HttpServletRequest req) Create a client identified using a concatenation of Basic authentication credentials and remote IP.- Parameters:
- req- The request to process
- Returns:
- The client
 
 - 
setAuthenticationChainpublic void setAuthenticationChain(AuthenticationChain authenticationChain) 
 - 
destroypublic void destroy() 
 - 
getSessionDaopublic SessionDAO getSessionDao() 
 - 
setSessionDaopublic void setSessionDao(SessionDAO sessionDao) 
 - 
addListenerpublic void addListener(SessionListener listener) 
 - 
removeListenerpublic void removeListener(SessionListener listener) 
 
- 
 
-