Spring Boot 安全性不会绕过登录页面 URL

时间:2021-05-23 20:24:20

标签: spring-boot spring-security

我使用 OAuth2 作为安全令牌,但对于 /login /welcome 这样的几个 URL,我不希望它通过 OAuth2 令牌进行访问。我正在使用以下代码,但对于 /login/welcome,它都在询问令牌并返回 HTTP 状态 401。

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

         http
             .authorizeRequests()
                 .antMatchers(HttpMethod.POST, "/login").permitAll()
                 .antMatchers(HttpMethod.GET, "/login").permitAll()
                 .antMatchers(HttpMethod.GET, "/welcome").permitAll()
                 .anyRequest().authenticated();
     }
}

0 个答案:

没有答案