[英]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.