我想重写 CheckTokenEndpoint 以将我自己的自定义输出作为 Map 提供给资源服务器。我已经尝试过以下方法,但不起作用。
- 为 (/oauth/check_token) 引入新的自定义 Controller ,但 Spring 拒绝此自定义并注册自己的 Controller 。
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]]
使用 (
/oauth/check_custom_token
) 创建了我自己的端点,但不确定下面的 Autowiring ResourceServerTokenServices,@autowire 对我没有帮助。@autowire
私有(private)ResourceServerTokenServices资源服务器 token 服务;
Spring 已使用 DefaultTokenServices
Autowiring 此功能。
我还可以在代码中创建 new DefaultTokenServices()
,但是如何在 DefaultTokenServices 中 Autowiring 以下内容?又是同样的问题。
private TokenStore tokenStore;
private ClientDetailsService clientDetailsService;
private TokenEnhancer accessTokenEnhancer;
private AuthenticationManager authenticationManager;
你能帮我一下吗?
最佳答案
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 实例,它允许您将一些属性注入(inject)实例等。
完成后,在 AuthorizationServerEndpointsConfiguration.checkTokenEndpoint
中,您可以看到上面设置的 accessTokenConverter 将被传递到 CheckTokenEndpoint
的 OOTB 实例,并用于创建 map 。
关于 Spring OAUTH : Override CheckTokenEndpoint 'check_token?token=' response map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47405585/