1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.acegisecurity.vote;
16
17 import org.acegisecurity.AuthorizationServiceException;
18
19 import org.aopalliance.intercept.MethodInvocation;
20
21 import org.aspectj.lang.JoinPoint;
22 import org.aspectj.lang.reflect.CodeSignature;
23
24 import org.springframework.util.Assert;
25
26
27
28
29
30
31
32
33 public abstract class AbstractAclVoter implements AccessDecisionVoter {
34
35
36 private Class processDomainObjectClass;
37
38
39
40 protected Object getDomainObjectInstance(Object secureObject) {
41 Object[] args;
42 Class[] params;
43
44 if (secureObject instanceof MethodInvocation) {
45 MethodInvocation invocation = (MethodInvocation) secureObject;
46 params = invocation.getMethod().getParameterTypes();
47 args = invocation.getArguments();
48 } else {
49 JoinPoint jp = (JoinPoint) secureObject;
50 params = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes();
51 args = jp.getArgs();
52 }
53
54 for (int i = 0; i < params.length; i++) {
55 if (processDomainObjectClass.isAssignableFrom(params[i])) {
56 return args[i];
57 }
58 }
59
60 throw new AuthorizationServiceException("Secure object: " + secureObject
61 + " did not provide any argument of type: " + processDomainObjectClass);
62 }
63
64 public Class getProcessDomainObjectClass() {
65 return processDomainObjectClass;
66 }
67
68 public void setProcessDomainObjectClass(Class processDomainObjectClass) {
69 Assert.notNull(processDomainObjectClass, "processDomainObjectClass cannot be set to null");
70 this.processDomainObjectClass = processDomainObjectClass;
71 }
72
73
74
75
76
77
78
79
80
81 public boolean supports(Class clazz) {
82 if (MethodInvocation.class.isAssignableFrom(clazz)) {
83 return true;
84 } else if (JoinPoint.class.isAssignableFrom(clazz)) {
85 return true;
86 } else {
87 return false;
88 }
89 }
90 }