简体   繁体   中英

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. This my java configs:

@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
public class Entity {
    @PreAuthorize("hasPermission(this, 'publish')")
    public void method() { }
}

I also added spring-security-aspects as dependency. 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:

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 . This seems to be bug that was discussed here : Spring Security AspectJMode with @EnableGlobalMethodSecurity not working

However this bug should not affect my version of spring security... Is there any workaround for this issue?

Ok I have solved this. It was problem with spring boot's SecurityAutoConfiguration class. I had to exclude it from auto configuration and configre spring security manually - not very big deal, but anyway...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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