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 * @since 1.0
036 */
037 public class AspectjAnnotationsAuthorizingMethodInterceptor extends AnnotationsAuthorizingMethodInterceptor {
038 /**
039 * This class's private log instance.
040 */
041 private static final Logger log = LoggerFactory.getLogger(AspectjAnnotationsAuthorizingMethodInterceptor.class);
042
043 /**
044 * Performs the method interception of the before advice at the specified joint point.
045 *
046 * @param aJoinPoint The joint point to intercept.
047 * @throws Throwable If an error occurs berforming the method invocation.
048 */
049 protected void performBeforeInterception(JoinPoint aJoinPoint) throws Throwable {
050 if (log.isTraceEnabled()) log.trace("#### Invoking a method decorated with a Shiro annotation" +
051 "\n\tkind : " + aJoinPoint.getKind() +
052 "\n\tjoinPoint : " + aJoinPoint +
053 "\n\tannotations: " + Arrays.toString(((MethodSignature) aJoinPoint.getSignature()).getMethod().getAnnotations()) +
054 "\n\ttarget : " + aJoinPoint.getTarget()
055 );
056
057 // 1. Adapt the join point into a method invocation
058 BeforeAdviceMethodInvocationAdapter mi = BeforeAdviceMethodInvocationAdapter.createFrom(aJoinPoint);
059
060 // 2. Delegate the authorization of the method call to the super class
061 super.invoke(mi);
062 }
063 }