Beispiel #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet
   * .http.HttpSessionBindingEvent)
   */
  public void valueUnbound(HttpSessionBindingEvent event) {
    // 刷新页面的时候,TSysUser为null,所以要判断一下
    LoginUserVO user = (LoginUserVO) event.getValue();
    if (user != null) {
      /** ********************** UniId begin ******************************** */
      // 通知统一身份认证服务中心。此处的实现是通过数据库
      boolean singleLogin =
          PropDbUtil.getBoolean(IdConstants.SINGLE_LOGIN); // 是否开启了同一用户同一时间所有节点上只能登录一个的要求
      if (singleLogin) {
        String sql = SQLConfigUtil.getSql("sql.loginUserVO.delete");
        DBUtil.executeSQL(sql, user.getUserloginid()); // 移除在线用户表中用户信息
      }
      /** ********************** UniId end ******************************** */
      onlineUsers.remove(event.getSession().getId());
      if (LOG.isInfoEnabled()) {
        LOG.info(
            user.getUsername()
                + "[账号:"
                + user.getUserloginid()
                + "]"
                + " 退出系统"
                + ",目前有"
                + getCurrentOnlineCount()
                + "个用户已登录");
      }

    } else {
      if (LOG.isInfoEnabled()) {
        LOG.info(" 一个用户刷新系统" + ",目前有" + getCurrentOnlineCount() + "个用户已登录");
      }
    }
  }
Beispiel #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet
   * .http.HttpSessionBindingEvent)
   */
  public void valueBound(HttpSessionBindingEvent event) {

    LoginUserVO user = (LoginUserVO) event.getValue();
    onlineUsers.put(event.getSession().getId(), user);
    if (LOG.isInfoEnabled()) {
      LOG.info(
          user.getUsername()
              + "[账号:"
              + user.getUserloginid()
              + "]"
              + " 登录系统"
              + ",目前有"
              + getCurrentOnlineCount()
              + "个用户已登录");
    }

    /** ********************** UniId begin ******************************** */
    // 通知统一身份认证服务中心。此处的实现是通过数据库
    boolean singleLogin =
        PropDbUtil.getBoolean(IdConstants.SINGLE_LOGIN); // 是否开启了同一用户同一时间所有节点上只能登录一个的要求
    if (singleLogin) {
      try {
        String sql = SQLConfigUtil.getSql("sql.loginUserVO.count");
        int onlineNum = DBUtil.count(sql, getUserloginid());
        if (onlineNum == 0) {
          sql = SQLConfigUtil.getSql("sql.loginUserVO.insert");
          DBUtil.executeSQL(
              sql, getUserloginid(), getClientIP(), getServerIP(), DateUtil.currentTime());
        }
      } catch (SQLException e) {
        LOG.error(e);
      }
    }
    /** ********************** UniId end ******************************** */
  }
 public void attributeReplaced(HttpSessionBindingEvent evt) {
   final String name = evt.getName();
   if (!shallIgnore(name)) {
     final Session sess = Sessions.getCurrent();
     if (sess instanceof SimpleSession && evt.getSession().equals(sess.getNativeSession()))
       ((SimpleSession) sess).getScopeListeners().notifyReplaced(name, evt.getValue());
   }
 }
 @Override
 public void attributeAdded(HttpSessionBindingEvent _event) {
   System.out.println(
       "edu.temple.cis3238.wiki.WikiEventMonitor.[SESSION]attributeAdded()\n added "
           + _event.getName()
           + _event.toString());
   LOG.info(Objects.toString(_event.getValue().toString()));
   LOG.info(Objects.toString(_event.getSource()));
 }
 /**
  * This method is designed to catch when user's login and record their name
  *
  * @param event the event to process
  * @see
  *     javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
  */
 public void attributeAdded(HttpSessionBindingEvent event) {
   if (event.getName().equals(EVENT_KEY) && !isAnonymous()) {
     SecurityContext securityContext = (SecurityContext) event.getValue();
     if (securityContext.getAuthentication().getPrincipal() instanceof User) {
       User user = (User) securityContext.getAuthentication().getPrincipal();
       addUsername(user);
     }
   }
 }
Beispiel #6
0
  /** {@inheritDoc} */
  @Override
  public void attributeReplaced(HttpSessionBindingEvent event) {
    if (event.getName().equals(EVENT_KEY) && !isAnonymous()) {
      Authentication auth = ((SecurityContext) event.getValue()).getAuthentication();

      if (auth != null && auth.getPrincipal() instanceof User) {
        addUser((User) auth.getPrincipal(), event.getSession().getServletContext());
      }
    }
  }
 /**
  * When user's logout, remove their name from the hashMap
  *
  * @param event the session binding event
  * @see
  *     javax.servlet.http.HttpSessionAttributeListener#attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)
  */
 public void attributeRemoved(HttpSessionBindingEvent event) {
   if (event.getName().equals(EVENT_KEY) && !isAnonymous()) {
     SecurityContext securityContext = (SecurityContext) event.getValue();
     Authentication auth = securityContext.getAuthentication();
     if (auth != null && (auth.getPrincipal() instanceof User)) {
       User user = (User) auth.getPrincipal();
       removeUsername(user);
     }
   }
 }
