dimanche 22 février 2015

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?


Aucun commentaire:

Enregistrer un commentaire