|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MethodSecurityInterceptor.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 1 | /* Copyright 2004 Acegi Technology Pty Limited | |
| 2 | * | |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | * you may not use this file except in compliance with the License. | |
| 5 | * You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * 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 | /** | |
| 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 | //~ Instance fields ======================================================== | |
| 48 | ||
| 49 | private MethodDefinitionSource objectDefinitionSource; | |
| 50 | ||
| 51 | //~ Methods ================================================================ | |
| 52 | ||
| 53 | 26 | public void setObjectDefinitionSource(MethodDefinitionSource newSource) { |
| 54 | 26 | this.objectDefinitionSource = newSource; |
| 55 | } | |
| 56 | ||
| 57 | 10 | public MethodDefinitionSource getObjectDefinitionSource() { |
| 58 | 10 | return this.objectDefinitionSource; |
| 59 | } | |
| 60 | ||
| 61 | 107 | public Class getSecureObjectClass() { |
| 62 | 107 | 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 | 10 | public Object invoke(MethodInvocation mi) throws Throwable { |
| 76 | 10 | Object result = null; |
| 77 | 10 | InterceptorStatusToken token = super.beforeInvocation(mi); |
| 78 | ||
| 79 | 6 | try { |
| 80 | 6 | result = mi.proceed(); |
| 81 | } finally { | |
| 82 | 6 | result = super.afterInvocation(token, result); |
| 83 | } | |
| 84 | ||
| 85 | 6 | return result; |
| 86 | } | |
| 87 | ||
| 88 | 61 | public ObjectDefinitionSource obtainObjectDefinitionSource() { |
| 89 | 61 | return this.objectDefinitionSource; |
| 90 | } | |
| 91 | } |
|
||||||||||