1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.intercept.method.aopalliance;
17
18 import org.acegisecurity.intercept.method.MethodDefinitionSource;
19
20 import org.aopalliance.intercept.MethodInvocation;
21
22 import org.springframework.aop.framework.AopConfigException;
23 import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
24
25 import java.lang.reflect.AccessibleObject;
26 import java.lang.reflect.Method;
27
28
29 /***
30 * Advisor driven by a {@link MethodDefinitionSource}, used to exclude a {@link
31 * MethodSecurityInterceptor} from public (ie non-secure) methods.
32 *
33 * <p>
34 * Because the AOP framework caches advice calculations, this is normally
35 * faster than just letting the <code>MethodSecurityInterceptor</code> run and
36 * find out itself that it has no work to do.
37 * </p>
38 *
39 * <p>
40 * This class also allows the use of Spring's
41 * <code>DefaultAdvisorAutoProxyCreator</code>, which makes configuration
42 * easier than setup a <code>ProxyFactoryBean</code> for each object requiring
43 * security. Note that autoproxying is not supported for BeanFactory
44 * implementations, as post-processing is automatic only for application
45 * contexts.
46 * </p>
47 *
48 * <p>
49 * Based on Spring's TransactionAttributeSourceAdvisor.
50 * </p>
51 *
52 * @author Ben Alex
53 * @version $Id: MethodDefinitionSourceAdvisor.java,v 1.3 2005/11/17 00:55:49 benalex Exp $
54 */
55 public class MethodDefinitionSourceAdvisor
56 extends StaticMethodMatcherPointcutAdvisor {
57
58
59 private MethodDefinitionSource transactionAttributeSource;
60
61
62
63 public MethodDefinitionSourceAdvisor(MethodSecurityInterceptor advice) {
64 super(advice);
65
66 if (advice.getObjectDefinitionSource() == null) {
67 throw new AopConfigException(
68 "Cannot construct a MethodDefinitionSourceAdvisor using a "
69 + "MethodSecurityInterceptor that has no ObjectDefinitionSource configured");
70 }
71
72 this.transactionAttributeSource = advice.getObjectDefinitionSource();
73 }
74
75
76
77 public boolean matches(Method m, Class targetClass) {
78 MethodInvocation methodInvocation = new InternalMethodInvocation(m);
79
80 return (this.transactionAttributeSource.getAttributes(methodInvocation) != null);
81 }
82
83
84
85 /***
86 * Represents a <code>MethodInvocation</code>.
87 *
88 * <p>
89 * Required as <code>MethodDefinitionSource</code> only supports lookup of
90 * configuration attributes for <code>MethodInvocation</code>s.
91 * </p>
92 */
93 class InternalMethodInvocation implements MethodInvocation {
94 Method method;
95
96 public InternalMethodInvocation(Method method) {
97 this.method = method;
98 }
99
100 protected InternalMethodInvocation() {
101 throw new UnsupportedOperationException();
102 }
103
104 public Object[] getArguments() {
105 throw new UnsupportedOperationException();
106 }
107
108 public Method getMethod() {
109 return this.method;
110 }
111
112 public AccessibleObject getStaticPart() {
113 throw new UnsupportedOperationException();
114 }
115
116 public Object getThis() {
117 throw new UnsupportedOperationException();
118 }
119
120 public Object proceed() throws Throwable {
121 throw new UnsupportedOperationException();
122 }
123 }
124 }