【问题标题】:Spring security permit all is not working for multiple urlsSpring security permit all 不适用于多个 url
【发布时间】:2020-10-09 11:53:50
【问题描述】:

我正在尝试将 permit all 授予多个 url,但我得到 403。当我禁用 csrf 时,所有请求都在没有身份验证的情况下工作。请在我的安全配置下方找到。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()//.anyRequest().permitAll()
                .antMatchers("/actuator/**","/v1/foo/link")
                .permitAll()
                .antMatchers("/**")
                .authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt(withDefaults());
    }
}

请纠正我遗漏的地方。谢谢。。

【问题讨论】:

    标签: java spring-boot microservices spring-security-oauth2


    【解决方案1】:

    我在提到的 stackoverflow 链接中找到了这个答案,它正在工作。

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/v1/foo/link").antMatchers("/v1/refer/link");
    }
    

    Spring Security exclude url patterns in security annotation configurartion

    【讨论】:

      猜你喜欢
      • 2021-03-25
      • 2017-06-09
      • 2015-11-03
      • 2015-10-02
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2020-12-02
      • 2016-04-16
      相关资源
      最近更新 更多