Exemplo n.º 1
0
 @Override
 public void onRemoval(RemovalNotification<Serializable, Session> notification) {
   Serializable key = notification.getKey();
   Session session = notification.getValue();
   if (notification.getCause() == RemovalCause.EXPIRED) {
     // time out cause session expired.
     logger.info("session for {} expired.", session.getId());
   } else {
     // logout cause session be removed.
     logger.info("session for {} stoped.", session.getId());
   }
   Object attribute = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
   if (attribute instanceof PrincipalCollection) {
     PrincipalCollection collection = (PrincipalCollection) attribute;
     for (Object object : collection) {
       if (object instanceof ShiroPrincipal) {
         ShiroPrincipal shiroPrincipal = (ShiroPrincipal) object;
         UsrSession userSession = shiroPrincipal.getSession();
         userSession.setLastAccessTime(new Timestamp(session.getLastAccessTime().getTime()));
         userSession.setStopTime(new Timestamp(System.currentTimeMillis()));
         UsrSession merge = userSessionDao.update(userSession);
         shiroPrincipal.setSession(merge);
       }
     }
   }
 }
Exemplo n.º 2
0
 @Override
 public void onRemoval(RemovalNotification<Serializable, WebSession> notification) {
   Serializable key = notification.getKey();
   WebSession session = notification.getValue();
   if (notification.getCause() == RemovalCause.EXPIRED) {
     // time out cause session expired.
     logger.info("session for {} expired.", session.getId());
   } else {
     // logout cause session be removed.
     logger.info("session for {} stoped.", session.getId());
   }
   session.stop();
   UsrSession userSession = session.getValue();
   userSession.setLastAccessTime(new Timestamp(session.getLastAccessTime().getTime()));
   userSession.setStopTime(new Timestamp(session.getStopTimestamp().getTime()));
   userSessionDao.update(userSession);
 }