|
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 |
| |
|
55 |
| public class InsecureChannelProcessor implements InitializingBean, |
|
56 |
| ChannelProcessor { |
|
57 |
| |
|
58 |
| |
|
59 |
| private ChannelEntryPoint entryPoint = new RetryWithHttpEntryPoint(); |
|
60 |
| private String insecureKeyword = "REQUIRES_INSECURE_CHANNEL"; |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
2
| public void setEntryPoint(ChannelEntryPoint entryPoint) {
|
|
65 |
2
| this.entryPoint = entryPoint;
|
|
66 |
| } |
|
67 |
| |
|
68 |
2
| public ChannelEntryPoint getEntryPoint() {
|
|
69 |
2
| return entryPoint;
|
|
70 |
| } |
|
71 |
| |
|
72 |
3
| public void setInsecureKeyword(String secureKeyword) {
|
|
73 |
3
| this.insecureKeyword = secureKeyword;
|
|
74 |
| } |
|
75 |
| |
|
76 |
8
| public String getInsecureKeyword() {
|
|
77 |
8
| return insecureKeyword;
|
|
78 |
| } |
|
79 |
| |
|
80 |
4
| public void afterPropertiesSet() throws Exception {
|
|
81 |
4
| Assert.hasLength(insecureKeyword, "insecureKeyword required");
|
|
82 |
2
| Assert.notNull(entryPoint, "entryPoint required");
|
|
83 |
| } |
|
84 |
| |
|
85 |
3
| public void decide(FilterInvocation invocation,
|
|
86 |
| ConfigAttributeDefinition config) throws IOException, ServletException { |
|
87 |
3
| if ((invocation == null) || (config == null)) {
|
|
88 |
1
| throw new IllegalArgumentException("Nulls cannot be provided");
|
|
89 |
| } |
|
90 |
| |
|
91 |
2
| Iterator iter = config.getConfigAttributes();
|
|
92 |
| |
|
93 |
2
| while (iter.hasNext()) {
|
|
94 |
4
| ConfigAttribute attribute = (ConfigAttribute) iter.next();
|
|
95 |
| |
|
96 |
4
| if (supports(attribute)) {
|
|
97 |
2
| if (invocation.getHttpRequest().isSecure()) {
|
|
98 |
1
| entryPoint.commence(invocation.getRequest(),
|
|
99 |
| invocation.getResponse()); |
|
100 |
| } |
|
101 |
| } |
|
102 |
| } |
|
103 |
| } |
|
104 |
| |
|
105 |
7
| public boolean supports(ConfigAttribute attribute) {
|
|
106 |
7
| if ((attribute != null) && (attribute.getAttribute() != null)
|
|
107 |
| && attribute.getAttribute().equals(getInsecureKeyword())) { |
|
108 |
3
| return true;
|
|
109 |
| } else { |
|
110 |
4
| return false;
|
|
111 |
| } |
|
112 |
| } |
|
113 |
| } |