我自己实现了ClientDetailsService:
@Service
public class JpaClientDetailsService implements ClientDetailsService {
@Autowired
private ClientRepository clientRepositoy;
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
ClientDetails client = clientRepositoy.findOne(clientId);
if (client == null) {
throw new ClientRegistrationException(String.format("Client with id %s not found", clientId));
}
return client;
}
}
ClientRepository是标准的JpaRepository。
我配置了这样的AuthorizationServerConfigurerAdapter:
@Configuration
@EnableAuthorizationServer
@EnableResourceServer
public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private ClientDetailsService clientDetailsService;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(clientDetailsService);
}
}
但是当我去http://localhost:9999/oauth/authorize?response_type=code&client_id=lipton
时,我得到了一个
java.lang.StackOverflowError: null. Spring loops on com.sun.proxy.$Proxy81.loadClientByClientId(Unknown Source).
我不明白为什么。
答案 0 :(得分:8)
我不明白为什么,但是如果我直接注入我的bean而不是注入接口,它就可以工作:
public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {
...
@Autowired
private JpaClientDetailsService clientDetailsService;
...
如果我用@Primary注释注释我的服务,它也有效:
@Service
@Primary
public class JpaClientDetailsService implements ClientDetailsService {
答案 1 :(得分:6)
我有类似的问题。最后,当我向clientDetailsService提供另一个名称,即myClientDetailsService,然后在AuthorizationServerConfig类中按名称注入时,我解决了错误:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Resource(name = "myClientDetailsService")
private ClientDetailsService clientDetailsService;
...
我认为如果我自己的ClientDetailsService实现还没有创建Spring注入AuthorizationServerConfig某种代理。
所以,如果你想解决这种错误,你必须确定 Spring注入了适当的ClientDetailsService AuthorizationServerConfig。如果您:
,您可以实现这一目标答案 2 :(得分:2)
最终为我工作的是将ClientDetailsService @Bean添加到@EnableAuthorizationServer类:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration implements AuthorizationServerConfigurer {
...
@Autowired
ClientDetailsService clientDetailsService;
...
@Bean
public ClientDetailsService clientDetailsService() {
return new CustomClientDetailsServiceImpl();
}
...
}
答案 3 :(得分:0)
我想说最好的解决方案是明确的-如果您要自动装配clientDetailsService-那就这样。
ball.physicsBody?.velocity = CGVector(dx:velocityX, dy:velocityY)
但是,我的问题略有不同,并且上述解决方案无效。这是创建它的条件。 我创建了一个CustomTokenEndpointAuthenticationFilter-它需要一个OAuth2RequestFactory实例。 我通过调用endpoints.getOAuth2RequestFactory()创建了OAuth2RequestFactory实例。在设置clientDetailsService之前。
如果以这种方式创建OAuth2RequestFactory,则使用默认的clientDetailsService创建DefaultOAuth2RequestFactory,因此,即使您稍后稍后在AuthorizationServerEndpointsConfigurer中显式设置clientDetailsService,它也不会位于自定义过滤器使用的OAuth2RequestFactory中。
因此,在这种情况下
@Autowired
ClientDetailsService myClientDetailsService;
@Override
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.setClientDetailsService(myClientDetailsService);
....
}
无法工作,但是
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
oAuth2RequestFactory = endpoints.getOAuth2RequestFactory();
endpoints.setClientDetailsService(myClientDetailsService);
...
}
会。
另一种确定的方法是创建自己的OAuth2RequestFatory
public void configure(final AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.setClientDetailsService(myClientDetailsService);
oAuth2RequestFactory = endpoints.getOAuth2RequestFactory();
...
}
答案 4 :(得分:0)
我在我的服装 ClientDetailsService 中修复了这个注释 @Primary:
@Service
@Primary
public class ClientDetailsServiceImp implements ClientDetailsService {