首页 > 解决方案 > Postman 应用程序的基本 HTTP 身份验证

问题描述

我无法理解一件特定的事情。我http-basic在我的服务器上使用身份验证。

我的代码是:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                    .authorizeRequests()
                    .antMatchers("/user/save")
                    .permitAll()
                .and()
                    .authorizeRequests()
                    .antMatchers("/user/**")
                    .hasRole("USER")
                .and()
                    .authorizeRequests()
                    .antMatchers("/admin/**")
                    .hasRole("ADMIN")
                .and()
                    .httpBasic()
                .and()
                    .logout()
                    .permitAll()
                .and()
                    .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
    }

我的请求映射/user是:

@GetMapping
public Principal user(Principal user){
    return user;
}

当我在邮递员应用程序/user中使用用户名和密码查询端点时,我得到了所需的认证结果。

但是,当我使用故意错误的密码更新标头时,我仍然得到经过身份验证的结果。我不明白为什么会这样。

此外,POST端点上的请求/logout失败并显示:

{
    "timestamp": "2018-07-30T07:42:48.172+0000",
    "status": 403,
    "error": "Forbidden",
    "message": "Forbidden",
    "path": "/logout"
}

我无法理解。任何帮助表示赞赏。

标签: spring-securitypostmanbasic-authentication

解决方案


推荐阅读