如何禁用一个请求的基本身份验证并将其保留给所有请求。 我尝试这样做,但这些对 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
,或者出于某种原因,如果您也有对/registration
的POST
请求,则将HttpMethod.GET
全部删除,/registration
留在antMatchers