/** * Calls {@code super.create(session)}, then caches the session keyed by the returned {@code sessionId}, and then * returns this {@code sessionId}. * * @param session Session object to create in the EIS and then cache. */ public Serializable create(Session session) { Serializable sessionId = super.create(session); cache(session, sessionId); return sessionId; }
public EnterpriseCacheSessionDAO() { setCacheManager(new AbstractCacheManager() { @Override protected Cache<Serializable, Session> createCache(String name) throws CacheException { return new MapCache<Serializable, Session>(name, new ConcurrentHashMap<Serializable, Session>()); } }); }
/** * Removes the specified session from any cache and then permanently deletes the session from the EIS by * delegating to {@link #doDelete}. * * @param session the session to remove from caches and permanently delete from the EIS. */ public void delete(Session session) { uncache(session); doDelete(session); }
@Override public boolean forceLogout(String sessionId) { Session session = sessionDAO.readSession(sessionId); session.setTimeout(0); session.stop(); sessionDAO.delete(session); return true; }
/** * Attempts to acquire the Session from the cache first using the session ID as the cache key. If no session * is found, {@code super.readSession(sessionId)} is called to perform the actual retrieval. * * @param sessionId the id of the session to retrieve from the EIS. * @return the session identified by {@code sessionId} in the EIS. * @throws UnknownSessionException if the id specified does not correspond to any session in the cache or EIS. */ public Session readSession(Serializable sessionId) throws UnknownSessionException { Session s = getCachedSession(sessionId); if (s == null) { s = super.readSession(sessionId); } return s; }
protected Serializable doCreate(Session session) { Serializable sessionId = generateSessionId(session); assignSessionId(session, sessionId); storeSession(sessionId, session); return sessionId; }
protected Session retrieveSessionFromDataSource(Serializable sessionId) throws UnknownSessionException { return sessionDAO.readSession(sessionId); }
/** * Default no-arg constructor that defaults the {@link #setSessionIdGenerator sessionIdGenerator} to be a * {@link org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator}. */ public AbstractSessionDAO() { this.sessionIdGenerator = new JavaUuidSessionIdGenerator(); }
protected void delete(Session session) { sessionDAO.delete(session); }
/** * Creates the session by delegating EIS creation to subclasses via the {@link #doCreate} method, and then * asserting that the returned sessionId is not null. * * @param session Session object to create in the EIS and associate with an ID. */ public Serializable create(Session session) { Serializable sessionId = doCreate(session); verifySessionId(sessionId); return sessionId; }
protected Serializable doCreate(Session session) { Serializable sessionId = generateSessionId(session); assignSessionId(session, sessionId); return sessionId; }
protected void onChange(Session session) { sessionDAO.update(session); }
/** * Caches the specified session under the cache entry key of {@code sessionId}. * * @param session the session to cache * @param sessionId the session id, to be used as the cache entry key. * @since 1.0 */ protected void cache(Session session, Serializable sessionId) { if (session == null || sessionId == null) { return; } Cache<Serializable, Session> cache = getActiveSessionsCacheLazy(); if (cache == null) { return; } cache(session, sessionId, cache); }
/** * Returns the cached session with the corresponding {@code sessionId} or {@code null} if there is * no session cached under that id (or if there is no Cache). * * @param sessionId the id of the cached session to acquire. * @return the cached session with the corresponding {@code sessionId}, or {@code null} if the session * does not exist or is not cached. */ protected Session getCachedSession(Serializable sessionId) { Session cached = null; if (sessionId != null) { Cache<Serializable, Session> cache = getActiveSessionsCacheLazy(); if (cache != null) { cached = getCachedSession(sessionId, cache); } } return cached; }
protected SessionDAO sessionDAO() { return new MemorySessionDAO(); }
protected Collection<Session> getActiveSessions() { Collection<Session> active = sessionDAO.getActiveSessions(); return active != null ? active : Collections.<Session>emptySet(); }
/** * Persists the given session instance to an underlying EIS (Enterprise Information System). This implementation * delegates and calls * <code>this.{@link SessionDAO sessionDAO}.{@link SessionDAO#create(org.apache.shiro.session.Session) create}(session);<code> * * @param session the Session instance to persist to the underlying EIS. */ protected void create(Session session) { if (log.isDebugEnabled()) { log.debug("Creating new EIS record for new session instance [" + session + "]"); } sessionDAO.create(session); }
/** * Returns the active sessions cache, but if that cache instance is null, first lazily creates the cache instance * via the {@link #createActiveSessionsCache()} method and then returns the instance. * <p/> * Note that this method will only return a non-null value code if the {@code CacheManager} has been set. If * not set, there will be no cache. * * @return the active sessions cache instance. */ private Cache<Serializable, Session> getActiveSessionsCacheLazy() { if (this.activeSessions == null) { this.activeSessions = createActiveSessionsCache(); } return activeSessions; }
public void update(Session session) throws UnknownSessionException { storeSession(session.getId(), session); }
public DefaultSessionManager() { this.deleteInvalidSessions = true; this.sessionFactory = new SimpleSessionFactory(); this.sessionDAO = new MemorySessionDAO(); }