Ejemplo n.º 1
0
 /**
  * 退出登陆
  *
  * @param sessionId
  */
 public void logout(String sessionId) {
   // 更新用户登录日志中会话的退出时间
   UserSessionContext userSessionContext =
       UserSessionContextManager.createInstance().getUserSessionContext(sessionId);
   if (userSessionContext == null) {
     return;
   }
   SysUser user = userSessionContext.getSysUser();
   if (user != null) {
     // 清除用户缓存
     UserSessionContextManager.createInstance().removeUserSessionContext(user.getSessionId());
   }
 }
Ejemplo n.º 2
0
  /**
   * 为用户创建会话
   *
   * @param logonUser
   * @param user
   */
  public void buildUserSession(LogonUser logonUser, SysUser user) {
    UserSessionContext userSessionContext = new UserSessionContext();

    // 生成一个sessionId
    String sessionId = CodeGenerator.getUUID();
    String token = UserSessionContext.getSessionToken(sessionId, logonUser.getIp());

    userSessionContext.setLastRequestTime(System.currentTimeMillis());
    userSessionContext.setLogonIp(logonUser.getIp());
    userSessionContext.setLogonTime(DateUtils.getCurrTimeStrOfStoreFormat());
    userSessionContext.setToken(token);

    user.setLastLogonIp(userSessionContext.getLogonIp());
    user.setSessionId(sessionId);

    updateByIdSelective(user);

    userSessionContext.setSysUser(user);
    // 将登录后的用户信息放到二级缓存里面去
    UserSessionContextManager.createInstance().putIntoCache(userSessionContext);

    // 将用户会话绑定到线程中
    UserSessionContextHolder.mountUserSessionContext(userSessionContext);
  }