首页 文章

Spring OAUTH:覆盖CheckTokenEndpoint 'check_token?token='响应映射

提问于
浏览
1

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

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

使用不同的定义覆盖bean'checkTokenEndpoint'的bean定义:replacement [Generic bean:class [com.datami.auth.security.CheckTokenEndpoint];范围=单;抽象= FALSE; lazyInit = FALSE; autowireMode = 0; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = NULL; factoryMethodName = NULL; initMethodName = NULL; destroyMethodName = NULL;使用[root bean:class]在文件[/usr/local/Cellar/tomcat/8.5.5/libexec/webapps/oauth-server/WEB-INF/classes/com/datami/auth/security/CheckTokenEndpoint.class]中定义[空值];范围=;抽象= FALSE; lazyInit = FALSE; autowireMode = 3; dependencyCheck = 0; autowireCandidate = TRUE;初级= FALSE; factoryBeanName = org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; factoryMethodName = checkTokenEndpoint; initMethodName = NULL; destroyMethodName =(推断);在类路径资源中定义[org / springframework / security / oauth2 / config / annotation / web / configuration / AuthorizationServerEndpointsConfiguration.class]]

  • 使用( /oauth/check_custom_token )创建了我自己的 endpoints 但不确定自动装配下面的resourceServerTokenServices,@ usowire对我没有帮助 .

@autowire
private ResourceServerTokenServices resourceServerTokenServices;

Spring用 DefaultTokenServices 自动启动了这个 .

我也可以在我的代码中创建 new DefaultTokenServices() ,但是如何在DefaultTokenServices内部自动装配?再次出现同样的问题 .

private TokenStore tokenStore;

private ClientDetailsService clientDetailsService;

private TokenEnhancer accessTokenEnhancer;

private AuthenticationManager authenticationManager;

请你帮帮我吧 .

1 回答

  • 2

    CheckTokenEndpoint 依赖于其 accessTokenConverter 实例来创建和返回 Map .

    您可以创建一个自定义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实例并用于创建 Map .

相关问题