|
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 |
| |
|
24 |
| import java.io.IOException; |
|
25 |
| |
|
26 |
| import java.util.Iterator; |
|
27 |
| import java.util.List; |
|
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 |
| public class ChannelDecisionManagerImpl implements ChannelDecisionManager, |
|
52 |
| InitializingBean { |
|
53 |
| |
|
54 |
| |
|
55 |
| private List channelProcessors; |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
7
| public void setChannelProcessors(List newList) {
|
|
60 |
7
| checkIfValidList(newList);
|
|
61 |
| |
|
62 |
5
| Iterator iter = newList.iterator();
|
|
63 |
| |
|
64 |
5
| while (iter.hasNext()) {
|
|
65 |
9
| Object currentObject = null;
|
|
66 |
| |
|
67 |
9
| try {
|
|
68 |
9
| currentObject = iter.next();
|
|
69 |
| |
|
70 |
9
| ChannelProcessor attemptToCast = (ChannelProcessor) currentObject;
|
|
71 |
| } catch (ClassCastException cce) { |
|
72 |
1
| throw new IllegalArgumentException("ChannelProcessor "
|
|
73 |
| + currentObject.getClass().getName() |
|
74 |
| + " must implement ChannelProcessor"); |
|
75 |
| } |
|
76 |
| } |
|
77 |
| |
|
78 |
4
| this.channelProcessors = newList;
|
|
79 |
| } |
|
80 |
| |
|
81 |
2
| public List getChannelProcessors() {
|
|
82 |
2
| return this.channelProcessors;
|
|
83 |
| } |
|
84 |
| |
|
85 |
4
| public void afterPropertiesSet() throws Exception {
|
|
86 |
4
| checkIfValidList(this.channelProcessors);
|
|
87 |
| } |
|
88 |
| |
|
89 |
2
| public void decide(FilterInvocation invocation,
|
|
90 |
| ConfigAttributeDefinition config) throws IOException, ServletException { |
|
91 |
2
| Iterator iter = this.channelProcessors.iterator();
|
|
92 |
| |
|
93 |
2
| while (iter.hasNext()) {
|
|
94 |
3
| ChannelProcessor processor = (ChannelProcessor) iter.next();
|
|
95 |
| |
|
96 |
3
| processor.decide(invocation, config);
|
|
97 |
| |
|
98 |
3
| if (invocation.getResponse().isCommitted()) {
|
|
99 |
1
| break;
|
|
100 |
| } |
|
101 |
| } |
|
102 |
| } |
|
103 |
| |
|
104 |
3
| public boolean supports(ConfigAttribute attribute) {
|
|
105 |
3
| Iterator iter = this.channelProcessors.iterator();
|
|
106 |
| |
|
107 |
3
| while (iter.hasNext()) {
|
|
108 |
5
| ChannelProcessor processor = (ChannelProcessor) iter.next();
|
|
109 |
| |
|
110 |
5
| if (processor.supports(attribute)) {
|
|
111 |
2
| return true;
|
|
112 |
| } |
|
113 |
| } |
|
114 |
| |
|
115 |
1
| return false;
|
|
116 |
| } |
|
117 |
| |
|
118 |
11
| private void checkIfValidList(List listToCheck) {
|
|
119 |
11
| if ((listToCheck == null) || (listToCheck.size() == 0)) {
|
|
120 |
3
| throw new IllegalArgumentException(
|
|
121 |
| "A list of ChannelProcessors is required"); |
|
122 |
| } |
|
123 |
| } |
|
124 |
| } |