【问题标题】:how to secure only one url with spring security and permit all如何使用 spring security 只保护一个 url 并允许所有
【发布时间】:2018-01-03 10:09:44
【问题描述】:

我正在尝试将 Spring 安全配置为仅阻止对 swagger 的请求,但它会阻止所有 url。 有谁知道如何只锁定 swagger 的 url 而其余的都不安全?

protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable()
        .authorizeRequests().anyRequest().permitAll()
        .and()
        .authorizeRequests()
            .antMatchers("/swagger*/**").authenticated();

        http.httpBasic();
    }

【问题讨论】:

  • 除了招摇,那不是挡住了一切吗?
  • 这阻碍了我的帖子 localhost:8012/bus/refresh

标签: java spring-security springfox


【解决方案1】:

尝试以下方法:

http.authorizeRequests()
.antMatchers("/swagger*/**").authenticated()
.anyRequest().permitAll()
.and()
.csrf().disable();

这应该只验证 swagger,但允许其余请求。

【讨论】:

    【解决方案2】:

    这是你的意图吗?

    protected void configure(HttpSecurity http) throws Exception {
    
        http.csrf().disable()
        .authorizeRequests()
            .antMatchers("/swagger*/**").authenticated()
            .anyRequest().permitAll();            
    
        http.httpBasic();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-20
      • 2017-11-06
      • 2019-08-10
      • 2016-01-31
      • 1970-01-01
      • 2020-08-22
      • 2013-06-07
      • 2014-03-07
      相关资源
      最近更新 更多