|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.afterinvocation; |
|
17 |
| |
|
18 |
| import org.acegisecurity.AccessDeniedException; |
|
19 |
| import org.acegisecurity.AfterInvocationManager; |
|
20 |
| import org.acegisecurity.Authentication; |
|
21 |
| import org.acegisecurity.ConfigAttribute; |
|
22 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
23 |
| |
|
24 |
| import org.apache.commons.logging.Log; |
|
25 |
| import org.apache.commons.logging.LogFactory; |
|
26 |
| |
|
27 |
| import org.springframework.beans.factory.InitializingBean; |
|
28 |
| |
|
29 |
| import java.util.Iterator; |
|
30 |
| import java.util.List; |
|
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 AfterInvocationProviderManager implements AfterInvocationManager, |
|
56 |
| InitializingBean { |
|
57 |
| |
|
58 |
| |
|
59 |
| protected static final Log logger = LogFactory.getLog(AfterInvocationProviderManager.class); |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| private List providers; |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
5
| public void setProviders(List newList) {
|
|
68 |
5
| checkIfValidList(newList);
|
|
69 |
| |
|
70 |
4
| Iterator iter = newList.iterator();
|
|
71 |
| |
|
72 |
4
| while (iter.hasNext()) {
|
|
73 |
11
| Object currentObject = null;
|
|
74 |
| |
|
75 |
11
| try {
|
|
76 |
11
| currentObject = iter.next();
|
|
77 |
| |
|
78 |
11
| AfterInvocationProvider attemptToCast = (AfterInvocationProvider) currentObject;
|
|
79 |
| } catch (ClassCastException cce) { |
|
80 |
1
| throw new IllegalArgumentException("AfterInvocationProvider "
|
|
81 |
| + currentObject.getClass().getName() |
|
82 |
| + " must implement AfterInvocationProvider"); |
|
83 |
| } |
|
84 |
| } |
|
85 |
| |
|
86 |
3
| this.providers = newList;
|
|
87 |
| } |
|
88 |
| |
|
89 |
1
| public List getProviders() {
|
|
90 |
1
| return this.providers;
|
|
91 |
| } |
|
92 |
| |
|
93 |
4
| public void afterPropertiesSet() throws Exception {
|
|
94 |
4
| checkIfValidList(this.providers);
|
|
95 |
| } |
|
96 |
| |
|
97 |
5
| public Object decide(Authentication authentication, Object object,
|
|
98 |
| ConfigAttributeDefinition config, Object returnedObject) |
|
99 |
| throws AccessDeniedException { |
|
100 |
5
| Iterator iter = this.providers.iterator();
|
|
101 |
| |
|
102 |
5
| Object result = returnedObject;
|
|
103 |
| |
|
104 |
5
| while (iter.hasNext()) {
|
|
105 |
15
| AfterInvocationProvider provider = (AfterInvocationProvider) iter
|
|
106 |
| .next(); |
|
107 |
15
| result = provider.decide(authentication, object, config, result);
|
|
108 |
| } |
|
109 |
| |
|
110 |
5
| return result;
|
|
111 |
| } |
|
112 |
| |
|
113 |
2
| public boolean supports(ConfigAttribute attribute) {
|
|
114 |
2
| Iterator iter = this.providers.iterator();
|
|
115 |
| |
|
116 |
2
| while (iter.hasNext()) {
|
|
117 |
5
| AfterInvocationProvider provider = (AfterInvocationProvider) iter
|
|
118 |
| .next(); |
|
119 |
| |
|
120 |
5
| if (logger.isDebugEnabled()) {
|
|
121 |
0
| logger.debug("Evaluating " + attribute + " against " + provider);
|
|
122 |
| } |
|
123 |
| |
|
124 |
5
| if (provider.supports(attribute)) {
|
|
125 |
1
| return true;
|
|
126 |
| } |
|
127 |
| } |
|
128 |
| |
|
129 |
1
| return false;
|
|
130 |
| } |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
2
| public boolean supports(Class clazz) {
|
|
149 |
2
| Iterator iter = this.providers.iterator();
|
|
150 |
| |
|
151 |
2
| while (iter.hasNext()) {
|
|
152 |
4
| AfterInvocationProvider provider = (AfterInvocationProvider) iter
|
|
153 |
| .next(); |
|
154 |
| |
|
155 |
4
| if (!provider.supports(clazz)) {
|
|
156 |
1
| return false;
|
|
157 |
| } |
|
158 |
| } |
|
159 |
| |
|
160 |
1
| return true;
|
|
161 |
| } |
|
162 |
| |
|
163 |
9
| private void checkIfValidList(List listToCheck) {
|
|
164 |
9
| if ((listToCheck == null) || (listToCheck.size() == 0)) {
|
|
165 |
2
| throw new IllegalArgumentException(
|
|
166 |
| "A list of AfterInvocationProviders is required"); |
|
167 |
| } |
|
168 |
| } |
|
169 |
| } |