Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将spring oauth db从inmemory迁移到jdbc_Java_Spring_Jdbc_Oauth - Fatal编程技术网

Java 将spring oauth db从inmemory迁移到jdbc

Java 将spring oauth db从inmemory迁移到jdbc,java,spring,jdbc,oauth,Java,Spring,Jdbc,Oauth,我正在尝试向java rest服务添加oauth2支持 我设法让它在内存中工作: protected static class MyAuthorizationServerConfigurerAdapter extends AuthorizationServerConfigurerAdapter { ... @Override public void configure(ClientDetailsServiceConfigurer clients) thro

我正在尝试向java rest服务添加oauth2支持

我设法让它在内存中工作:

protected static class MyAuthorizationServerConfigurerAdapter extends
            AuthorizationServerConfigurerAdapter {
...
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients
            .inMemory()
                .withClient("myapp")
                    .authorizedGrantTypes("password", "refresh_token")
                    .authorities("USER")
                    .scopes("read", "write")
                    .resourceIds(RESOURCE_ID)
                    .secret("mysecret");
        }
...
    }
问题是,每次服务器重新启动时,数据库都会丢失。 所以我想把它和现有的独立SQL数据库连接起来,有什么想法或指南吗

我发现有一个jdbc选项,但我找不到一种方法使它工作

clients.jdbc(dataSource)

谢谢

您确定要将客户端配置放入数据库中吗?这只允许您动态配置新客户端

我认为您需要的是将令牌保存在数据库中,这样,如果重新启动服务器,客户端就不会丢失会话

这可以通过以下代码实现:

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception }
    endpoints.tokenStore(new JdbcTokenStore(dataSource)).userApprovalHandler(userApprovalHandler)
                    .authenticationManager(authenticationManager);
}
以下是创建数据库表的代码:

CREATE TABLE `oauth_access_token` (
  `token_id` varchar(255) DEFAULT NULL,
  `token` blob,
  `authentication_id` varchar(255) DEFAULT NULL,
  `user_name` varchar(255) DEFAULT NULL,
  `client_id` varchar(255) DEFAULT NULL,
  `authentication` blob,
  `refresh_token` varchar(255) DEFAULT NULL
);

CREATE TABLE `oauth_refresh_token` (
  `token_id` varchar(256) DEFAULT NULL,
  `token` blob,
  `authentication` blob
);

来源:

我也想把令牌放在db中,但这将是下一步,把它们放在一起会更好