DirectAccessGrantUserDetailsAuthenticationProvider extends DirectAccessGrantAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) super.authenticate(authentication); String username; UserDetails userDetails; if (token == null) { return null; } username = this.resolveUsername(token); userDetails = userDetailsService.loadUserByUsername(username); return new KeycloakUserDetailsAuthenticationToken(userDetails, token.getAccount(), token.getAuthorities()); }  @Override Authentication authenticate(Authentication authentication); @Required void setUserDetailsService(UserDetailsService userDetailsService);  }
@Ignore @Test public void testAuthenticate() throws Exception { Authentication authentication = provider.authenticate(token); assertNotNull(authentication); assertTrue(authentication.isAuthenticated()); }