简体   繁体   English

使用AspectJ的Spring启动+ Spring安全性无法正常工作

[英]Spring boot + Spring security with AspectJ not working

I am trying to configure spring global method security with AspectJ advice mode so I can use @PreAuthorize annotations in all @Configurable annotated classes. 我正在尝试使用AspectJ建议模式配置spring全局方法安全性,因此我可以在所有@Configurable注释类中使用@PreAuthorize注释。 This my java configs: 这是我的java配置:

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

and: 和:

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

This is my @Configurable class: 这是我的@Configurable类:

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

I also added spring-security-aspects as dependency. 我还添加了spring-security-aspects作为依赖。 From AspectJ logs I can clearly see that Spring security related aspects are applied on my @Configurable classes however as soon as I create instance of these classes I get this exception: 从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!

I am using spring boot version 1.2.1 therefore spring security version is 3.2.5 . 我使用的是spring boot 1.2.1版本,因此Spring安全版本为3.2.5。 This seems to be bug that was discussed here : Spring Security AspectJMode with @EnableGlobalMethodSecurity not working 这似乎是这里讨论的错误: Spring安全AspectJMode与@EnableGlobalMethodSecurity无法正常工作

However this bug should not affect my version of spring security... Is there any workaround for this issue? 但是这个bug不应该影响我的弹簧安全版本......这个问题是否有解决方法?

Ok I have solved this. 好的我已经解决了这个问题 It was problem with spring boot's SecurityAutoConfiguration class. 这是spring boot的SecurityAutoConfiguration类的问题。 I had to exclude it from auto configuration and configre spring security manually - not very big deal, but anyway... 我不得不将它从自动配置中排除并手动配置弹簧安全 - 不是很大,但无论如何......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM