public ISerializableSession create(AbstractSession session) { synchronized(session) { ISerializableSession s = create(session.getId(), session.getCreationTime(), session.getAccessed()); if (session.isValid()) { for (String key: session.getNames()) { s.setAttribute(key, session.getAttribute(key)); } } else { // we do not need to retrieve attributes of invalidated sessions since // they have been cleared on AbstractSession.invalidate(). s.setValid(false); } return s; } }
/** * @see SessionIdManager#invalidateAll(String) */ public void invalidateAll(String id) { Collection<WeakReference<HttpSession>> sessions; synchronized (this) { sessions = _sessions.remove(id); } if (sessions!=null) { for (WeakReference<HttpSession> ref: sessions) { AbstractSession session=(AbstractSession)ref.get(); if (session!=null && session.isValid()) session.invalidate(); } sessions.clear(); } }
public void renewId(HttpServletRequest request) { _manager._sessionIdManager.renewSessionId(getClusterId(), getNodeId(), request); setIdChanged(true); }
protected boolean access(long time) { synchronized(this) { if (_invalid) return false; _newSession=false; _lastAccessed=_accessed; _accessed=time; if (checkExpiry(time)) { invalidate(); return false; } _requests++; return true; } }
/** * Add a newly created session to our in-memory list for this node and persist it. * * @see org.eclipse.jetty.server.session.AbstractSessionManager#addSession(org.eclipse.jetty.server.session.AbstractSession) */ @Override protected void addSession(AbstractSession session) { if (session==null) return; _sessions.put(session.getClusterId(), (Session)session); try { synchronized (session) { session.willPassivate(); storeSession(((JDBCSessionManager.Session)session)); session.didActivate(); } } catch (Exception e) { LOG.warn("Unable to store new session id="+session.getId() , e); } }
public HttpCookie access(HttpSession session,boolean secure) { long now=System.currentTimeMillis(); AbstractSession s = ((SessionIf)session).getSession(); if (s.access(now)) { // Do we need to refresh the cookie? if (isUsingCookies() && (s.isIdChanged() || (getSessionCookieConfig().getMaxAge()>0 && getRefreshCookieAge()>0 && ((now-s.getCookieSetTime())/1000>getRefreshCookieAge())) ) ) { HttpCookie cookie=getSessionCookie(session,_context==null?"/":(_context.getContextPath()),secure); s.cookieSet(); s.setIdChanged(false); return cookie; } } return null; }
/** Remove session from manager * @param session The session to remove * @param invalidate True if {@link HttpSessionListener#sessionDestroyed(HttpSessionEvent)} and * {@link SessionIdManager#invalidateAll(String)} should be called. */ public boolean removeSession(AbstractSession session, boolean invalidate) { // Remove session from context and global maps boolean removed = removeSession(session.getClusterId()); if (removed) { _sessionsStats.decrement(); _sessionTimeStats.set(round((System.currentTimeMillis() - session.getCreationTime())/1000.0)); // Remove session from all context and global id maps _sessionIdManager.removeSession(session); if (invalidate) _sessionIdManager.invalidateAll(session.getClusterId()); if (invalidate && _sessionListeners!=null) { HttpSessionEvent event=new HttpSessionEvent(session); for (int i = _sessionListeners.size()-1; i>=0; i--) { _sessionListeners.get(i).sessionDestroyed(event); } } } return removed; }
public String changeSessionId() { HttpSession session = getSession(false); if (session == null) throw new IllegalStateException("No session"); if (session instanceof AbstractSession) { AbstractSession abstractSession = ((AbstractSession)session); abstractSession.renewId(this); if (getRemoteUser() != null) abstractSession.setAttribute(AbstractSession.SESSION_CREATED_SECURE, Boolean.TRUE); if (abstractSession.isIdChanged()) _channel.getResponse().addCookie(_sessionManager.getSessionCookie(abstractSession, getContextPath(), isSecure())); } return session.getId(); }
/** * Create a new HttpSession for a request */ public HttpSession newHttpSession(HttpServletRequest request) { AbstractSession session=newSession(request); session.setMaxInactiveInterval(_dftMaxIdleSecs); addSession(session,true); return session; }
@Override public final void removeSession(final AbstractSession session, boolean invalidate) { final String clusterId = getClusterId(session); final boolean removed = removeSession(clusterId); if (removed) { _sessionsStats.decrement(); _sessionTimeStats.set(Math.round((System.currentTimeMillis() - session.getCreationTime()) / 1000.0)); _sessionIdManager.removeSession(session); if (invalidate) { _sessionIdManager.invalidateAll(session.getClusterId()); } if (invalidate && _sessionListeners != null) { final HttpSessionEvent event = new HttpSessionEvent(session); for (int i = LazyList.size(_sessionListeners); i-- > 0;) { ((HttpSessionListener) LazyList.get(_sessionListeners, i)).sessionDestroyed(event); } } if (!invalidate) { session.willPassivate(); } } }
@Override public String toString() { return this.getClass().getName()+":"+getId()+"@"+hashCode(); }
@Override public void setAttribute (String name, Object value) { super.setAttribute(name, value); _dirty=true; }
public String getClusterId(HttpSession session) { AbstractSession s = ((SessionIf)session).getSession(); return s.getClusterId(); }
@Override public boolean isValid(HttpSession session) { AbstractSession s = ((SessionIf)session).getSession(); return s.isValid(); }
protected boolean access(long time) { synchronized(this) { if (_invalid) return false; _newSession=false; _lastAccessed=_accessed; _accessed=time; if (_maxIdleMs>0 && _lastAccessed>0 && _lastAccessed + _maxIdleMs < time) { invalidate(); return false; } _requests++; return true; } }
/** * @deprecated As of Version 2.2, this method is replaced by * {@link #getAttribute} */ @Deprecated public Object getValue(String name) throws IllegalStateException { return getAttribute(name); }
@Override protected final void addSession(final AbstractSession session) { if (isRunning()) { final String clusterId = getClusterId(session); sessions.put(clusterId, (Session) session); session.willPassivate(); storeSession((Session) session); session.didActivate(); } }
/** * Add a newly created session to our in-memory list for this node and persist it. * * @see org.eclipse.jetty.server.session.AbstractSessionManager#addSession(org.eclipse.jetty.server.session.AbstractSession) */ @Override protected void addSession(AbstractSession session) { if (session==null) return; synchronized (this) { _sessions.put(session.getClusterId(), session); } //TODO or delay the store until exit out of session? If we crash before we store it //then session data will be lost. try { session.willPassivate(); storeSession(((JDBCSessionManager.Session)session)._data); session.didActivate(); } catch (Exception e) { LOG.warn("Unable to store new session id="+session.getId() , e); } }
public HttpCookie access(HttpSession session,boolean secure) { long now=System.currentTimeMillis(); AbstractSession s = ((SessionIf)session).getSession(); if (s.access(now)) { // Do we need to refresh the cookie? if (isUsingCookies() && (s.isIdChanged() || (getSessionCookieConfig().getMaxAge()>0 && getRefreshCookieAge()>0 && ((now-s.getCookieSetTime())/1000>getRefreshCookieAge())) ) ) { HttpCookie cookie=getSessionCookie(session,_context==null?"/":(_context.getContextPath()),secure); s.cookieSet(); s.setIdChanged(false); return cookie; } } return null; }
/** Remove session from manager * @param session The session to remove * @param invalidate True if {@link HttpSessionListener#sessionDestroyed(HttpSessionEvent)} and * {@link SessionIdManager#invalidateAll(String)} should be called. */ public void removeSession(AbstractSession session, boolean invalidate) { // Remove session from context and global maps boolean removed = removeSession(session.getClusterId()); if (removed) { _sessionsStats.decrement(); _sessionTimeStats.set(round((System.currentTimeMillis() - session.getCreationTime())/1000.0)); // Remove session from all context and global id maps _sessionIdManager.removeSession(session); if (invalidate) _sessionIdManager.invalidateAll(session.getClusterId()); if (invalidate && _sessionListeners!=null) { HttpSessionEvent event=new HttpSessionEvent(session); for (HttpSessionListener listener : _sessionListeners) listener.sessionDestroyed(event); } } }