Пример #1
0
 public void expireSession(String sessionId) {
   Session s = (Session) sessions.get(sessionId);
   if (s == null) {
     return;
   }
   s.expire();
 }
 protected ModelAndView handleRequestInternal(
     HttpServletRequest request, HttpServletResponse response) throws Exception {
   String[] sidWebApps = ServletRequestUtils.getStringParameters(request, "sid_webapp");
   for (int i = 0; i < sidWebApps.length; i++) {
     if (sidWebApps[i] != null) {
       String[] ss = sidWebApps[i].split(";");
       if (ss.length == 2) {
         String sessionId = ss[0];
         String appName = ss[1];
         Context context = getContainerWrapper().getTomcatContainer().findContext(appName);
         if (context != null) {
           Manager manager = context.getManager();
           Session session = manager.findSession(sessionId);
           if (session != null && session.isValid()) {
             session.expire();
           }
         } else {
           return new ModelAndView("errors/paramerror");
         }
       } else {
         return new ModelAndView("errors/paramerror");
       }
     }
   }
   return new ModelAndView(new InternalResourceView(getViewName()));
 }
Пример #3
0
 public void expireSession(String sessionId) {
   Session s = (Session) sessions.get(sessionId);
   if (s == null) {
     if (log.isInfoEnabled()) log.info("Session not found " + sessionId);
     return;
   }
   s.expire();
 }
Пример #4
0
 /**
  * Expire sessions whose lifetime is greater than or equal to <code>maxLifetimeMillis</code>
  *
  * @param maxLifetimeMillis The maximum session lifetime in milliseconds
  */
 public void expireSessions(long maxLifetimeMillis) {
   Session[] sessions = context.getManager().findSessions();
   for (Session session : sessions) {
     if ((System.currentTimeMillis() - session.getCreationTime()) >= maxLifetimeMillis) {
       session.expire();
     }
   }
 }
Пример #5
0
  public void logout() throws SecurityServiceException {
    HttpGraniteContext context = (HttpGraniteContext) GraniteManager.getCurrentInstance();

    Session session = getSession(context.getRequest(), false);
    if (session != null && session.getPrincipal() != null) {
      session.setAuthType(null);
      session.setPrincipal(null);
      session.removeNote(Constants.SESS_USERNAME_NOTE);
      session.removeNote(Constants.SESS_PASSWORD_NOTE);
      session.expire();
    }
  }
 @Override
 public ApiResponse signOutAll() {
   ApiResponse response = ApiResponse.createDefaultApiResponse();
   HttpServletRequest request = HttpUtil.getRequest();
   HttpSession httpSession = HttpUtil.getSession();
   if (request instanceof RequestFacade) {
     Field requestField = null;
     try {
       requestField = request.getClass().getDeclaredField("request");
     } catch (NoSuchFieldException e) {
       e.printStackTrace();
     }
     if (requestField != null) {
       requestField.setAccessible(true);
       Request req = null;
       try {
         req = (Request) requestField.get(request);
       } catch (IllegalAccessException e) {
         e.printStackTrace();
       }
       if (req != null) {
         Context context = req.getContext();
         Manager manager = context.getManager();
         Session[] sessions = manager.findSessions();
         if (sessions != null) {
           for (Session session : sessions) {
             if (!httpSession.getId().equals(session.getId())) {
               session.expire();
             }
           }
         }
       }
     }
   }
   return response;
 }
 /**
  * This method is called by the received thread when a SessionMessage has been received from one
  * of the other nodes in the cluster.
  *
  * @param msg - the message received
  * @param sender - the sender of the message, this is used if we receive a EVT_GET_ALL_SESSION
  *     message, so that we only reply to the requesting node
  */
 protected void messageReceived(SessionMessage msg, Member sender) {
   try {
     if (log.isInfoEnabled()) {
       log.debug("Received SessionMessage of type=" + msg.getEventTypeString());
       log.debug("Received SessionMessage sender=" + sender);
     }
     switch (msg.getEventType()) {
       case SessionMessage.EVT_GET_ALL_SESSIONS:
         {
           // get a list of all the session from this manager
           Object[] sessions = findSessions();
           java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
           java.io.ObjectOutputStream oout = new java.io.ObjectOutputStream(bout);
           oout.writeInt(sessions.length);
           for (int i = 0; i < sessions.length; i++) {
             ReplicatedSession ses = (ReplicatedSession) sessions[i];
             oout.writeUTF(ses.getIdInternal());
             byte[] data = writeSession(ses);
             oout.writeObject(data);
           } // for
           // don't send a message if we don't have to
           oout.flush();
           oout.close();
           byte[] data = bout.toByteArray();
           SessionMessage newmsg =
               new SessionMessageImpl(
                   name,
                   SessionMessage.EVT_ALL_SESSION_DATA,
                   data,
                   "SESSION-STATE",
                   "SESSION-STATE-" + getName());
           cluster.send(newmsg, sender);
           break;
         }
       case SessionMessage.EVT_ALL_SESSION_DATA:
         {
           java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(msg.getSession());
           java.io.ObjectInputStream oin = new java.io.ObjectInputStream(bin);
           int size = oin.readInt();
           for (int i = 0; i < size; i++) {
             String id = oin.readUTF();
             byte[] data = (byte[]) oin.readObject();
             Session session = readSession(data, id);
           } // for
           stateTransferred = true;
           break;
         }
       case SessionMessage.EVT_SESSION_CREATED:
         {
           Session session = this.readSession(msg.getSession(), msg.getSessionID());
           if (log.isDebugEnabled()) {
             log.debug("Received replicated session=" + session + " isValid=" + session.isValid());
           }
           break;
         }
       case SessionMessage.EVT_SESSION_EXPIRED:
         {
           Session session = findSession(msg.getSessionID());
           if (session != null) {
             session.expire();
             this.remove(session);
           } // end if
           break;
         }
       case SessionMessage.EVT_SESSION_ACCESSED:
         {
           Session session = findSession(msg.getSessionID());
           if (session != null) {
             session.access();
             session.endAccess();
           }
           break;
         }
       default:
         {
           // we didn't recognize the message type, do nothing
           break;
         }
     } // switch
   } catch (Exception x) {
     log.error("Unable to receive message through TCP channel", x);
   }
 }
Пример #8
0
 public void expire() {
   tomcatSession.expire();
 }
Пример #9
0
 /** Expire all sessions of this webapp */
 public void expireAllSessions() {
   Session[] sessions = context.getManager().findSessions();
   for (Session session : sessions) {
     session.expire();
   }
 }