我使用 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();
}
}