私は認可にspring oauth2を使用しています。私は、トークンをリフレッシュしようとするとエラーが発生することを発見しました:UserDetailsServiceが必要です(興味深いことに、このエラーはUNIXマシンとWindows上でのみ発生します)。私はspring oauth2 version 2.0.7を使用しています。私は問題をローカライズすることができました。何らかの理由でDefaultTokenServiceのAuthenticationManagerが空ではなく、ユーザーがまだ存在するかどうかを確認するためにユーザーを認証しようとします。私はそれがいくつかの春のセキュリティ対春のoauth2構成の問題のために初期化されると思います。私はカスタムUserDetailsServiceを使用していないので、この時点でユーザーを認証すべきではありません。しかし、私はそれをデバッグするとき、WebSecurityConfigurerAdapterからのものを使用しようとし、このエラーになることがわかります。カスタムダミーのUserDetailsServiceを提供しても、そのカスタムダミーを使用していませんが、もう1つ、つまりnullを使用しようとします。私はここに何かを逃していますかなぜこれが起こっているのか分からないのですか?春のセキュリティを使用してリフレッシュ・トークン呼び出しが失敗しました。エラーのあるoauth2: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 InMemoryTokenStore();
}
}
私の春のセキュリティ設定
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.antMatchers("/myRest/events/**", "/events/**", "/events", "/myRest/events").permitAll()
.antMatchers("/login.jsp", "/login").permitAll()
.and()
.csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize")).disable()
.csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("/myRest/events")).disable()
.sessionManagement().sessionFixation().none();
// @formatter:on
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/index*", "/myRest/events/**", "/events/**", "/myRest/events", "/events", "/swagger/**", "/kibana/**",
"/elastic/**", "/version/**", "/api-docs/**", "/js/**", "/oauth/uncache_approvals", "/oauth/cache_approvals");
}
}
いいえ、それは真実ではありません。 Oauth2構成にはそのサービスは必要ありませんが、空のままにすることもできます。私はそのサービスの実装を提供しようとしましたが、同じ例外が投げられました。私はすでにこの問題を解決しました。問題は構成の順序(いくつかのオブジェクトがあるため)でした。 OAuth2構成の順序を100に、Webセキュリティ構成を101に設定しました。このようにして動作します。 –