|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.securechannel; |
|
17 |
| |
|
18 |
| import org.acegisecurity.ConfigAttribute; |
|
19 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
20 |
| import org.acegisecurity.intercept.web.FilterInvocation; |
|
21 |
| |
|
22 |
| import org.springframework.beans.factory.InitializingBean; |
|
23 |
| import org.springframework.util.Assert; |
|
24 |
| |
|
25 |
| import java.io.IOException; |
|
26 |
| |
|
27 |
| import java.util.Iterator; |
|
28 |
| |
|
29 |
| import javax.servlet.ServletException; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public class SecureChannelProcessor implements InitializingBean, |
|
55 |
| ChannelProcessor { |
|
56 |
| |
|
57 |
| |
|
58 |
| private ChannelEntryPoint entryPoint = new RetryWithHttpsEntryPoint(); |
|
59 |
| private String secureKeyword = "REQUIRES_SECURE_CHANNEL"; |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
2
| public void setEntryPoint(ChannelEntryPoint entryPoint) {
|
|
64 |
2
| this.entryPoint = entryPoint;
|
|
65 |
| } |
|
66 |
| |
|
67 |
2
| public ChannelEntryPoint getEntryPoint() {
|
|
68 |
2
| return entryPoint;
|
|
69 |
| } |
|
70 |
| |
|
71 |
3
| public void setSecureKeyword(String secureKeyword) {
|
|
72 |
3
| this.secureKeyword = secureKeyword;
|
|
73 |
| } |
|
74 |
| |
|
75 |
8
| public String getSecureKeyword() {
|
|
76 |
8
| return secureKeyword;
|
|
77 |
| } |
|
78 |
| |
|
79 |
4
| public void afterPropertiesSet() throws Exception {
|
|
80 |
4
| Assert.hasLength(secureKeyword, "secureKeyword required");
|
|
81 |
2
| Assert.notNull(entryPoint, "entryPoint required");
|
|
82 |
| } |
|
83 |
| |
|
84 |
3
| public void decide(FilterInvocation invocation,
|
|
85 |
| ConfigAttributeDefinition config) throws IOException, ServletException { |
|
86 |
3
| Assert.isTrue((invocation != null) && (config != null), "Nulls cannot be provided");
|
|
87 |
| |
|
88 |
2
| Iterator iter = config.getConfigAttributes();
|
|
89 |
| |
|
90 |
2
| while (iter.hasNext()) {
|
|
91 |
4
| ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
|
92 |
| |
|
93 |
4
| if (supports(attribute)) {
|
|
94 |
2
| if (!invocation.getHttpRequest().isSecure()) {
|
|
95 |
1
| entryPoint.commence(invocation.getRequest(),
|
|
96 |
| invocation.getResponse()); |
|
97 |
| } |
|
98 |
| } |
|
99 |
| } |
|
100 |
| } |
|
101 |
| |
|
102 |
7
| public boolean supports(ConfigAttribute attribute) {
|
|
103 |
7
| if ((attribute != null) && (attribute.getAttribute() != null)
|
|
104 |
| && attribute.getAttribute().equals(getSecureKeyword())) { |
|
105 |
3
| return true;
|
|
106 |
| } else { |
|
107 |
4
| return false;
|
|
108 |
| } |
|
109 |
| } |
|
110 |
| } |