KeycloakUserDetailsAuthenticationProvider extends KeycloakAuthenticationProvider { protected String resolveUsername(KeycloakAuthenticationToken token) { Assert.notNull(token, "KeycloakAuthenticationToken required"); Assert.notNull(token.getAccount(), "KeycloakAuthenticationToken.getAccount() cannot be return null"); OidcKeycloakAccount account = token.getAccount(); Principal principal = account.getPrincipal(); return principal.getName(); }  @Override Authentication authenticate(Authentication authentication); @Required void setUserDetailsService(UserDetailsService userDetailsService);  }
@Test public void testResolveUsername() throws Exception { assertEquals(KNOWN_USERNAME, provider.resolveUsername(token)); }