@Bean
 @Primary
 public DefaultTokenServices tokenServices() {
   final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
   defaultTokenServices.setTokenStore(tokenStore());
   return defaultTokenServices;
 }
 @Bean
 public DefaultTokenServices tokenServices() {
   DefaultTokenServices tokenServices = new DefaultTokenServices();
   tokenServices.setTokenStore(tokenStore());
   tokenServices.setClientDetailsService(clientDetailsService());
   return tokenServices;
 }
 @Bean
 @ConditionalOnMissingBean(ResourceServerTokenServices.class)
 public ResourceServerTokenServices jwtTokenServices() {
   DefaultTokenServices services = new DefaultTokenServices();
   services.setTokenStore(jwtTokenStore());
   return services;
 }
 @Bean
 public ResourceServerTokenServices tokenServices() {
   final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
   defaultTokenServices.setTokenEnhancer(jwtTokenEnhancer());
   defaultTokenServices.setTokenStore(tokenStore());
   return defaultTokenServices;
 }
 @Bean
 @Primary
 public DefaultTokenServices tokenServices() {
   DefaultTokenServices tokenServices = new DefaultTokenServices();
   tokenServices.setSupportRefreshToken(true);
   tokenServices.setTokenStore(this.tokenStore);
   return tokenServices;
 }
 @Bean
 public DefaultTokenServices tokenServices() {
   DefaultTokenServices services = new DefaultTokenServices();
   services.setClientDetailsService(clientDetailsService);
   services.setSupportRefreshToken(true);
   services.setTokenStore(new InMemoryTokenStore());
   return services;
 }
 @Bean
 @Primary
 public DefaultTokenServices tokenServices() {
   DefaultTokenServices tokenServices = new DefaultTokenServices();
   tokenServices.setSupportRefreshToken(true);
   tokenServices.setTokenStore(getTokenStore());
   tokenServices.setTokenEnhancer(tokenEnhancer());
   return tokenServices;
 }
 @Bean
 public DefaultTokenServices tokenServices(
     InMemoryTokenStore tokenStore, ClientDetailsService jpaUserCredentialsService) {
   DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
   defaultTokenServices.setTokenStore(tokenStore);
   defaultTokenServices.setSupportRefreshToken(true);
   defaultTokenServices.setClientDetailsService(jpaUserCredentialsService);
   return defaultTokenServices;
 }
  @Test
  public void testAuthorizationCodeGrant() {

    Authentication userAuthentication =
        new UsernamePasswordAuthenticationToken(
            "marissa", "koala", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));

    parameters.clear();
    parameters.put(OAuth2Utils.CLIENT_ID, "foo");
    parameters.put(OAuth2Utils.SCOPE, "scope");
    OAuth2Request storedOAuth2Request =
        RequestTokenFactory.createOAuth2Request(
            parameters, "foo", null, true, Collections.singleton("scope"), null, null, null);

    String code =
        authorizationCodeServices.createAuthorizationCode(
            new OAuth2Authentication(storedOAuth2Request, userAuthentication));
    parameters.putAll(storedOAuth2Request.getRequestParameters());
    parameters.put("code", code);

    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters);

    AuthorizationCodeTokenGranter granter =
        new AuthorizationCodeTokenGranter(
            providerTokenServices, authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    assertTrue(providerTokenServices.loadAuthentication(token.getValue()).isAuthenticated());
  }
 @Test
 public void testSunnyDay() {
   ResourceOwnerPasswordTokenGranter granter =
       new ResourceOwnerPasswordTokenGranter(
           authenticationManager, providerTokenServices,
           clientDetailsService, requestFactory);
   OAuth2AccessToken token = granter.grant("password", tokenRequest);
   OAuth2Authentication authentication =
       providerTokenServices.loadAuthentication(token.getValue());
   assertTrue(authentication.isAuthenticated());
 }
  public ResourceOwnerPasswordTokenGranterTests() {
    String clientId = "client";
    BaseClientDetails clientDetails = new BaseClientDetails();
    clientDetails.setClientId(clientId);

    providerTokenServices.setTokenStore(new InMemoryTokenStore());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("username", "foo");
    parameters.put("password", "bar");
    parameters.put("client_id", clientId);

    tokenRequest = requestFactory.createTokenRequest(parameters, clientDetails);
  }
 public TestAuthorizationCodeTokenGranter() {
   providerTokenServices.setTokenStore(new InMemoryTokenStore());
 }