简体   繁体   English

Spring Security Http Basic 无法显示登录页面

[英]Spring Security Http Basic not working showing Login Page

I have following class to initialize spring security我有以下课程来初始化弹簧安全

@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();

    }
}

But, this is showing login page instead of Basic Authentication Popup.但是,这是显示登录页面而不是基本身份验证弹出窗口。 I need Basic Auth, So that I can login it through Postman.我需要基本身份验证,以便我可以通过 Postman 登录。

在此处输入图片说明

Your must return the response header WWW-Authenticate with value "Basic".您必须返回值为“Basic”的响应头 WWW-Authenticate。

Documentation about this response header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate有关此响应标头的文档: https : //developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate

In the next link there is a complete example:在下一个链接中有一个完整的例子:

https://memorynotfound.com/spring-security-basic-authentication-configuration-example/ https://memorynotfound.com/spring-security-basic-authentication-configuration-example/

You make login page need to authenticated, so it didn't show.您使登录页面需要进行身份验证,因此它没有显示。 It's easy to resolve, just make uri /login not need authenticated.这很容易解决,只需使 uri /login 不需要身份验证即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM