相关疑难解决方法(0)

使用Spring Security OAuth2刷新令牌调用失败,并出现以下错误:UserDetailsS​​ervice是必需的

我正在使用Spring Security OAuth2进行授权。尝试刷新令牌时,出现错误:(UserDetailsService is required有趣的是,我仅在UNIX计算机上而不是Windows上收到此错误)。我正在使用Spring OAuth2版本2.0.7。

由于某种原因,中的AuthenticationManagerin DefaultTokenService不为空,它尝试对用户进行身份验证以检查其是否仍然存在。我认为它由于一些春季安全性与春季oauth2配置问题而被初始化。

我没有使用任何自定义UserDetailsService,因此此时它不应该对用户进行身份验证。但是,当我调试它时,我看到它尝试使用中的一个WebSecurityConfigurerAdapter并得到此错误。即使我提供了自定义的虚拟对象UserDetailsService,它也没有使用该虚拟对象,而是尝试使用另一个虚拟对象,这是空的。我在这里想念什么吗?我不知道为什么会这样?

这是我的Oauth2配置

@Configuration
@EnableAuthorizationServer
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private MySpringTokenStore tokenStore;

    @Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private MyClientDetailsServiceImpl clientDetailsService;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.tokenStore(tokenStore);
        endpoints.authenticationManager(authenticationManager)
          .approvalStoreDisabled();
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.withClientDetails(clientDetailsService);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.allowFormAuthenticationForClients();
    }

    @Bean
    public TokenStore tokenStore() {
        return new …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-security-oauth2 spring-oauth2

5
推荐指数
1
解决办法
3544
查看次数