java - Spring boot + Spring security with AspectJ 不工作

标签 java spring spring-security spring-boot aspectj

我正在尝试使用 AspectJ 建议模式配置 spring 全局方法安全性,以便我可以在所有 @Configurable 注释类中使用 @PreAuthorize 注释。这是我的 java 配置:

@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, mode = AdviceMode.ASPECTJ)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration

和:

@EnableCaching
@SpringBootApplication
@EnableSpringConfigured
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class WebApplication extends WebMvcConfigurerAdapter 

这是我的@Configurable类:

@Configurable
public class Entity {
    @PreAuthorize("hasPermission(this, 'publish')")
    public void method() { }
}

我还添加了 spring-security-aspects 作为依赖项。从 AspectJ 日志中,我可以清楚地看到 Spring 安全相关方面应用于我的 @Configurable 类,但是一旦我创建这些类的实例,我就会得到这个异常:

Post-processor tried to replace bean instance of type [com.example.Entity] with (proxy) object of type [com.sun.proxy.$Proxy130] - not supported for aspect-configured classes!

我使用的是 spring boot 版本 1.2.1 因此 spring security 版本是 3.2.5 。这似乎是这里讨论的错误:Spring Security AspectJMode with @EnableGlobalMethodSecurity not working

但是这个错误不应该影响我的 spring security 版本......这个问题有什么解决方法吗?

最佳答案

好的,我已经解决了这个问题。这是 spring boot 的 SecurityAutoConfiguration 类的问题。我不得不将它从自动配置中排除并手动配置 spring security - 没什么大不了的,但无论如何......

关于java - Spring boot + Spring security with AspectJ 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28658718/

相关文章:

spring-security - 获取异常java.lang.NoClassDefFoundError : Could not initialize class javax. xml.bind.DatatypeConverterImpl

java - Android Studio 2.3 for mac 打开zip文件时出现: gradle sync failed,错误

java - 从用户获取更多信息 - Spring Security

node.js - 使用 Tomcat 和 NodeJS 进行单点登录

java - Spring 安全 "authorities-by-username-query"错误

spring - 如何配置 Spring Data REST 以将新创建​​的实体作为 POST 正文的一部分返回

grails - Grails Acegi:更新用户名

java - 配置 com.sun.xml.ws.transport.http.servlet.WSServletContextListener 类的应用程序监听器时出错

java - jackson : Updating (not creating new object) JavaObject from Json?

java - 为什么建议使用 Yourkit 8.X 仅分析 java 5 应用程序?