Coverage Report - org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
AspectJSecurityInterceptor
100% 
100% 
1
 
 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.aspectj;
 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.aspectj.lang.JoinPoint;
 24  
 
 25  
 
 26  
 /**
 27  
  * Provides security interception of AspectJ method invocations.<p>The <code>ObjectDefinitionSource</code> required
 28  
  * by this security interceptor is of type {@link MethodDefinitionSource}. This is shared with the AOP Alliance based
 29  
  * security interceptor (<code>MethodSecurityInterceptor</code>),  since both work with Java <code>Method</code>s.</p>
 30  
  *  <p>The secure object type is <code>org.aspectj.lang.JoinPoint</code>, which is passed from the relevant
 31  
  * <code>around()</code> advice. The <code>around()</code> advice also passes an anonymous implementation of {@link
 32  
  * AspectJCallback} which contains the call for AspectJ to continue processing:  <code>return proceed();</code>.</p>
 33  
  *  <P>Refer to {@link AbstractSecurityInterceptor} for details on the workflow.</p>
 34  
  *
 35  
  * @author Ben Alex
 36  
  * @version $Id: AspectJSecurityInterceptor.java 1496 2006-05-23 13:38:33Z benalex $
 37  
  */
 38  2
 public class AspectJSecurityInterceptor extends AbstractSecurityInterceptor {
 39  
     //~ Instance fields ================================================================================================
 40  
 
 41  
     private MethodDefinitionSource objectDefinitionSource;
 42  
 
 43  
     //~ Methods ========================================================================================================
 44  
 
 45  
     public MethodDefinitionSource getObjectDefinitionSource() {
 46  1
         return this.objectDefinitionSource;
 47  
     }
 48  
 
 49  
     public Class getSecureObjectClass() {
 50  17
         return JoinPoint.class;
 51  
     }
 52  
 
 53  
     /**
 54  
      * This method should be used to enforce security on a <code>JoinPoint</code>.
 55  
      *
 56  
      * @param jp The AspectJ joint point being invoked which requires a security decision
 57  
      * @param advisorProceed the advice-defined anonymous class that implements <code>AspectJCallback</code> containing
 58  
      *        a simple <code>return proceed();</code> statement
 59  
      *
 60  
      * @return The returned value from the method invocation
 61  
      */
 62  
     public Object invoke(JoinPoint jp, AspectJCallback advisorProceed) {
 63  2
         Object result = null;
 64  2
         InterceptorStatusToken token = super.beforeInvocation(jp);
 65  
 
 66  
         try {
 67  1
             result = advisorProceed.proceedWithObject();
 68  
         } finally {
 69  1
             result = super.afterInvocation(token, result);
 70  1
         }
 71  
 
 72  1
         return result;
 73  
     }
 74  
 
 75  
     public ObjectDefinitionSource obtainObjectDefinitionSource() {
 76  8
         return this.objectDefinitionSource;
 77  
     }
 78  
 
 79  
     public void setObjectDefinitionSource(MethodDefinitionSource newSource) {
 80  2
         this.objectDefinitionSource = newSource;
 81  2
     }
 82  
 }