Spring OAUTH:覆盖 CheckTokenEndpoint 'check_token?token=' 响应映射
Spring OAUTH: Override CheckTokenEndpoint 'check_token?token=' response map
我想覆盖 CheckTokenEndpoint 以将我自己的自定义输出作为映射提供给资源服务器。我尝试了以下方法,但没有用。
- 为 (/oauth/check_token) 引入新的自定义控制器,但 Spring 拒绝此自定义并注册自己的。
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
) 创建了我自己的端点,但不确定下面的自动装配 resourceServerTokenServices,@autowire 没有帮助我。
@autowire
私有 ResourceServerTokenServices resourceServerTokenServices;
Spring 已使用 DefaultTokenServices
.
自动装配它
我也可以在我的代码中创建 new DefaultTokenServices()
,但是如何在 DefaultTokenServices 中自动装配以下内容?又是同样的问题。
private TokenStore tokenStore;
private ClientDetailsService clientDetailsService;
private TokenEnhancer accessTokenEnhancer;
private AuthenticationManager authenticationManager;
你能帮帮我吗
CheckTokenEndpoint
取决于要创建的 accessTokenConverter
实例和 return 地图。
您可以创建一个自定义的 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 实例并用于创建地图。
我想覆盖 CheckTokenEndpoint 以将我自己的自定义输出作为映射提供给资源服务器。我尝试了以下方法,但没有用。
- 为 (/oauth/check_token) 引入新的自定义控制器,但 Spring 拒绝此自定义并注册自己的。
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
) 创建了我自己的端点,但不确定下面的自动装配 resourceServerTokenServices,@autowire 没有帮助我。@autowire
私有 ResourceServerTokenServices resourceServerTokenServices;
Spring 已使用 DefaultTokenServices
.
我也可以在我的代码中创建 new DefaultTokenServices()
,但是如何在 DefaultTokenServices 中自动装配以下内容?又是同样的问题。
private TokenStore tokenStore;
private ClientDetailsService clientDetailsService;
private TokenEnhancer accessTokenEnhancer;
private AuthenticationManager authenticationManager;
你能帮帮我吗
CheckTokenEndpoint
取决于要创建的 accessTokenConverter
实例和 return 地图。
您可以创建一个自定义的 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 实例并用于创建地图。