Package org.springframework.security.oauth2.common

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


  /**
   * tests no double encoding of existing query parameter
   */
  @Test
  public void testNonEncodingOfUriTemplate() throws Exception {
    OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
    UriTemplate uriTemplate = new UriTemplate("https://graph.facebook.com/fql?q={q}");
    URI expanded = uriTemplate.expand("[q: fql]");
    URI appended = restTemplate.appendQueryParameter(expanded, token);
    assertEquals("https://graph.facebook.com/fql?q=%5Bq:%20fql%5D&bearer_token=12345", appended.toString());
  }
View Full Code Here


  /**
   * tests URI with fragment value
   */
  @Test
  public void testFragmentUri() throws Exception {
    OAuth2AccessToken token = new DefaultOAuth2AccessToken("1234");
    URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search#foo"), token);
    assertEquals("https://graph.facebook.com/search?bearer_token=1234#foo", appended.toString());
  }
View Full Code Here

   * tests encoding of access token value passed in protected requests ref: SECOAUTH-90
   */
  @Test
  public void testDoubleEncodingOfAccessTokenValue() throws Exception {
    // try with fictitious token value with many characters to encode
    OAuth2AccessToken token = new DefaultOAuth2AccessToken("1 qI+x:y=z");
    // System.err.println(UriUtils.encodeQueryParam(token.getValue(), "UTF-8"));
    URI appended = restTemplate.appendQueryParameter(URI.create("https://graph.facebook.com/search"), token);
    assertEquals("https://graph.facebook.com/search?bearer_token=1+qI%2Bx%3Ay%3Dz", appended.toString());
  }
View Full Code Here

  }

  @Test
  public void testRetryAccessDeniedException() throws Exception {
    final AtomicBoolean failed = new AtomicBoolean(false);
    restTemplate.getOAuth2ClientContext().setAccessToken(new DefaultOAuth2AccessToken("TEST"));
    restTemplate.setAccessTokenProvider(new StubAccessTokenProvider());
    restTemplate.setRequestFactory(new ClientHttpRequestFactory() {
      public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        if (!failed.get()) {
          failed.set(true);
View Full Code Here

    assertTrue(result);
  }

  @Test
  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

  @Test
  public void testExpiredToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    // Make it expire (and rely on mutable state in volatile token store)
    firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    expected.expect(InvalidTokenException.class);
    expected.expectMessage("expired");
    getTokenServices().loadAuthentication(firstAccessToken.getValue());
  }
View Full Code Here

    assertTrue(!token.equals(newToken));
  }

  @Test
  public void testTokenIsResetIfInvalid() throws Exception {
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
    token.setExpiration(new Date(System.currentTimeMillis() - 1000));
    restTemplate.getOAuth2ClientContext().setAccessToken(token);
    restTemplate.setAccessTokenProvider(new StubAccessTokenProvider() {
      @Override
      public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details,
          AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
View Full Code Here

  @Test
  public void testExpiredRefreshToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNotNull(firstAccessToken.getRefreshToken());
    // Make it expire (and rely on mutable state in volatile token store)
    ReflectionTestUtils.setField(firstAccessToken.getRefreshToken(), "expiration",
        new Date(System.currentTimeMillis() - 1000));
    firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    expected.expect(InvalidTokenException.class);
    expected.expectMessage("refresh token (expired)");
    TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id", null, null);
    getTokenServices().refreshAccessToken(firstAccessToken.getRefreshToken().getValue(), tokenRequest);
  }
View Full Code Here

  @Test
  public void testExpiredRefreshTokenIsRenewedWithNewAccessToken() throws Exception {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    assertNotNull(firstAccessToken.getRefreshToken());
    // Make it expire (and rely on mutable state in volatile token store)
    ReflectionTestUtils.setField(firstAccessToken.getRefreshToken(), "expiration",
        new Date(System.currentTimeMillis() - 1000));
    firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    DefaultOAuth2AccessToken secondAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        expectedAuthentication);
    ExpiringOAuth2RefreshToken refreshToken = (ExpiringOAuth2RefreshToken) secondAccessToken.getRefreshToken();
    assertNotNull(refreshToken);
    assertTrue(refreshToken.getExpiration().getTime() > System.currentTimeMillis());
  }
View Full Code Here

        return client;
      }
    });
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
        "id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
        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",
View Full Code Here

TOP

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

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.