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.AbstractSecurityInterceptor;
19 import org.acegisecurity.intercept.InterceptorStatusToken;
20 import org.acegisecurity.intercept.ObjectDefinitionSource;
21 import org.acegisecurity.intercept.method.MethodDefinitionSource;
22
23 import org.aopalliance.intercept.MethodInterceptor;
24 import org.aopalliance.intercept.MethodInvocation;
25
26
27 /***
28 * Provides security interception of AOP Alliance based method invocations.
29 *
30 * <p>
31 * The <code>ObjectDefinitionSource</code> required by this security
32 * interceptor is of type {@link MethodDefinitionSource}. This is shared with
33 * the AspectJ based security interceptor
34 * (<code>AspectJSecurityInterceptor</code>), since both work with Java
35 * <code>Method</code>s.
36 * </p>
37 *
38 * <P>
39 * Refer to {@link AbstractSecurityInterceptor} for details on the workflow.
40 * </p>
41 *
42 * @author Ben Alex
43 * @version $Id: MethodSecurityInterceptor.java,v 1.3 2005/11/17 00:55:49 benalex Exp $
44 */
45 public class MethodSecurityInterceptor extends AbstractSecurityInterceptor
46 implements MethodInterceptor {
47
48
49 private MethodDefinitionSource objectDefinitionSource;
50
51
52
53 public void setObjectDefinitionSource(MethodDefinitionSource newSource) {
54 this.objectDefinitionSource = newSource;
55 }
56
57 public MethodDefinitionSource getObjectDefinitionSource() {
58 return this.objectDefinitionSource;
59 }
60
61 public Class getSecureObjectClass() {
62 return MethodInvocation.class;
63 }
64
65 /***
66 * This method should be used to enforce security on a
67 * <code>MethodInvocation</code>.
68 *
69 * @param mi The method being invoked which requires a security decision
70 *
71 * @return The returned value from the method invocation
72 *
73 * @throws Throwable if any error occurs
74 */
75 public Object invoke(MethodInvocation mi) throws Throwable {
76 Object result = null;
77 InterceptorStatusToken token = super.beforeInvocation(mi);
78
79 try {
80 result = mi.proceed();
81 } finally {
82 result = super.afterInvocation(token, result);
83 }
84
85 return result;
86 }
87
88 public ObjectDefinitionSource obtainObjectDefinitionSource() {
89 return this.objectDefinitionSource;
90 }
91 }