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