spring-security - 我们可以在编写自定义身份验证提供程序时添加密码编码器吗?
问题描述
我是 Spring Security 的新手。我正在尝试编写我的自定义身份验证提供程序。它可以工作,但我找不到与它一起使用密码编码器的选项。
请指导。
我的代码位于https://github.com/payalbnsl/MvcSecurityCustomAuthenticationProvider
它是一个基本的 spring mvc 应用程序,只有一个使用我的自定义身份验证提供程序编写的 usernamepasswordtoken 类型的端点。我想在其中添加密码编码器。可能吗?
解决方案
您可以在客户提供商中创建密码编码器,而不是将编码器注入您自己的身份验证提供商。
但我认为没有必要写你自己的客户提供商,因为我读了你的CustomAuthenticationProvider
这很简单,你可以使用JdbcUserDetailsManager
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(datasource)
.usersByUsernameQuery("select username,password,1 "+ "from xxx " + "where username = ?")
.authoritiesByUsernameQuery("select username, role "+ "from xxx " + "where username = ?")
.passwordEncoder(passwordEncoder())
}
推荐阅读
- reactjs - 使用 Hooks 在 React 中获取 URL
- heroku - Heroku-kafka - log4j
- excel - 如何使用 vba 将来自两个单独数据表的单元格与特定请求结合起来
- actions-on-google - 在测验中,我怎样才能代替“说 A、B 或 C”让用户使用三个响应词之一?
- python - 如何修复错误“str”对象没有属性“relative_url”
- sql - 如何组合来自 SQL 查询的结果
- reactjs - 类型错误:_firebase__WEBPACK_IMPORTED_MODULE_4__.default.auth 不是函数
- javascript - 隐藏基于单选的问题集
- data-structures - 数据结构:什么是固定大小的数组与称为(双重)链表的组合?
- c++ - 指针初始化错误导致写访问冲突