Package org.beangle.security.core.session

Examples of org.beangle.security.core.session.Sessioninfo


  @Override
  protected void doFilterHttp(HttpServletRequest request, HttpServletResponse response,
      FilterChain chain) throws IOException, ServletException {
    HttpSession session = request.getSession(false);
    if (session != null) {
      SessionInfo info = sessionRegistry.getSessionInfo(session.getId());
      if (info != null) {
        if (info.isExpired()) {
          // Expired - abort processing
          doLogout(request, response);
          String targetUrl = determineExpiredUrl(request, info);
          if (targetUrl != null) {
            RedirectUtils.sendRedirect(request, response, targetUrl);
            return;
          } else {
            response.getWriter().print(
                "This session has been expired (possibly due to multiple concurrent "
                    + "logins being attempted as the same user).");
            response.flushBuffer();
          }
          return;
        } else {
          // Non-expired - update last request date/time
          info.refreshLastRequest();
        }
      }
    }

    chain.doFilter(request, response);
View Full Code Here


  public SessionInfo getSessionInfo(String sessionId) {
    return null;
  }

  public void refreshLastRequest(String sessionId) {
    SessionInfo info = getSessionInfo(sessionId);
    if (info != null) {
      info.refreshLastRequest();
    }
  }
View Full Code Here

  protected void allowableSessionsExceeded(String sessionId, List<SessionInfo> sessions,
      int allowableSessions, SessionRegistry registry) throws SessionException {
    if (exceptionIfMaximumExceeded || (sessions == null)) { throw new SessionException(
        "over max online sessions "); }
    // Determine least recently used session, and mark it for invalidation
    SessionInfo leastRecentlyUsed = null;
    for (int i = 0; i < sessions.size(); i++) {
      if ((leastRecentlyUsed == null)
          || sessions.get(i).getLastAccessAt()
              .before(leastRecentlyUsed.getLastAccessAt())) {
        leastRecentlyUsed = (SessionInfo) sessions.get(i);
      }
    }

    leastRecentlyUsed.expireNow();
  }
View Full Code Here

  /**
   * 注册用户
   */
  public void register(String sessionId, Authentication auth) {
    CategoryPrincipal principal = (CategoryPrincipal) auth.getPrincipal();
    SessionInfo existed = innerRegistry.getSessionInfo(sessionId);
    // 原先没有的要占座
    if (null == existed && !sessionController.reserve(principal.getCategory(), sessionId)) {
      throw new SessionException("over max " + sessionController.getMax());
    } else {
      innerRegistry.register(sessionId, auth);
View Full Code Here

      innerRegistry.register(sessionId, auth);
    }
  }

  public SessionInfo remove(String sessionId) {
    SessionInfo info = innerRegistry.remove(sessionId);
    if (null != info) {
      sessionController.left(categoryPrincipal(info).getCategory());
    }
    return info;
  }
View Full Code Here

  public Sessioninfo remove(String sessionId) {
    return remove(sessionId, null);
  }

  private Sessioninfo remove(String sessionId, String reason) {
    Sessioninfo info = getSessioninfo(sessionId);
    if (null == info) {
      return null;
    } else {
      // FIXME not in a transcation
      if (null != reason) info.addRemark(reason);
      entityDao.remove(info);
      controller.onLogout(info);
      entries.remove(info.getId());
      Object sessioninfoLog = sessioninfoBuilder.buildLog(info);
      if (null != sessioninfoLog) {
        entityDao.save(sessioninfoLog);
      }
      logger.debug("Remove session {} for {}", sessionId, info.getUsername());
      return info;
    }
  }
View Full Code Here

      return info;
    }
  }

  public void expire(String sessionId) {
    Sessioninfo info = getSessioninfo(sessionId);
    if (null != info) {
      controller.onLogout(info);
      info.expireNow();
      entityDao.saveOrUpdate(info);
    }
  }
View Full Code Here

    Set<String> sessionsUsedByPrincipal = principals.get(principal);
    List<Sessioninfo> list = CollectUtils.newArrayList();
    if (null == sessionsUsedByPrincipal) { return list; }
    synchronized (sessionsUsedByPrincipal) {
      for (final String sessionid : sessionsUsedByPrincipal) {
        Sessioninfo info = getSessioninfo(sessionid);
        if (info == null) {
          continue;
        }
        if (includeExpiredSessions || !info.isExpired()) {
          list.add(info);
        }
      }
    }
View Full Code Here

  public Sessioninfo getSessioninfo(String sessionid) {
    return sessionids.get(sessionid);
  }

  public void register(Authentication auth, String sessionid) throws SessionException {
    Sessioninfo existed = getSessioninfo(sessionid);
    String principal = auth.getName();
    // 是否为重复注册
    if (null != existed && ObjectUtils.equals(existed.getUsername(), principal)) return;
    // 争取名额
    boolean success = controller.onRegister(auth, sessionid, this);
    if (!success) throw new SessionException("security.OvermaxSession");
    // 注销同会话的其它账户
    if (null != existed) {
      existed.addRemark(" expired with replacement.");
      remove(sessionid);
    }
    // 新生
    sessionids.put(sessionid, sessioninfoBuilder.build(auth, controller.getServerName(), sessionid));
    Set<String> sessionsUsedByPrincipal = principals.get(principal);
View Full Code Here

    }
    sessionsUsedByPrincipal.add(sessionid);
  }

  public Sessioninfo remove(String sessionid) {
    Sessioninfo info = getSessioninfo(sessionid);
    if (null == info) { return null; }
    sessionids.remove(sessionid);
    String principal = info.getUsername();
    logger.debug("Remove session {} for {}", sessionid, principal);
    Set<String> sessionsUsedByPrincipal = principals.get(principal);
    if (null != sessionsUsedByPrincipal) {
      synchronized (sessionsUsedByPrincipal) {
        sessionsUsedByPrincipal.remove(sessionid);
View Full Code Here

TOP

Related Classes of org.beangle.security.core.session.Sessioninfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.