【问题标题】:How to separate authorization server spring security in java如何在java中分离授权服务器spring security
【发布时间】:2016-04-07 21:59:50
【问题描述】:

我已经开始学习 Spring Security (Oauth2)。我有一个受 Spring Oauth2 保护的 REST API 服务。我想要做的是,我想将授权服务器和资源服务器分开,例如,

我有 授权:http://server1:8080/RESTTest/oauth/token/grant_type=client_credentials&client_id=clientt&client_secret=secret

并且 资源 http://server1:8080/RESTTest/api/users/?access_token=2cf682c6-2900-47dc-a468-441fcee0dc18

我想要的是,

授权:http://Server1:8080/authorizationserver /oauth/token/grant_type=client_credentials&client_id=clientt&client_secret=secret

资源: http://server2:8080/RESTTest/api/users/?access_token=2cf682c6-2900-47dc-a468-441fcee0dc18

我正在使用 JDBCTokenstore。我不确定如何将其分开。有人能帮我吗。

谢谢,

【问题讨论】:

标签: java spring oauth-2.0 spring-security-oauth2


【解决方案1】:

您可以将自定义端点映射到提供的默认值,仅供参考 http://projects.spring.io/spring-security-oauth/docs/oauth2.html

@Configuration
    @EnableAuthorizationServer
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {

@Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {

            endpoints.tokenStore(tokenStore).userApprovalHandler(userApprovalHandler)
                    .authenticationManager(authenticationManager);
            endpoints.pathMapping("/oauth/token", "/authorizationserver/oauth/token")
        }

}

【讨论】:

  • 嗨,问题是我会将授权服务器和资源服务器部署为单独的实例。这意味着 server1 将拥有授权服务器,Server2 将拥有资源服务器
  • @Backtrack ,您应该能够以相同的方式扩展 AuthorizationServerConfigurerAdapter ,然后相应地映射路径,并且在您的客户端中,您必须提供新的授权服务器 URL。这里有很多例子github.com/spring-projects/spring-security-oauth
猜你喜欢
  • 2015-05-22
  • 2022-01-14
  • 2018-09-26
  • 2011-11-10
  • 2016-07-25
  • 2019-10-27
  • 2021-10-29
  • 2020-03-14
  • 2021-10-28
相关资源
最近更新 更多