Beispiel #8
0
  public void attributeRemoved(HttpSessionBindingEvent event) {
    // TODO Auto-generated method stub

    if (event.getName().equals("LOGIN_IP")) {
      try {
        OnlineCounter.doUser(event.getValue(), true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
 private void checkAttribute(
     HttpSessionBindingEvent event,
     String orderAttributeName,
     String keyItemName,
     String message) {
   String currentAttributeName = event.getName();
   String currentItemName = (String) event.getValue();
   if (currentAttributeName.equals(orderAttributeName) && currentItemName.equals(keyItemName)) {
     ServletContext context = event.getSession().getServletContext();
     context.log("Customer" + message + keyItemName + ".");
   }
 }
Beispiel #10
0
 @Override
 public void attributeReplaced(final HttpSessionBindingEvent se) {
   se.getSession()
       .getServletContext()
       .log(
           "Session Attribute replaced (session id="
               + se.getSession().getId()
               + ") "
               + se.getName()
               + "="
               + se.getValue());
 }
 /**
  * This method is invoked when an attribute is replaced in the ServletContext object
  *
  * @param event Description of the Parameter
  */
 public void attributeReplaced(HttpSessionBindingEvent event) {
   // This event has a handle to the old User object
   ServletContext context = event.getSession().getServletContext();
   // The user has logged in
   if ("User".equals(event.getName())) {
     UserBean thisUser = (UserBean) event.getValue();
     thisUser.setSessionId(event.getSession().getId());
     Tracker tracker =
         ((SystemStatus)
                 ((Hashtable) context.getAttribute("SystemStatus"))
                     .get(thisUser.getConnectionElement().getUrl()))
             .getTracker();
     tracker.remove(event.getSession().getId());
     tracker.add(thisUser.getSessionId(), thisUser);
   }
 }
 /**
  * This method is invoked when an attribute is removed from the ServletContext object
  *
  * @param se Description of the Parameter
  */
 public void attributeRemoved(HttpSessionBindingEvent se) {
   ServletContext context = se.getSession().getServletContext();
   try {
     if (se.getName().equals("User")) {
       UserBean thisUser = (UserBean) se.getValue();
       if (thisUser != null) {
         // Internal SessionManager
         int userId = thisUser.getActualUserId();
         if (userId > -2) {
           // If context reloaded, then SystemStatus is null, but user is valid
           Hashtable systems = (Hashtable) context.getAttribute("SystemStatus");
           if (systems != null) {
             SystemStatus systemStatus =
                 (SystemStatus) systems.get(thisUser.getConnectionElement().getUrl());
             if (systemStatus != null) {
               // Remove the user from the session if it already is there
               SessionManager thisManager = systemStatus.getSessionManager();
               if (thisManager != null) {
                 UserSession thisSession = thisManager.getUserSession(userId);
                 if (thisSession != null && thisSession.getId().equals(thisUser.getSessionId())) {
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> Session for user " + userId + " ended");
                   }
                   thisManager.removeUser(userId);
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> User removed from valid user list");
                   }
                 }
               }
               // Website Tracker
               Tracker tracker = systemStatus.getTracker();
               tracker.remove(thisUser.getSessionId());
             }
           }
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace(System.out);
     System.out.println("ContextSessionListener-> attributeRemoved Error: " + e.toString());
   }
 }
Beispiel #13
0
  public void attributeAdded(HttpSessionBindingEvent event) {
    // TODO Auto-generated method stub
    if (event.getName().equals("LOGIN_IP")) {
      try {
        OnlineCounter.doUser(event.getValue(), false);

        //		      List list = OnlineCounter.getOnline();
        //		    循环list
        //				for (int i = 0; i < list.size(); i++) {
        //					String[] temp = (String[])list.get(i);
        //					 System.out.println("用户"+i+":ip:"+temp[0]+"---"+temp[1]);
        //				}
        //			System.out.println("在线用户个数:"+OnlineCounter.getOnlineAllCount());

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
 /**
  * This method is invoked when an attribute is added to the ServletContext object
  *
  * @param event Description of the Parameter
  */
 public void attributeAdded(HttpSessionBindingEvent event) {
   ServletContext context = event.getSession().getServletContext();
   if ("User".equals(event.getName())) {
     // A user session has been created, can be a portal user or system user
     UserBean thisUser = (UserBean) event.getValue();
     thisUser.setSessionId(event.getSession().getId());
     // Track website users
     Hashtable systems = (Hashtable) context.getAttribute("SystemStatus");
     if (systems != null && thisUser.getConnectionElement() != null) {
       SystemStatus systemStatus =
           (SystemStatus) systems.get(thisUser.getConnectionElement().getUrl());
       if (systemStatus != null) {
         Tracker tracker =
             ((SystemStatus)
                     ((Hashtable) context.getAttribute("SystemStatus"))
                         .get(thisUser.getConnectionElement().getUrl()))
                 .getTracker();
         tracker.add(thisUser.getSessionId(), thisUser);
       }
     }
   }
 }
 @Override
 public void attributeReplaced(HttpSessionBindingEvent event) {
   event.getSession().getServletContext().removeAttribute(event.getName());
   event.getSession().getServletContext().setAttribute(event.getName(), event.getValue());
 }
 @Override
 public void attributeReplaced(HttpSessionBindingEvent event) {
   log.debug("Session attribute replaced: " + event.getName() + ":" + event.getValue());
 }