Skip to content

Commit

Permalink
shiro教程-第十八章
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkaitao committed Feb 19, 2014
1 parent 6ca2813 commit b49321b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected boolean isAccessAllowed(ServletRequest request, ServletResponse respon
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
Subject subject = getSubject(request, response);
if(!subject.isAuthenticated() && !subject.isRemembered()) {
//如果没有登录,直接进行之后的流程
return true;
}

Expand All @@ -72,26 +73,30 @@ protected boolean onAccessDenied(ServletRequest request, ServletResponse respons
cache.put(username, deque);
}

//如果队列里没有此sessionId,且用户没有被踢出;放入队列
if(!deque.contains(sessionId) && session.getAttribute("kickout") == null) {
deque.push(sessionId);
}

//如果队列里的sessionId数超出最大会话数,开始踢人
while(deque.size() > maxSession) {
Serializable kickoutSessionId = null;
if(kickoutAfter) {
if(kickoutAfter) { //如果踢出后者
kickoutSessionId = deque.removeFirst();
} else {
} else { //否则踢出前者
kickoutSessionId = deque.removeLast();
}
try {
Session kickoutSession = sessionManager.getSession(new DefaultSessionKey(kickoutSessionId));
if(kickoutSession != null) {
//设置会话的kickout属性表示踢出了
kickoutSession.setAttribute("kickout", true);
}
} catch (Exception e) {//ignore exception
}
}

//如果被踢出了,直接退出,重定向到踢出后的地址
if (session.getAttribute("kickout") != null) {
//会话被踢出了
try {
Expand Down

0 comments on commit b49321b

Please sign in to comment.