| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| MethodDefinitionSourceAdvisor |
|
| 1.7777777777777777;1.778 |
| 1 | /* Copyright 2004, 2005, 2006 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.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 MethodSecurityInterceptor} from |
|
| 31 | * public (ie non-secure) methods.<p>Because the AOP framework caches advice calculations, this is normally faster |
|
| 32 | * than just letting the <code>MethodSecurityInterceptor</code> run and find out itself that it has no work to do.</p> |
|
| 33 | * <p>This class also allows the use of Spring's <code>DefaultAdvisorAutoProxyCreator</code>, which makes |
|
| 34 | * configuration easier than setup a <code>ProxyFactoryBean</code> for each object requiring security. Note that |
|
| 35 | * autoproxying is not supported for BeanFactory implementations, as post-processing is automatic only for application |
|
| 36 | * contexts.</p> |
|
| 37 | * <p>Based on Spring's TransactionAttributeSourceAdvisor.</p> |
|
| 38 | * |
|
| 39 | * @author Ben Alex |
|
| 40 | * @version $Id: MethodDefinitionSourceAdvisor.java 1784 2007-02-24 21:00:24Z luke_t $ |
|
| 41 | */ |
|
| 42 | public class MethodDefinitionSourceAdvisor extends StaticMethodMatcherPointcutAdvisor { |
|
| 43 | //~ Instance fields ================================================================================================ |
|
| 44 | ||
| 45 | private MethodDefinitionSource transactionAttributeSource; |
|
| 46 | ||
| 47 | //~ Constructors =================================================================================================== |
|
| 48 | ||
| 49 | public MethodDefinitionSourceAdvisor(MethodSecurityInterceptor advice) { |
|
| 50 | 5 | super(advice); |
| 51 | ||
| 52 | 5 | if (advice.getObjectDefinitionSource() == null) { |
| 53 | 1 | throw new AopConfigException("Cannot construct a MethodDefinitionSourceAdvisor using a " |
| 54 | + "MethodSecurityInterceptor that has no ObjectDefinitionSource configured"); |
|
| 55 | } |
|
| 56 | ||
| 57 | 4 | this.transactionAttributeSource = advice.getObjectDefinitionSource(); |
| 58 | 4 | } |
| 59 | ||
| 60 | //~ Methods ======================================================================================================== |
|
| 61 | ||
| 62 | public boolean matches(Method m, Class targetClass) { |
|
| 63 | 2 | MethodInvocation methodInvocation = new InternalMethodInvocation(m); |
| 64 | ||
| 65 | 2 | return (this.transactionAttributeSource.getAttributes(methodInvocation) != null); |
| 66 | } |
|
| 67 | ||
| 68 | //~ Inner Classes ================================================================================================== |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Represents a <code>MethodInvocation</code>. |
|
| 72 | * <p>Required as <code>MethodDefinitionSource</code> only supports lookup of configuration attributes for |
|
| 73 | * <code>MethodInvocation</code>s.</p> |
|
| 74 | */ |
|
| 75 | class InternalMethodInvocation implements MethodInvocation { |
|
| 76 | private Method method; |
|
| 77 | ||
| 78 | 3 | public InternalMethodInvocation(Method method) { |
| 79 | 3 | this.method = method; |
| 80 | 3 | } |
| 81 | ||
| 82 | 1 | protected InternalMethodInvocation() { |
| 83 | 1 | throw new UnsupportedOperationException(); |
| 84 | } |
|
| 85 | ||
| 86 | public Object[] getArguments() { |
|
| 87 | 1 | throw new UnsupportedOperationException(); |
| 88 | } |
|
| 89 | ||
| 90 | public Method getMethod() { |
|
| 91 | 2 | return this.method; |
| 92 | } |
|
| 93 | ||
| 94 | public AccessibleObject getStaticPart() { |
|
| 95 | 1 | throw new UnsupportedOperationException(); |
| 96 | } |
|
| 97 | ||
| 98 | public Object getThis() { |
|
| 99 | 1 | throw new UnsupportedOperationException(); |
| 100 | } |
|
| 101 | ||
| 102 | public Object proceed() throws Throwable { |
|
| 103 | 1 | throw new UnsupportedOperationException(); |
| 104 | } |
|
| 105 | } |
|
| 106 | } |