【问题标题】:Spring boot + Spring security with AspectJ not workingSpring boot + Spring security with AspectJ 不工作
【发布时间】:2015-02-22 14:06:57
【问题描述】:

我正在尝试使用 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 版本...有没有解决这个问题的方法?

【问题讨论】:

    标签: java spring spring-security spring-boot aspectj


    【解决方案1】:

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

    【讨论】:

    • 您能否详细说明如何禁用自动配置以及必须手动设置的 bean?我正在尝试自己解决这个问题,并在 Spring Boot 和 AspectJ 中遇到相同的错误消息。
    猜你喜欢
    • 2021-07-28
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 2020-02-09
    相关资源
    最近更新 更多