|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.afterinvocation; |
|
17 |
| |
|
18 |
| import java.util.Iterator; |
|
19 |
| |
|
20 |
| import org.acegisecurity.AccessDeniedException; |
|
21 |
| import org.acegisecurity.AcegiMessageSource; |
|
22 |
| import org.acegisecurity.Authentication; |
|
23 |
| import org.acegisecurity.ConfigAttribute; |
|
24 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
25 |
| import org.acegisecurity.acl.AclEntry; |
|
26 |
| import org.acegisecurity.acl.AclManager; |
|
27 |
| import org.acegisecurity.acl.basic.BasicAclEntry; |
|
28 |
| import org.acegisecurity.acl.basic.SimpleAclEntry; |
|
29 |
| import org.apache.commons.logging.Log; |
|
30 |
| import org.apache.commons.logging.LogFactory; |
|
31 |
| import org.springframework.beans.factory.InitializingBean; |
|
32 |
| import org.springframework.context.MessageSource; |
|
33 |
| import org.springframework.context.MessageSourceAware; |
|
34 |
| import org.springframework.context.support.MessageSourceAccessor; |
|
35 |
| import org.springframework.util.Assert; |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| public class BasicAclEntryAfterInvocationProvider |
|
92 |
| implements AfterInvocationProvider, InitializingBean, MessageSourceAware { |
|
93 |
| |
|
94 |
| |
|
95 |
| protected static final Log logger = LogFactory.getLog(BasicAclEntryAfterInvocationProvider.class); |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| private AclManager aclManager; |
|
100 |
| protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor(); |
|
101 |
| private String processConfigAttribute = "AFTER_ACL_READ"; |
|
102 |
| private int[] requirePermission = {SimpleAclEntry.READ}; |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
9
| public void afterPropertiesSet() throws Exception {
|
|
107 |
9
| Assert.notNull(processConfigAttribute,
|
|
108 |
| "A processConfigAttribute is mandatory"); |
|
109 |
8
| Assert.notNull(aclManager, "An aclManager is mandatory");
|
|
110 |
7
| Assert.notNull(messages, "A message source must be set");
|
|
111 |
| |
|
112 |
7
| if ((requirePermission == null) || (requirePermission.length == 0)) {
|
|
113 |
1
| throw new IllegalArgumentException(
|
|
114 |
| "One or more requirePermission entries is mandatory"); |
|
115 |
| } |
|
116 |
| } |
|
117 |
| |
|
118 |
7
| public Object decide(Authentication authentication, Object object,
|
|
119 |
| ConfigAttributeDefinition config, Object returnedObject) |
|
120 |
| throws AccessDeniedException { |
|
121 |
7
| Iterator iter = config.getConfigAttributes();
|
|
122 |
| |
|
123 |
7
| while (iter.hasNext()) {
|
|
124 |
8
| ConfigAttribute attr = (ConfigAttribute) iter.next();
|
|
125 |
| |
|
126 |
8
| if (this.supports(attr)) {
|
|
127 |
| |
|
128 |
6
| if (returnedObject == null) {
|
|
129 |
| |
|
130 |
| |
|
131 |
1
| if (logger.isDebugEnabled()) {
|
|
132 |
0
| logger.debug("Return object is null, skipping");
|
|
133 |
| } |
|
134 |
| |
|
135 |
1
| return null;
|
|
136 |
| } |
|
137 |
| |
|
138 |
5
| AclEntry[] acls = aclManager.getAcls(returnedObject,
|
|
139 |
| authentication); |
|
140 |
| |
|
141 |
5
| if ((acls == null) || (acls.length == 0)) {
|
|
142 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
143 |
| "BasicAclEntryAfterInvocationProvider.noPermission", |
|
144 |
| new Object[] {authentication.getName(), returnedObject}, |
|
145 |
| "Authentication {0} has NO permissions at all to the domain object {1}")); |
|
146 |
| } |
|
147 |
| |
|
148 |
4
| for (int i = 0; i < acls.length; i++) {
|
|
149 |
| |
|
150 |
6
| if (acls[i] instanceof BasicAclEntry) {
|
|
151 |
5
| BasicAclEntry processableAcl = (BasicAclEntry) acls[i];
|
|
152 |
| |
|
153 |
| |
|
154 |
5
| for (int y = 0; y < requirePermission.length; y++) {
|
|
155 |
5
| if (processableAcl.isPermitted(requirePermission[y])) {
|
|
156 |
3
| if (logger.isDebugEnabled()) {
|
|
157 |
0
| logger.debug(
|
|
158 |
| "Principal DOES have permission to return object: " |
|
159 |
| + returnedObject + " due to ACL: " |
|
160 |
| + processableAcl.toString()); |
|
161 |
| } |
|
162 |
| |
|
163 |
3
| return returnedObject;
|
|
164 |
| } |
|
165 |
| } |
|
166 |
| } |
|
167 |
| } |
|
168 |
| |
|
169 |
| |
|
170 |
1
| throw new AccessDeniedException(messages.getMessage(
|
|
171 |
| "BasicAclEntryAfterInvocationProvider.insufficientPermission", |
|
172 |
| new Object[] {authentication.getName(), returnedObject}, |
|
173 |
| "Authentication {0} has ACL permissions to the domain object, but not the required ACL permission to the domain object {1}")); |
|
174 |
| } |
|
175 |
| } |
|
176 |
| |
|
177 |
1
| return returnedObject;
|
|
178 |
| } |
|
179 |
| |
|
180 |
1
| public AclManager getAclManager() {
|
|
181 |
1
| return aclManager;
|
|
182 |
| } |
|
183 |
| |
|
184 |
10
| public String getProcessConfigAttribute() {
|
|
185 |
10
| return processConfigAttribute;
|
|
186 |
| } |
|
187 |
| |
|
188 |
2
| public int[] getRequirePermission() {
|
|
189 |
2
| return requirePermission;
|
|
190 |
| } |
|
191 |
| |
|
192 |
8
| public void setAclManager(AclManager aclManager) {
|
|
193 |
8
| this.aclManager = aclManager;
|
|
194 |
| } |
|
195 |
| |
|
196 |
0
| public void setMessageSource(MessageSource messageSource) {
|
|
197 |
0
| this.messages = new MessageSourceAccessor(messageSource);
|
|
198 |
| } |
|
199 |
| |
|
200 |
2
| public void setProcessConfigAttribute(String processConfigAttribute) {
|
|
201 |
2
| this.processConfigAttribute = processConfigAttribute;
|
|
202 |
| } |
|
203 |
| |
|
204 |
2
| public void setRequirePermission(int[] requirePermission) {
|
|
205 |
2
| this.requirePermission = requirePermission;
|
|
206 |
| } |
|
207 |
| |
|
208 |
8
| public boolean supports(ConfigAttribute attribute) {
|
|
209 |
8
| if ((attribute.getAttribute() != null)
|
|
210 |
| && attribute.getAttribute().equals(getProcessConfigAttribute())) { |
|
211 |
6
| return true;
|
|
212 |
| } else { |
|
213 |
2
| return false;
|
|
214 |
| } |
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
1
| public boolean supports(Class clazz) {
|
|
226 |
1
| return true;
|
|
227 |
| } |
|
228 |
| } |