如何只保护一个带弹簧安全的网址并允许所有网址

时间:2017-07-27 15:17:36

标签: java spring-security springfox

我试图将Spring安全性配置为仅阻止请求swagger,但它阻止所有URL。 有谁知道如何只锁定昂首阔步的网址并让所有其他网址不安全?

protected void configure(HttpSecurity http) throws Exception {

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

        http.httpBasic();
    }

2 个答案:

答案 0 :(得分:2)

尝试以下方法:

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

这应该只验证招摇,但允许其余的请求。

答案 1 :(得分:-1)

这是你的意图吗?

protected void configure(HttpSecurity http) throws Exception {

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

    http.httpBasic();
}
相关问题