|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.adapters; |
|
17 |
| |
|
18 |
| import org.acegisecurity.Authentication; |
|
19 |
| import org.acegisecurity.context.SecurityContextHolder; |
|
20 |
| |
|
21 |
| import org.apache.commons.logging.Log; |
|
22 |
| import org.apache.commons.logging.LogFactory; |
|
23 |
| |
|
24 |
| import java.io.IOException; |
|
25 |
| |
|
26 |
| import java.security.Principal; |
|
27 |
| |
|
28 |
| import javax.servlet.Filter; |
|
29 |
| import javax.servlet.FilterChain; |
|
30 |
| import javax.servlet.FilterConfig; |
|
31 |
| import javax.servlet.ServletException; |
|
32 |
| import javax.servlet.ServletRequest; |
|
33 |
| import javax.servlet.ServletResponse; |
|
34 |
| import javax.servlet.http.HttpServletRequest; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| public class HttpRequestIntegrationFilter implements Filter { |
|
60 |
| |
|
61 |
| |
|
62 |
| private static final Log logger = LogFactory.getLog(HttpRequestIntegrationFilter.class); |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
0
| public void destroy() {}
|
|
70 |
| |
|
71 |
3
| public void doFilter(ServletRequest request, ServletResponse response,
|
|
72 |
| FilterChain chain) throws IOException, ServletException { |
|
73 |
3
| if (request instanceof HttpServletRequest) {
|
|
74 |
2
| Principal principal = ((HttpServletRequest) request)
|
|
75 |
| .getUserPrincipal(); |
|
76 |
| |
|
77 |
2
| if ((principal != null) && principal instanceof Authentication) {
|
|
78 |
1
| SecurityContextHolder.getContext().setAuthentication((Authentication) principal);
|
|
79 |
| |
|
80 |
1
| if (logger.isDebugEnabled()) {
|
|
81 |
0
| logger.debug(
|
|
82 |
| "SecurityContextHolder updated with Authentication from container: '" |
|
83 |
| + principal + "'"); |
|
84 |
| } |
|
85 |
| } else { |
|
86 |
1
| if (logger.isDebugEnabled()) {
|
|
87 |
0
| logger.debug(
|
|
88 |
| "SecurityContextHolder not set with new Authentication as Principal was: '" |
|
89 |
| + principal + "'"); |
|
90 |
| } |
|
91 |
| } |
|
92 |
| } else { |
|
93 |
1
| throw new IllegalArgumentException(
|
|
94 |
| "Only HttpServletRequest is acceptable"); |
|
95 |
| } |
|
96 |
| |
|
97 |
2
| chain.doFilter(request, response);
|
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
0
| public void init(FilterConfig arg0) throws ServletException {}
|
|
108 |
| } |