我如何禁用一个请求的基本身份验证,并保留所有请求的身份验证。 我尝试做,但是这些不适用于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”。
答案 0 :(得分:2)
我假设/registration
是您创建的网页。那应该是
http.csrf()
.disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET,"/registration")
.permitAll()
.anyRequest()
.authenticated()
如果HttpMethod.POST
是API端点而不是网页,则应使用POST
,或者如果出于某些原因,如果您也有/registration
的{{1}}请求,请删除{{ 1}}在一起,只是将HttpMethod.GET
留在/registration