01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
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: * Provides security interception of AOP Alliance based method invocations.<p>The
28: * <code>ObjectDefinitionSource</code> required by this security interceptor is of type {@link
29: * MethodDefinitionSource}. This is shared with the AspectJ based security interceptor
30: * (<code>AspectJSecurityInterceptor</code>), since both work with Java <code>Method</code>s.</p>
31: * <P>Refer to {@link AbstractSecurityInterceptor} for details on the workflow.</p>
32: *
33: * @author Ben Alex
34: * @version $Id: MethodSecurityInterceptor.java 1496 2006-05-23 13:38:33Z benalex $
35: */
36: public class MethodSecurityInterceptor extends
37: AbstractSecurityInterceptor implements MethodInterceptor {
38: //~ Instance fields ================================================================================================
39:
40: private MethodDefinitionSource objectDefinitionSource;
41:
42: //~ Methods ========================================================================================================
43:
44: public MethodDefinitionSource getObjectDefinitionSource() {
45: return this .objectDefinitionSource;
46: }
47:
48: public Class getSecureObjectClass() {
49: return MethodInvocation.class;
50: }
51:
52: /**
53: * This method should be used to enforce security on a <code>MethodInvocation</code>.
54: *
55: * @param mi The method being invoked which requires a security decision
56: *
57: * @return The returned value from the method invocation
58: *
59: * @throws Throwable if any error occurs
60: */
61: public Object invoke(MethodInvocation mi) throws Throwable {
62: Object result = null;
63: InterceptorStatusToken token = super .beforeInvocation(mi);
64:
65: try {
66: result = mi.proceed();
67: } finally {
68: result = super .afterInvocation(token, result);
69: }
70:
71: return result;
72: }
73:
74: public ObjectDefinitionSource obtainObjectDefinitionSource() {
75: return this .objectDefinitionSource;
76: }
77:
78: public void setObjectDefinitionSource(
79: MethodDefinitionSource newSource) {
80: this.objectDefinitionSource = newSource;
81: }
82: }
|