|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.concurrent; |
|
17 |
| |
|
18 |
| import org.springframework.beans.factory.InitializingBean; |
|
19 |
| |
|
20 |
| import org.springframework.util.Assert; |
|
21 |
| |
|
22 |
| import java.io.IOException; |
|
23 |
| |
|
24 |
| import javax.servlet.Filter; |
|
25 |
| import javax.servlet.FilterChain; |
|
26 |
| import javax.servlet.FilterConfig; |
|
27 |
| import javax.servlet.ServletException; |
|
28 |
| import javax.servlet.ServletRequest; |
|
29 |
| import javax.servlet.ServletResponse; |
|
30 |
| import javax.servlet.http.HttpServletRequest; |
|
31 |
| import javax.servlet.http.HttpServletResponse; |
|
32 |
| import javax.servlet.http.HttpSession; |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class ConcurrentSessionFilter implements Filter, |
|
57 |
| InitializingBean { |
|
58 |
| |
|
59 |
| |
|
60 |
| private SessionRegistry sessionRegistry; |
|
61 |
| private String expiredUrl; |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
3
| public void setExpiredUrl(String expiredUrl) {
|
|
66 |
3
| this.expiredUrl = expiredUrl;
|
|
67 |
| } |
|
68 |
| |
|
69 |
3
| public void setSessionRegistry(SessionRegistry sessionRegistry) {
|
|
70 |
3
| this.sessionRegistry = sessionRegistry;
|
|
71 |
| } |
|
72 |
| |
|
73 |
2
| public void afterPropertiesSet() throws Exception {
|
|
74 |
2
| Assert.notNull(sessionRegistry, "SessionRegistry required");
|
|
75 |
1
| Assert.hasText(expiredUrl, "ExpiredUrl required");
|
|
76 |
| } |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
2
| public void destroy() {}
|
|
82 |
| |
|
83 |
2
| public void doFilter(ServletRequest request, ServletResponse response,
|
|
84 |
| FilterChain chain) throws IOException, ServletException { |
|
85 |
2
| Assert.isInstanceOf(HttpServletRequest.class, request,
|
|
86 |
| "Can only process HttpServletRequest"); |
|
87 |
2
| Assert.isInstanceOf(HttpServletResponse.class, response,
|
|
88 |
| "Can only process HttpServletResponse"); |
|
89 |
| |
|
90 |
2
| HttpServletRequest httpRequest = (HttpServletRequest) request;
|
|
91 |
2
| HttpServletResponse httpResponse = (HttpServletResponse) response;
|
|
92 |
| |
|
93 |
2
| HttpSession session = httpRequest.getSession(false);
|
|
94 |
| |
|
95 |
2
| if (session != null) {
|
|
96 |
2
| SessionInformation info = sessionRegistry.getSessionInformation(session
|
|
97 |
| .getId()); |
|
98 |
| |
|
99 |
2
| if (info != null) {
|
|
100 |
2
| if (info.isExpired()) {
|
|
101 |
| |
|
102 |
1
| session.invalidate();
|
|
103 |
| |
|
104 |
1
| String targetUrl = httpRequest.getContextPath()
|
|
105 |
| + expiredUrl; |
|
106 |
1
| httpResponse.sendRedirect(httpResponse.encodeRedirectURL(
|
|
107 |
| targetUrl)); |
|
108 |
| |
|
109 |
1
| return;
|
|
110 |
| } else { |
|
111 |
| |
|
112 |
1
| info.refreshLastRequest();
|
|
113 |
| } |
|
114 |
| } |
|
115 |
| } |
|
116 |
| |
|
117 |
1
| chain.doFilter(request, response);
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
2
| public void init(FilterConfig arg0) throws ServletException {}
|
|
128 |
| } |