[英]Spring Security Http Basic not working showing Login Page
我有以下课程来初始化弹簧安全
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Autowired
private RemoteHttpAuthenticationProvider authProvider;
protected void configure(AuthenticationManagerBuilder auth) {
auth.authenticationProvider(authProvider);
}
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api/ping");
}
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated()
.and().httpBasic();
}
}
但是,这是显示登录页面而不是基本身份验证弹出窗口。 我需要基本身份验证,以便我可以通过 Postman 登录。
您必须返回值为“Basic”的响应头 WWW-Authenticate。
有关此响应标头的文档: https : //developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate
在下一个链接中有一个完整的例子:
https://memorynotfound.com/spring-security-basic-authentication-configuration-example/
您使登录页面需要进行身份验证,因此它没有显示。 这很容易解决,只需使 uri /login 不需要身份验证即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.