Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring security 多个@EnableGlobalMethodSecurity注释_Spring Security_Spring Boot - Fatal编程技术网

Spring security 多个@EnableGlobalMethodSecurity注释

Spring security 多个@EnableGlobalMethodSecurity注释,spring-security,spring-boot,Spring Security,Spring Boot,如果多个配置类具有@EnableGlobalMethodSecurity注释,那么是否使用一个并忽略一个 在spring boot应用程序中有两个WebSecurityConfigureAdapter——一个用@EnableGlobalMethodSecurity(secured=true)注释,另一个用@EnableGlobalMethodSecurity(prespenabled=true)。但到目前为止,我无法使@PreAuthorize注释正常工作。只有一个注释,我才能看到它是否被应用。

如果多个配置类具有
@EnableGlobalMethodSecurity
注释,那么是否使用一个并忽略一个

在spring boot应用程序中有两个
WebSecurityConfigureAdapter
——一个用
@EnableGlobalMethodSecurity(secured=true)
注释,另一个用
@EnableGlobalMethodSecurity(prespenabled=true)
。但到目前为止,我无法使
@PreAuthorize
注释正常工作。只有一个注释,我才能看到它是否被应用。 乙二醇

spring security是否支持使用@EnableGlobalMethodSecurity注释多个配置类?
有没有办法查看实际配置的内容?

我调试它(到springframework源代码中)以查看加载的内容和顺序

我有一个类似的情况,我有一个配置
@EnableGlobalMethodSecurity(securedEnabled=true)
的库(我无法更改)

我想使用
@EnableGlobalMethodSecurity(preprestenabled=true)

发生的情况是,库配置被加载到我的配置上(只会使用最后加载的配置)

我尝试使用
@Order(Ordered.lower\u priority)
@EnableGlobalMethodSecurity(Order=Ordered.HIGHEST\u priority,…
,但没有效果

我的解决方案是通过在我的配置中导入库配置来设置我想要的顺序,如下所示:

@Import(LibraryConfig.class)
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class MyConfiguration extends GlobalMethodSecurityConfiguration {
    /* my code */
}
另外:我发现我的情况更加复杂,因为我使用的库不止一次配置了
@EnableGlobalMethodSecurity(securedEnabled=true)
。 因此,behave有点不同,为了强制使用我的配置,我必须覆盖此方法的实现:

@Bean
public MethodSecurityMetadataSource methodSecurityMetadataSource() {
    return super.methodSecurityMetadataSource();
}

@Bean
public MethodInterceptor methodSecurityInterceptor() throws Exception {
    return super.methodSecurityInterceptor();
}

@Bean
public PreInvocationAuthorizationAdvice preInvocationAuthorizationAdvice() {
    return super.preInvocationAuthorizationAdvice();
}

在我们的一款产品上遇到同样的问题,这有助于解决问题。
@Bean
public MethodSecurityMetadataSource methodSecurityMetadataSource() {
    return super.methodSecurityMetadataSource();
}

@Bean
public MethodInterceptor methodSecurityInterceptor() throws Exception {
    return super.methodSecurityInterceptor();
}

@Bean
public PreInvocationAuthorizationAdvice preInvocationAuthorizationAdvice() {
    return super.preInvocationAuthorizationAdvice();
}