Spring security Aspectj和spring安全特性-通知执行顺序

Spring security Aspectj和spring安全特性-通知执行顺序,spring-security,aspectj,spring-aop,aspectj-maven-plugin,Spring Security,Aspectj,Spring Aop,Aspectj Maven Plugin,我使用的是SpringSecurity3.2.4.RELEASE,SpringSecurityAspects3.2.4.RELEASE,AspectJMaven插件版本1.6,Java7 我使用的是AspectJ的编织而不是SpringAOP,因此我的AspectJ maven插件如下所示: <plugin> <groupId>org.codehaus.mojo</groupId>

我使用的是SpringSecurity3.2.4.RELEASE,SpringSecurityAspects3.2.4.RELEASE,AspectJMaven插件版本1.6,Java7

我使用的是AspectJ的编织而不是SpringAOP,因此我的AspectJ maven插件如下所示:

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>                     
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                    </execution>
                </executions>
                <configuration>
                    <Xlint>ignore</Xlint>
                    <showWeaveInfo>true</showWeaveInfo>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <complianceLevel>${org.aspectj-version}</complianceLevel>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework.security</groupId>
                            <artifactId>spring-security-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
          </plugin>
package com.mycompany.fw.app.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer;

import com.mycompany.fw.security.Integration;

@Aspect
@DeclarePrecedence("IntegrationAspects*,*")
public class IntegrationAspects {

    ParameterNameDiscoverer parameterNameDiscoverer = new DefaultSecurityParameterNameDiscoverer();

    @Pointcut("(execution(* com.mycompany..*(..))) && @annotation(integrate) ")
    public void integratePointCut(Integration integrate) {

    }

    /**
     * TODO: cache
     * 
     * @param jp
     * @param integrate
     * @throws Throwable
     */
    @Around("integratePointCut(integrate)")
    public Object integrate(final ProceedingJoinPoint pjp, Integration integrate) throws Throwable {
        Object res = pjp.proceed();
        return res;
    }

}
我需要的是将上面的(集成方面)放在任何其他方面(包括Spring的安全方面)之前 正如您所看到的,我用
@declareprecence
尝试了它(我也用
声明优先级:IntegrationAspects*,*
以及在.aj文件中尝试了它),不幸的是,没有成功


有人能告诉我如何定义方面调用顺序吗?

问题是在
@declarepreceidence
中没有使用简单的方面名称
IntegrationAspects
,而是使用了一个小丑角色
*
。在这种情况下,您需要使用完全限定的类名或jokers创建相同的类名

不起作用:

@declareReceidence(“集成方面*,*”)
有效:

@declareReceidence(“集成方面,*”)
@declarepreceidence(“com.mycompany.fw.security.Integration.IntegrationAspects,*”)
@declarepreceidence(“com.mycompany.fw.security.Integration.IntegrationAspects*,*”)
@declareReceidence(“*…集成方面*,*”)
等等。顺便说一下,在类名中使用大写的包名和复数看起来非常难看


我是AspectJ专家,不是Spring用户,所以我无法告诉您声明优先级是否也会影响Spring提供的方面。这可能还取决于它们是使用本机AspectJ还是Spring AOP(基于代理的“AOP lite”)实现的。

谢谢你的回答。我不是使用Spring AOP,而是使用纯AspectJ(尽管有些方面是Spring编写的)您是否知道@declareprecessence注释中结合*.aj文件和*.java文件的方面存在限制?更具体地说,您可以查看org.springframework.security.access.intercept.aspectj.aspect.AnnotationSecurityAspect,它是一个*.aj文件,我试图添加一个将在securedMethodExecution aspectWell之前调用的方面,我不知道您使用的是原生AspectJ,因为您也用SpringAOP标记了这个问题,而且语法应该是相同的。我的回答能解决你的问题吗?你没有提到那件事。您微妙的语法错误使它无法在我自己的测试项目中工作,但我的备选方案确实有效。我注意到的另一个观察结果是,当我添加我自己的方面时,我定义的顺序将被应用,但当我将AnnotationSecurityAspect.aj添加到顺序中时,没有任何效果,即使是在您正确之前正确运行的顺序,它们也会运行,但当我添加AnnotationSecurityAspect时,仍然没有应用任何顺序。
AnnotationSecurityAspect
是Spring框架的一部分。我不知道它是如何编织到代码中的,以及它是否使用与用于您自己方面的相同的编织器实例。作为SpringNoob,您能为我提供一个Git(Hub)存储库,其中包含一个随时可以运行的项目,重现这个问题吗?以Maven构建的最佳方式?