UserTokenGranter extends AbstractTokenGranter { @Override protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest tokenRequest) { ClientDetails receivingClient = clientDetailsService.loadClientByClientId(tokenRequest.getRequestParameters().get(CLIENT_ID), IdentityZoneHolder.get().getId()); return prepareForSerialization((DefaultOAuth2AccessToken) super.getAccessToken(receivingClient, tokenRequest)); } UserTokenGranter(AuthorizationServerTokenServices tokenServices,
                            MultitenantClientServices clientDetailsService,
                            OAuth2RequestFactory requestFactory,
                            RevocableTokenProvisioning tokenStore); @Override OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest);  }
@Test public void ensure_client_gets_swapped() { granter = new UserTokenGranter( tokenServices, clientDetailsService, requestFactory, tokenStore ) { @Override protected DefaultOAuth2AccessToken prepareForSerialization(DefaultOAuth2AccessToken token) { return null; } @Override protected Authentication validateRequest(TokenRequest request) { return userAuthentication; } }; granter.getAccessToken(requestingClient, tokenRequest); verify(clientDetailsService, times(1)).loadClientByClientId(eq(receivingClient.getClientId()), anyString()); }