【问题标题】:How to authenticate user from database using Spring rest api and oauth security如何使用 Spring rest api 和 oauth 安全性对数据库中的用户进行身份验证
【发布时间】:2018-07-26 03:30:24
【问题描述】:

我想使用 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");
}

【问题讨论】:

    标签: oauth-2.0 spring-jdbc spring-restcontroller


    【解决方案1】:

    我认为你可以配置如下: 将下面的代码放在扩展 WebSecurityConfigurerAdapter 的类中

    @Autowired
    private DataSource securityDataSource; // from Bean where you have connection, jdbc driver set up for database containing login information
    

    @Override

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication().dataSource(securityDataSource);
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 1970-01-01
      • 2020-06-11
      • 1970-01-01
      • 2013-08-12
      • 2012-08-17
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      相关资源
      最近更新 更多