【问题标题】:Use @EnableResourceServer with custom Authorization Provider将 @EnableResourceServer 与自定义授权提供程序一起使用
【发布时间】:2018-02-28 03:44:19
【问题描述】:

我正在尝试查找需要实现哪些类才能使用 @EnableResourceServer 注释并与我们的自定义 OAuth2 服务器和令牌存储进行交互。

我们的目标是将其打包为一个库并在其他服务之间共享。所以基本上我需要实现:

  1. 自定义令牌端点。
  2. 自定义刷新端点。
  3. 自定义令牌验证过滤器(以避免调用 /check_token 因为我们使用的是 JWT,所以我们只需确保令牌已正确签名即可。
  4. 在 Redis 中保存令牌(在资源服务上)
  5. 用于检索用户信息的自定义端点。

到目前为止,我已经看过以下课程:

  1. TokenEndpoint
  2. RefreshTokenGranter
  3. OAuth2AuthenticationProcessingFilter

但是由于我找不到太多文档,我想知道我是否有点迷失了,或者这些类不打算被覆盖,最好创建我的自定义逻辑而不是依赖@EnableResourceServer

【问题讨论】:

    标签: spring-boot spring-security spring-security-oauth2


    【解决方案1】:

    我相信您可能想从ResourceServerSecurityConfigurerResourceServerConfigurerAdapter 开始寻找。这遵循与WebSecurityConfigurerAdapter 类似的编程模型,将为您提供一些可以配置的上下文。

    从那里,查看 ResourceServerTokenServicesTokenStore 的第 1、3、4 和 5 点。

    现在,关于 #2,由于您还希望应用程序刷新令牌,听起来您可能想要创建两个库,一个用于想要使用 OAuth2 (@EnableResourceServer) 授权请求的服务,另一个用于想要处理这些资源服务器的服务 (@EnableOAuthClient)。在这种情况下,还请查看OAuth2RestTemplateClientTokenServices

    另外,如果你还没有看http://projects.spring.io/spring-security-oauth/docs/oauth2.html,因为这是我从上面提取大部分内容的地方。

    https://github.com/spring-projects/spring-security-oauth/tree/master/samples/oauth2 中的一些示例可能会对资源服务器端有所帮助,特别是 https://github.com/spring-projects/spring-security-oauth/blob/master/samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig.java

    https://github.com/spring-projects/spring-security-oauth/blob/master/tests/annotation/client/src/main/java/client/ClientApplication.java有一个客户的例子

    希望有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      相关资源
      最近更新 更多