spring - 传递一个角色来验证来自邮递员的基本 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");
}
解决方案
您不需要像您使用角色设置的Role
那样从 Postman 请求传递,因此您定义的路径可以通过角色访问,如果您尝试由该用户调用端点,您将可以作为“用户”访问,因为角色在您的记忆中用户将在基本身份验证中进行身份验证。inMemoryAuthentication
user
"ADMIN"
ADMIN
"ADMIN"
因此,从 Postman 只需选择Basic Auth
并传递user as user
,password as password
您将能够调用已定义为访问的那些端点"hasRole = ADMIN.
。
推荐阅读
- node.js - CLI 程序不做任何事情并忽略我的代码
- excel - 从 Excel 到 Act 的 OLEDB 连接出错
- python - 如何更改 Python matplotlib 补丁多边形中边缘线的不透明度/透明度(alpha)?
- bluetooth-lowenergy - 带蓝牙低功耗的 MbedTLS
- firebase - Firebase 在哪里存储用户是否通过电子邮件验证
- html - html 5表中的文本溢出列
- c++ - 你能切换一个 std::any.type() 吗?
- python - 如何将缓存设置导入views.py
- code-generation - Faktor-IPS 代码生成器删除注释
- wordpress - 如何将自定义链接而不是 http 添加到 Wordpress 菜单?我想添加链接 viber://add?number=0000000000