2017-10-20 61 views
2

我阅读之前有关禁用@EnableGlobalMethodSecurity解决方案的文章,但它对我无效。基本上,我需要在启动时启用/禁用我的@PreAuthorize批注以用于测试目的。这里是我的相关代码:禁用@EnableGlobalMethodSecurity进行测试

@Configuration 
@EnableGlobalMethodSecurity 
public class OpenAMMethodSecurityConfig extends GlobalMethodSecurityConfiguration { 

... 
    @Value("${security.enabled}") 
    private boolean enabled; 
... 

    protected MethodSecurityMetadataSource customMethodSecurityMetadataSource() { 
     return enabled ? new SecuredAnnotationSecurityMetadataSource() : null; 
    }   

虽然代码将禁用方法的安全性,如果“启用”标志被设置为true,也不会重新启用它,除非标注含有...(prePostEnabled =真) 。在研究代码时,我认为由于执行customMethodSecurityMetadataSource(),prePostEnabled被设置为true。

请指教...

回答

0

您可以使用测试属性来禁用基于你有什么设置...

@TestPropertySource(properties = "security.enabled:false")