为一个请求禁用基本身份验证(Spring 安全性),并保留所有请求



如何禁用一个请求的基本身份验证并将其保留给所有请求。 我尝试这样做,但这些对 mi 不起作用。

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/registration").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated().and().httpBasic();
}

基本身份验证仍然适用于"/注册"。

我假设/registration是您创建的网页。那么应该是

http.csrf()
.disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET,"/registration")
.permitAll()
.anyRequest()
.authenticated()

如果它是 API 端点而不是网页,则应使用HttpMethod.POST,或者出于某种原因,如果您也有对/registrationPOST请求,则将HttpMethod.GET全部删除,/registration留在antMatchers

最新更新