小编典典

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

spring-mvc

我想重写CheckTokenEndpoint以提供我自己的自定义输出作为Map到资源服务器。我已经尝试了以下方法,但是无法正常工作。

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

用不同的定义覆盖bean’checkTokenEndpoint’的bean定义:替换[Generic bean:class
[com.datami.auth.security.CheckTokenEndpoint]; 作用域=单个 abstract = false;
lazyInit = false; autowireMode = 0; dependencyCheck = 0; autowireCandidate =
true; primary = 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]中定义[空值]; 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 =(推断); 在类路径资源[org / springframework / security / oauth2 /
config / annotation / web / configuration /
AuthorizationServerEndpointsConfiguration.class]中定义

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

@autowire
私有ResourceServerTokenServices resourceServerTokenServices;

Spring已使用进行自动连线DefaultTokenServices

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

private TokenStore tokenStore;

private ClientDetailsService clientDetailsService;

private TokenEnhancer accessTokenEnhancer;

private AuthenticationManager authenticationManager;

可乐,请帮帮我。


阅读 2155

收藏
2020-06-01

共1个答案

小编典典

CheckTokenEndpoint取决于其accessTokenConverter实例来创建和返回地图。

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

@Configuration
@EnableAuthorizationServer
public class MyAuthConfig extends AuthorizationServerConfigurerAdapter {

    ...

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

        ....

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

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

2020-06-01