Package org.springframework.security.oauth2.common

Examples of org.springframework.security.oauth2.common.OAuth2AccessToken


  public void testNewTokenAcquiredIfExpired() throws Exception {
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
    token.setExpiration(new Date(System.currentTimeMillis() - 1000));
    restTemplate.getOAuth2ClientContext().setAccessToken(token);
    restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
    OAuth2AccessToken newToken = restTemplate.getAccessToken();
    assertNotNull(newToken);
    assertTrue(!token.equals(newToken));
  }
View Full Code Here


          AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
        throw new UserRedirectRequiredException("http://foo.com", Collections.<String, String> emptyMap());
      }
    });
    try {
      OAuth2AccessToken newToken = restTemplate.getAccessToken();
      assertNotNull(newToken);
      fail("Expected UserRedirectRequiredException");
    }
    catch (UserRedirectRequiredException e) {
      // planned
View Full Code Here

   * tests the basic provider
   */
  @Test
  @OAuth2ContextConfiguration(ClientCredentials.class)
  public void testPostForToken() throws Exception {
    OAuth2AccessToken token = context.getAccessToken();
    assertNull(token.getRefreshToken());
  }
View Full Code Here

   * tests that the registered scopes are used as defaults
   */
  @Test
  @OAuth2ContextConfiguration(NoScopeClientCredentials.class)
  public void testPostForTokenWithNoScopes() throws Exception {
    OAuth2AccessToken token = context.getAccessToken();
    assertFalse("Wrong scope: " + token.getScope(), token.getScope().isEmpty());
  }
View Full Code Here

        expectedAuthentication);
    OAuth2RefreshToken expectedExpiringRefreshToken = firstAccessToken.getRefreshToken();
    // Make it expire (and rely on mutable state in volatile token store)
    firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    // create another access token
    OAuth2AccessToken secondAccessToken = getTokenServices().createAccessToken(expectedAuthentication);
    assertFalse("The new access token should be different",
        firstAccessToken.getValue().equals(secondAccessToken.getValue()));
    assertEquals("The new access token should have the same refresh token",
        expectedExpiringRefreshToken.getValue(), secondAccessToken.getRefreshToken().getValue());
    // refresh access token with refresh token

    TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id",
        Collections.singleton("read"), null);
    getTokenServices().refreshAccessToken(expectedExpiringRefreshToken.getValue(), tokenRequest);
View Full Code Here

   
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
       
    AuthorizationCodeTokenGranter granter = new AuthorizationCodeTokenGranter(providerTokenServices,
        authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    assertTrue(providerTokenServices.loadAuthentication(token.getValue()).isAuthenticated());
  }
View Full Code Here

    parameters.put("code", code);
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
   
    AuthorizationCodeTokenGranter granter = new AuthorizationCodeTokenGranter(providerTokenServices,
        authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    OAuth2Request finalRequest = providerTokenServices.loadAuthentication(token.getValue())
        .getOAuth2Request();
    assertEquals(code, finalRequest.getRequestParameters().get("code"));
    assertEquals("bar", finalRequest.getRequestParameters().get("foo"));
  }
View Full Code Here

    parameters.put(OAuth2Utils.SCOPE, "read write");
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
   
    AuthorizationCodeTokenGranter granter = new AuthorizationCodeTokenGranter(providerTokenServices,
        authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    OAuth2Request finalRequest = providerTokenServices.loadAuthentication(token.getValue())
        .getOAuth2Request();
    assertEquals("[read]", finalRequest.getScope().toString());
    assertEquals("[resource]", finalRequest.getResourceIds().toString());
    assertTrue(finalRequest.isApproved());
  }
View Full Code Here

        storedOAuth2Request, userAuthentication));
    parameters.put("code", code);
    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters, client);
    AuthorizationCodeTokenGranter granter = new AuthorizationCodeTokenGranter(providerTokenServices,
        authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    assertTrue(providerTokenServices.loadAuthentication(token.getValue()).isAuthenticated());
  }
View Full Code Here

        result.setRefreshToken(refreshToken);
        return result;
      }
    });
    OAuth2Authentication authentication = createAuthentication();
    OAuth2AccessToken original = getTokenServices().createAccessToken(authentication);
    assertTrue(original.getRefreshToken().equals(refreshToken));
    OAuth2AccessToken result = getTokenStore().getAccessToken(authentication);
    assertEquals(original, result);
    assertEquals(refreshToken, result.getRefreshToken());
    assertEquals(refreshToken, getTokenStore().readRefreshToken(refreshToken.getValue()));
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth2.common.OAuth2AccessToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.