Java Code Examples for org.apache.catalina.Session#isValid()
The following examples show how to use
org.apache.catalina.Session#isValid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistentManagerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Remove the session from the Manager's list of active * sessions and write it out to the Store. If the session * is past its expiration or invalid, this method does * nothing. * * @param session The Session to write out * @throws IOException an IO error occurred */ protected void swapOut(Session session) throws IOException { if (store == null || !session.isValid()) { return; } ((StandardSession)session).passivate(); writeSession(session); super.remove(session, true); session.recycle(); }
Example 2
Source File: PersistentManagerBase.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Write the provided session to the Store without modifying * the copy in memory or triggering passivation events. Does * nothing if the session is invalid or past its expiration. * @param session The session that should be written * @throws IOException an IO error occurred */ protected void writeSession(Session session) throws IOException { if (store == null || !session.isValid()) { return; } try { if (SecurityUtil.isPackageProtectionEnabled()){ try{ AccessController.doPrivileged(new PrivilegedStoreSave(session)); }catch(PrivilegedActionException ex){ Exception exception = ex.getException(); if (exception instanceof IOException) { throw (IOException) exception; } log.error("Exception in the Store during writeSession: " + exception, exception); } } else { store.save(session); } } catch (IOException e) { log.error(sm.getString ("persistentManager.serializeError", session.getIdInternal(), e)); throw e; } }
Example 3
Source File: ApplicationHttpRequest.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Returns true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. * * @return true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. */ @Override public boolean isRequestedSessionIdValid() { if (crossContext) { String requestedSessionId = getRequestedSessionId(); if (requestedSessionId == null) return false; if (context == null) return false; Manager manager = context.getManager(); if (manager == null) return false; Session session = null; try { session = manager.findSession(requestedSessionId); } catch (IOException e) { // Ignore } if ((session != null) && session.isValid()) { return true; } else { return false; } } else { return super.isRequestedSessionIdValid(); } }
Example 4
Source File: PersistentManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Remove the session from the Manager's list of active * sessions and write it out to the Store. If the session * is past its expiration or invalid, this method does * nothing. * * @param session The Session to write out. */ protected void swapOut(Session session) throws IOException { if (store == null || !session.isValid()) { return; } ((StandardSession)session).passivate(); writeSession(session); super.remove(session, true); session.recycle(); }
Example 5
Source File: PersistentManagerBase.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Write the provided session to the Store without modifying * the copy in memory or triggering passivation events. Does * nothing if the session is invalid or past its expiration. */ protected void writeSession(Session session) throws IOException { if (store == null || !session.isValid()) { return; } try { if (SecurityUtil.isPackageProtectionEnabled()){ try{ AccessController.doPrivileged(new PrivilegedStoreSave(session)); }catch(PrivilegedActionException ex){ Exception exception = ex.getException(); if (exception instanceof IOException) { throw (IOException) exception; } log.error("Exception in the Store during writeSession: " + exception, exception); } } else { store.save(session); } } catch (IOException e) { log.error(sm.getString ("persistentManager.serializeError", session.getIdInternal(), e)); throw e; } }
Example 6
Source File: ApplicationHttpRequest.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Returns true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. * * @return true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. */ @Override public boolean isRequestedSessionIdValid() { if (crossContext) { String requestedSessionId = getRequestedSessionId(); if (requestedSessionId == null) return (false); if (context == null) return (false); Manager manager = context.getManager(); if (manager == null) return (false); Session session = null; try { session = manager.findSession(requestedSessionId); } catch (IOException e) { // Ignore } if ((session != null) && session.isValid()) { return (true); } else { return (false); } } else { return super.isRequestedSessionIdValid(); } }
Example 7
Source File: PersistentManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Remove the session from the Manager's list of active * sessions and write it out to the Store. If the session * is past its expiration or invalid, this method does * nothing. * * @param session The Session to write out. */ protected void swapOut(Session session) throws IOException { if (store == null || !session.isValid()) { return; } ((StandardSession)session).passivate(); writeSession(session); super.remove(session, true); session.recycle(); }
Example 8
Source File: PersistentManagerBase.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Write the provided session to the Store without modifying * the copy in memory or triggering passivation events. Does * nothing if the session is invalid or past its expiration. */ protected void writeSession(Session session) throws IOException { if (store == null || !session.isValid()) { return; } try { if (SecurityUtil.isPackageProtectionEnabled()){ try{ AccessController.doPrivileged(new PrivilegedStoreSave(session)); }catch(PrivilegedActionException ex){ Exception exception = ex.getException(); if (exception instanceof IOException) { throw (IOException) exception; } log.error("Exception in the Store during writeSession: " + exception, exception); } } else { store.save(session); } } catch (IOException e) { log.error(sm.getString ("persistentManager.serializeError", session.getIdInternal(), e)); throw e; } }
Example 9
Source File: ApplicationHttpRequest.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Returns true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. * * @return true if the request specifies a JSESSIONID that is valid within * the context of this ApplicationHttpRequest, false otherwise. */ @Override public boolean isRequestedSessionIdValid() { if (crossContext) { String requestedSessionId = getRequestedSessionId(); if (requestedSessionId == null) return (false); if (context == null) return (false); Manager manager = context.getManager(); if (manager == null) return (false); Session session = null; try { session = manager.findSession(requestedSessionId); } catch (IOException e) { // Ignore } if ((session != null) && session.isValid()) { return (true); } else { return (false); } } else { return super.isRequestedSessionIdValid(); } }
Example 10
Source File: PersistentManagerBase.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Look for a session in the Store and, if found, restore * it in the Manager's list of active sessions if appropriate. * The session will be removed from the Store after swapping * in, but will not be added to the active session list if it * is invalid or past its expiration. * * @param id The id of the session that should be swapped in * @return restored session, or {@code null}, if none is found * @throws IOException an IO error occurred */ protected Session swapIn(String id) throws IOException { if (store == null) return null; Object swapInLock = null; /* * The purpose of this sync and these locks is to make sure that a * session is only loaded once. It doesn't matter if the lock is removed * and then another thread enters this method and tries to load the same * session. That thread will re-create a swapIn lock for that session, * quickly find that the session is already in sessions, use it and * carry on. */ synchronized (this) { swapInLock = sessionSwapInLocks.get(id); if (swapInLock == null) { swapInLock = new Object(); sessionSwapInLocks.put(id, swapInLock); } } Session session = null; synchronized (swapInLock) { // First check to see if another thread has loaded the session into // the manager session = sessions.get(id); if (session == null) { Session currentSwapInSession = sessionToSwapIn.get(); try { if (currentSwapInSession == null || !id.equals(currentSwapInSession.getId())) { session = loadSessionFromStore(id); sessionToSwapIn.set(session); if (session != null && !session.isValid()) { log.error(sm.getString("persistentManager.swapInInvalid", id)); session.expire(); removeSession(id); session = null; } if (session != null) { reactivateLoadedSession(id, session); } } } finally { sessionToSwapIn.remove(); } } } // Make sure the lock is removed synchronized (this) { sessionSwapInLocks.remove(id); } return session; }
Example 11
Source File: ApplicationHttpRequest.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Return the session associated with this Request, creating one * if necessary and requested. * * @param create Create a new session if one does not exist */ @Override public HttpSession getSession(boolean create) { if (crossContext) { // There cannot be a session if no context has been assigned yet if (context == null) return null; // Return the current session if it exists and is valid if (session != null && session.isValid()) { return session.getSession(); } HttpSession other = super.getSession(false); if (create && (other == null)) { // First create a session in the first context: the problem is // that the top level request is the only one which can // create the cookie safely other = super.getSession(true); } if (other != null) { Session localSession = null; try { localSession = context.getManager().findSession(other.getId()); if (localSession != null && !localSession.isValid()) { localSession = null; } } catch (IOException e) { // Ignore } if (localSession == null && create) { localSession = context.getManager().createSession(other.getId()); } if (localSession != null) { localSession.access(); session = localSession; return session.getSession(); } } return null; } else { return super.getSession(create); } }
Example 12
Source File: ApplicationHttpRequest.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Return the session associated with this Request, creating one * if necessary and requested. * * @param create Create a new session if one does not exist */ @Override public HttpSession getSession(boolean create) { if (crossContext) { // There cannot be a session if no context has been assigned yet if (context == null) return (null); // Return the current session if it exists and is valid if (session != null && session.isValid()) { return (session.getSession()); } HttpSession other = super.getSession(false); if (create && (other == null)) { // First create a session in the first context: the problem is // that the top level request is the only one which can // create the cookie safely other = super.getSession(true); } if (other != null) { Session localSession = null; try { localSession = context.getManager().findSession(other.getId()); if (localSession != null && !localSession.isValid()) { localSession = null; } } catch (IOException e) { // Ignore } if (localSession == null && create) { localSession = context.getManager().createSession(other.getId()); } if (localSession != null) { localSession.access(); session = localSession; return session.getSession(); } } return null; } else { return super.getSession(create); } }
Example 13
Source File: ApplicationHttpRequest.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Return the session associated with this Request, creating one * if necessary and requested. * * @param create Create a new session if one does not exist */ @Override public HttpSession getSession(boolean create) { if (crossContext) { // There cannot be a session if no context has been assigned yet if (context == null) return (null); // Return the current session if it exists and is valid if (session != null && session.isValid()) { return (session.getSession()); } HttpSession other = super.getSession(false); if (create && (other == null)) { // First create a session in the first context: the problem is // that the top level request is the only one which can // create the cookie safely other = super.getSession(true); } if (other != null) { Session localSession = null; try { localSession = context.getManager().findSession(other.getId()); if (localSession != null && !localSession.isValid()) { localSession = null; } } catch (IOException e) { // Ignore } if (localSession == null && create) { localSession = context.getManager().createSession(other.getId()); } if (localSession != null) { localSession.access(); session = localSession; return session.getSession(); } } return null; } else { return super.getSession(create); } }