001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.shiro.aspectj;
020
021 import org.apache.shiro.aop.MethodInvocation;
022 import org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor;
023 import org.aspectj.lang.JoinPoint;
024 import org.aspectj.lang.reflect.MethodSignature;
025 import org.slf4j.Logger;
026 import org.slf4j.LoggerFactory;
027
028 import java.util.Arrays;
029
030 /**
031 * Extends the annotations authorizing method interceptor class hierarchie to adapt
032 * an aspectj {@link JoinPoint} into a {@link MethodInvocation} amd to perform the
033 * authorization of method invocations.
034 *
035 * @author J-C Desrochers
036 * @author Kalle Korhonen
037 * @since 1.0
038 */
039 public class AspectjAnnotationsAuthorizingMethodInterceptor extends AnnotationsAuthorizingMethodInterceptor {
040 /**
041 * This class's private log instance.
042 */
043 private static final Logger log = LoggerFactory.getLogger(AspectjAnnotationsAuthorizingMethodInterceptor.class);
044
045 /**
046 * Performs the method interception of the before advice at the specified joint point.
047 *
048 * @param aJoinPoint The joint point to intercept.
049 * @throws Throwable If an error occurs berforming the method invocation.
050 */
051 protected void performBeforeInterception(JoinPoint aJoinPoint) throws Throwable {
052 if (log.isTraceEnabled()) log.trace("#### Invoking a method decorated with a Shiro annotation" +
053 "\n\tkind : " + aJoinPoint.getKind() +
054 "\n\tjoinPoint : " + aJoinPoint +
055 "\n\tannotations: " + Arrays.toString(((MethodSignature) aJoinPoint.getSignature()).getMethod().getAnnotations()) +
056 "\n\ttarget : " + aJoinPoint.getTarget()
057 );
058
059 // 1. Adapt the join point into a method invocation
060 BeforeAdviceMethodInvocationAdapter mi = BeforeAdviceMethodInvocationAdapter.createFrom(aJoinPoint);
061
062 // 2. Delegate the authorization of the method call to the super class
063 super.invoke(mi);
064 }
065 }