【问题标题】:Spring OAUTH: Override CheckTokenEndpoint 'check_token?token=' response mapSpring OAUTH:覆盖 CheckTokenEndpoint 'check_token?token=' 响应映射
【发布时间】:2018-05-04 11:21:31
【问题描述】:

我想覆盖 CheckTokenEndpoint 以将我自己的自定义输出作为 Map 提供给资源服务器。我尝试了以下方法,但没有工作。

  1. 为 (/oauth/check_token) 引入新的自定义控制器,但 Spring 拒绝此自定义并注册它自己的。

用 bean 'checkTokenEndpoint' 覆盖 bean 定义 不同的定义:替换[通用bean:类 [com.datami.auth.security.CheckTokenEndpoint];范围=单例; 摘要=假;懒惰初始化=假;自动线模式=0;依赖检查=0; 自动接线候选=真;主要=假;工厂BeanName=空; 工厂方法名=空;初始化方法名=空;销毁方法名=空; 在文件中定义 [/usr/local/Cellar/tomcat/8.5.5/libexec/webapps/oauth-server/WEB-INF/classes/com/datami/auth/security/CheckTokenEndpoint.class]] 与 [根 bean: 类 [null];范围=;摘要=假;懒惰初始化=假; 自动线模式=3;依赖检查=0;自动接线候选=真; 主要=假; factoryBeanName=org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; factoryMethodName=checkTokenEndpoint;初始化方法名=空; destroyMethodName=(推断);在类路径资源中定义 [org/springframework/security/oauth2/config/annotation/web/configuration/AuthorizationServerEndpointsConfiguration.class]]

  1. 使用 (/oauth/check_custom_token) 创建了我自己的端点,但不确定下面的自动装配 resourceServerTokenServices,@autowire 没有帮助我。

    @autowire
    私有资源服务器令牌服务资源服务器令牌服务;

Spring 已使用 DefaultTokenServices 自动连接。

我也可以在我的代码中创建new DefaultTokenServices(),但是如何在 DefaultTokenServices 中自动装配以下内容?又是同样的问题。

private TokenStore tokenStore;

private ClientDetailsService clientDetailsService;

private TokenEnhancer accessTokenEnhancer;

private AuthenticationManager authenticationManager; 

请你帮帮我。

【问题讨论】:

    标签: spring spring-mvc spring-security oauth spring-security-oauth2


    【解决方案1】:

    CheckTokenEndpoint 依赖其accessTokenConverter 实例来创建和返回地图。

    您可以创建一个自定义 AccessTokenConverter(如果需要,可以从 OOTB DefaultAccessTokenConverter 扩展)并像这样使用它:

    @Configuration
    @EnableAuthorizationServer
    public class MyAuthConfig extends AuthorizationServerConfigurerAdapter {
    
        ...
    
        @Override
        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
            endpoints.accessTokenConverter(new MyAccessTokenConverter())...
    
            ....
    

    当然,您可能希望使用工厂方法来创建您的 accessTokenConverter 实例,它允许您将一些属性注入实例等。

    完成后,在AuthorizationServerEndpointsConfiguration.checkTokenEndpoint 内部,您可以看到您上面设置的accessTokenConverter 将被传递给CheckTokenEndpoint 的OOTB 实例并用于创建地图。

    【讨论】:

      猜你喜欢
      • 2017-12-07
      • 2013-06-14
      • 2020-06-30
      • 2020-09-05
      • 2014-09-29
      • 2021-07-01
      • 2021-03-15
      • 2015-11-10
      • 1970-01-01
      相关资源
      最近更新 更多