Spring OAUTH:覆盖 CheckTokenEndpoint 'check_token?token=' 响应映射 [英] Spring OAUTH: Override CheckTokenEndpoint 'check_token?token=' response map

查看:330
本文介绍了Spring OAUTH:覆盖 CheckTokenEndpoint 'check_token?token=' 响应映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<块引用>

用一个覆盖 bean 'checkTokenEndpoint' 的 bean 定义不同的定义:替换 [Generic bean: class[com.datami.auth.security.CheckTokenEndpoint];范围=单例;抽象=假;懒惰初始化=假;autowireMode=0;依赖检查=0;autowireCandidate=真;主要=假;factoryBeanName=null;工厂方法名=空;initMethodName=null;destroyMethodName=null;在文件中定义[/usr/local/Cellar/tomcat/8.5.5/libexec/webapps/oauth-server/WEB-INF/classes/com/datami/auth/security/CheckTokenEndpoint.class]]与 [根豆:类 [null];范围=;抽象=假;懒惰初始化=假;autowireMode=3;依赖检查=0;autowireCandidate=真;主要=假;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]]

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

    @autowire
    private ResourceServerTokenServices resourceServerTokenServices;

Spring 已经使用 DefaultTokenServices 自动装配了它.

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

私有TokenStore tokenStore;私有 ClientDetailsS​​ervice clientDetailsS​​ervice;私有 TokenEnhancer 访问令牌增强器;私有 AuthenticationManager authenticationManager;

你能帮帮我吗.

解决方案

CheckTokenEndpoint 依赖于它的 accessTokenConverter 实例来创建和返回地图.

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

@Configuration@EnableAuthorizationServer公共类 MyAuthConfig 扩展 AuthorizationServerConfigurerAdapter {...@覆盖public void configure(AuthorizationServerEndpointsConfigurer endpoints) 抛出异常 {endpoints.accessTokenConverter(new MyAccessTokenConverter()).......

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

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

I would like to override the CheckTokenEndpoint to provide my own custom output as Map to the resource server. I have tried the following, but not working.

  1. Introducing new custom controller for (/oauth/check_token), but Spring rejects this custom and registers its own.

Overriding bean definition for bean 'checkTokenEndpoint' with a different definition: replacing [Generic bean: class [com.datami.auth.security.CheckTokenEndpoint]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/usr/local/Cellar/tomcat/8.5.5/libexec/webapps/oauth-server/WEB-INF/classes/com/datami/auth/security/CheckTokenEndpoint.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; factoryMethodName=checkTokenEndpoint; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/AuthorizationServerEndpointsConfiguration.class]]

  1. Created my own endpoint with (/oauth/check_custom_token) but not sure autowiring resourceServerTokenServices in the below, @autowire doesn't helped me.

    @autowire
    private ResourceServerTokenServices resourceServerTokenServices;

Spring has autowired this with DefaultTokenServices.

I can also create new DefaultTokenServices() in my code, but then how to autowire the below inside DefaultTokenServices? again the same problem.

private TokenStore tokenStore;

private ClientDetailsService clientDetailsService;

private TokenEnhancer accessTokenEnhancer;

private AuthenticationManager authenticationManager; 

Coul you please help me out.

解决方案

CheckTokenEndpoint depends on its accessTokenConverter instance to create and return the map.

You could create a custom AccessTokenConverter (maybe extending from OOTB DefaultAccessTokenConverter if needed) and use it like so:

@Configuration
@EnableAuthorizationServer
public class MyAuthConfig extends AuthorizationServerConfigurerAdapter {

    ...

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.accessTokenConverter(new MyAccessTokenConverter())...

        ....

Of course, you might want to use a factory method to create your accessTokenConverter instance, which allows you to inject a few properties into the instance etc.

Once done, inside AuthorizationServerEndpointsConfiguration.checkTokenEndpoint you can see that the accessTokenConverter you set above will be passed to the OOTB instance of CheckTokenEndpoint and used to create the map.

这篇关于Spring OAUTH:覆盖 CheckTokenEndpoint 'check_token?token=' 响应映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