oauth-2.0 - 如何使用 Spring rest api 和 oauth 安全性从数据库中对用户进行身份验证
问题描述
我想使用 oauth2 实现 Rest api 安全性,并且我已经按照 this 使用静态用户数据实现了这种安全性。现在我想更改这种情况以使用 jdbc 对数据库中的数据进行身份验证,但直到现在我无法找到任何有关 jdbc 身份验证的教程。请向我推荐一些我的要求示例,我的要求是 Spring mvc Rest api+OAuth2+jdbc database+java-config 示例。
目前我已经用下面的静态用户进行了测试。
public void globalUserDetails(AuthenticationManagerBuilder auth) throws
Exception {
auth.inMemoryAuthentication()
.withUser("crmadmin").password("crmpass").roles("ADMIN","USER").and()
.withUser("crmuser").password("pass123").roles("USER");
}
解决方案
我认为您可以将其配置如下:将下面的代码放在扩展 WebSecurityConfigurerAdapter 的类中
@Autowired
private DataSource securityDataSource; // from Bean where you have connection, jdbc driver set up for database containing login information
@覆盖
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(securityDataSource);
}
推荐阅读
- machine-learning - 如果我在做一个多分类问题,catboost 中的 loss function='Multiclass' 是否与 log loss 相同?
- c++ - std::stringstream 和 getline 在文件末尾减慢
- javascript - 有没有办法允许自动音频播放(报警网站)
- java - Spring-Boot @Autowired 变量为空
- javascript - React Router 组件未加载但成功重定向
- java - 从 CSV 文件中获取未命名的列数据
- r - 为什么 R 使用系统 tar,而不是 Rtools tar?
- bots - 如何让我的不和谐机器人对随机表情符号做出反应?
- javascript - 在 React JSX 对象中设置背景图像 URL 的正确方法
- javascript - 在 Jquery 中,如何使用 id 提醒常规元素的值?