首页 > 解决方案 > 传递一个角色来验证来自邮递员的基本 http

问题描述

我正在使用Spring boot security并定义内存身份验证中的用户进行身份验证,http basic但我没有看到Postman传递用户角色的选项,所以我的问题是如何postman为所有请求传递角色?

 public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
          .withUser("user").password(passwordEncoder().encode("passowrd"))
          .authorities("ADMIN");
    }

标签: springspring-bootspring-securitypostman

解决方案


您不需要像您使用角色设置的Role那样从 Postman 请求传递,因此您定义的路径可以通过角色访问,如果您尝试由该用户调用端点,您将可以作为“用户”访问,因为角色在您的记忆中用户将在基本身份验证中进行身份验证。inMemoryAuthenticationuser"ADMIN"ADMIN"ADMIN"

因此,从 Postman 只需选择Basic Auth并传递user as userpassword as password您将能够调用已定义为访问的那些端点"hasRole = ADMIN.


推荐阅读