예제 #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() + "个用户已登录");
      }
    }
  }
예제 #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 ******************************** */
  }
예제 #3
0
 /**
  * 取指定用户的session
  *
  * @param userLoginID 用户登陆账号
  * @return 用户未登录,返回null
  */
 public static HttpSession getThisUserSession(String userLoginID) {
   HttpSession ret = null;
   for (LoginUserVO userSrc : onlineUsers.values()) {
     if (userSrc.getUserloginid().equals(userLoginID)) {
       ret = userSrc.getSession();
       break;
     }
   }
   return ret;
 }
예제 #4
0
  /**
   * 返回在线人员列表数据,注意返回的是克隆出来的新集合,对它的修改不会影响到原集合
   *
   * @return 克隆出来的新集合
   * @throws IllegalAccessException
   * @throws InstantiationException
   * @throws InvocationTargetException
   * @throws NoSuchMethodException
   */
  public static List<LoginUserVO> getOnlineUsers()
      throws IllegalAccessException, InstantiationException, InvocationTargetException,
          NoSuchMethodException {
    List<LoginUserVO> newMap = new ArrayList<LoginUserVO>(onlineUsers.size());
    for (LoginUserVO userSrc : onlineUsers.values()) {
      TSysDepart newDepart = new TSysDepart();
      TSysDepart srcDepart = userSrc.getDepart();
      BeanUtils.copyProperties(newDepart, srcDepart);

      LoginUserVO newUser = new LoginUserVO();
      BeanUtils.copyProperties(newUser, userSrc);

      newUser.setDepart(newDepart);
      newMap.add(newUser);
    }
    return newMap;
  }