首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Spring 2中禁用执行器安全性而不完全禁用它

如何在Spring 2中禁用执行器安全性而不完全禁用它
EN

Stack Overflow用户
提问于 2018-09-02 15:59:20
回答 7查看 22.8K关注 0票数 7

我在OAuth2中使用。我不想禁用健康端点的安全性。

我可以完全禁用安全性,或者编写自己的WebSecurityConfigurerAdapter实现,并禁用自动配置的实现。

但是如何修改WebSecurityConfigurerAdapter (OAuth2SsoDefaultConfiguration)的现有实现呢?

我试图在不禁用自动配置的情况下创建自己的配置,但由于Order冲突,这是不可能的。

以下是错误消息:

代码语言:javascript
运行
复制
Caused by: java.lang.IllegalStateException: @Order on WebSecurityConfigurers must be unique. 
Order of 100 was already used on SecurityConfiguration$$EnhancerBySpringCGLIB$$9505fc58@13f182b9,
 so it cannot be used on 
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2SsoDefaultConfiguration$$EnhancerBySpringCGLIB$$dc290e2b@5ee0cf64 too.

此外,我试图为我自己的安全配置显式设置更高的顺序,但看起来像自动配置的一个覆盖了我的配置。

那么,如何在不重新实现整个配置的情况下覆盖特定的安全规则?

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2018-09-02 17:42:19

您需要在

@SpringBootApplication

代码语言:javascript
运行
复制
 @SpringBootApplication
 @EnableResourceServer
 @EnableGlobalMethodSecurity(prePostEnabled = true)
 @Configuration
 public class BusinessLogicServiceApplication extends ResourceServerConfigurerAdapter {

 public static void main(String[] args) throws IOException {
    ConfigurableApplicationContext context =  
    SpringApplication.run(BusinessLogicServiceApplication.class, args);
    }

  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/health").permitAll().anyRequest().authenticated();

    }
}
票数 8
EN

Stack Overflow用户

发布于 2018-09-02 20:26:04

代码语言:javascript
运行
复制
@Configuration
@EnableOAuth2Sso
class MyConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/actuator/health")
                .permitAll()
            .anyRequest()
                .authenticated();
    }

}

确保您是在WebSecurityConfigurerAdapter类上使用WebSecurityConfigurerAdapter。这很重要,因为它将包括OAuth2SsoCustomConfiguration,它基本上复制了OAuth2SsoDefaultConfiguration#configure的功能。

您还可能希望显示完整的健康详细信息:

代码语言:javascript
运行
复制
management:
  endpoint:
    health:
      show-details: always
票数 6
EN

Stack Overflow用户

发布于 2018-09-02 16:44:57

以下是可能的支票。

解决方案1:确保您正在使用

org.springframework.core.annotation.Order

而不是

org.apache.logging.log4j.core.config.Order

因为Spring没有解析正确的注释,所以它假设这两种配置的默认值为100。

解决方案2

也许您已经用@EnableWebSecurity注释了另一个类。请注意,只有一个类可以实现此注释。

解决方案3:请参阅此https://stackoverflow.com/a/44076087/6572971

解决方案4:

代码语言:javascript
运行
复制
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class DemoConfigurer extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception{
        http.authorizeRequests().antMatchers("/health").permitAll();
        super.configure(http);
    }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52138679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档