Package org.springframework.security.oauth2.common

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


  @Test(expected = InvalidTokenException.class)
  public void testSunnyDayWIthExpiredTokenAndExpiredRefreshToken() throws Exception {
    AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
    accessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
    DefaultOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("EXP", new Date(
        System.currentTimeMillis() - 1000));
    accessToken.setRefreshToken(refreshToken);
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setExistingToken(accessToken);
    SecurityContextHolder.getContext().setAuthentication(user);
View Full Code Here


  @Before
  public void before() throws Exception {
    converter = new JaxbOAuth2AccessTokenMessageConverter();
    accessToken = new DefaultOAuth2AccessToken("SlAV32hkKG");
    accessToken.setExpiration(expiration);
    accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("8xLOxBtZp8"));
  }
View Full Code Here

  }

  @Test
  public void testReadAuthenticationForRefreshToken() throws Exception {
    checkAuthentications(expectedAuthentication,
        tokenStore.readAuthenticationForRefreshToken(new DefaultOAuth2RefreshToken(expectedOAuth2AccessToken
            .getValue())));
  }
View Full Code Here

  @Test
  public void removeRefreshToken() throws Exception {
    tokenStore.setApprovalStore(approvalStore);
    approvalStore.addApprovals(Collections.singleton(new Approval("test", "id", "read", new Date(), ApprovalStatus.APPROVED)));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
    tokenStore.removeRefreshToken(new DefaultOAuth2RefreshToken(expectedOAuth2AccessToken.getValue()));
    assertEquals(0, approvalStore.getApprovals("test", "id").size());
  }
View Full Code Here

  @Test
  public void removeAccessTokenFromRefreshToken() throws Exception {
    tokenStore.setApprovalStore(approvalStore);
    approvalStore.addApprovals(Collections.singleton(new Approval("test", "id", "read", new Date(), ApprovalStatus.APPROVED)));
    assertEquals(1, approvalStore.getApprovals("test", "id").size());
    tokenStore.removeAccessTokenUsingRefreshToken(new DefaultOAuth2RefreshToken(expectedOAuth2AccessToken.getValue()));
    assertEquals(0, approvalStore.getApprovals("test", "id").size());
  }
View Full Code Here

  public void testRefreshTokenAdded() {
    OAuth2Authentication authentication = new OAuth2Authentication(createOAuth2Request("foo", Collections.singleton("read")),
        userAuthentication);
    DefaultOAuth2AccessToken original = new DefaultOAuth2AccessToken("FOO");
    original.setScope(authentication.getOAuth2Request().getScope());
    original.setRefreshToken(new DefaultOAuth2RefreshToken("BAR"));
    OAuth2AccessToken token = tokenEnhancer.enhance(original, authentication);
    assertNotNull(token.getValue());
    assertNotNull(token.getRefreshToken());
    String claims = JwtHelper.decode(token.getRefreshToken().getValue()).getClaims();
    assertTrue("Wrong claims: " + claims, claims.contains("\"" + AccessTokenConverter.SCOPE + "\""));
View Full Code Here

  @Test
  public void testRefreshTokenIsNotStoredDuringAccessToken() {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
    expectedOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refreshToken"));
    getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);

    OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().readAccessToken("testToken");
    assertNotNull(actualOAuth2AccessToken.getRefreshToken());
   
View Full Code Here

    assertNull(getTokenStore().readRefreshToken("refreshToken"));
  }

  @Test
  public void testStoreRefreshToken() {
    DefaultOAuth2RefreshToken expectedExpiringRefreshToken = new DefaultExpiringOAuth2RefreshToken("testToken",
        new Date());
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
    getTokenStore().storeRefreshToken(expectedExpiringRefreshToken, expectedAuthentication);

    OAuth2RefreshToken actualExpiringRefreshToken = getTokenStore().readRefreshToken("testToken");
    assertEquals(expectedExpiringRefreshToken, actualExpiringRefreshToken);
    assertEquals(expectedAuthentication, getTokenStore().readAuthenticationForRefreshToken(expectedExpiringRefreshToken));
    getTokenStore().removeRefreshToken(expectedExpiringRefreshToken);
    assertNull(getTokenStore().readRefreshToken("testToken"));
    assertNull(getTokenStore().readAuthentication(expectedExpiringRefreshToken.getValue()));
  }
View Full Code Here

  private Authentication createAuthentication(JsonObject token) {
    return new PreAuthenticatedAuthenticationToken(token.get("sub").getAsString(), token, introspectionAuthorityGranter.getAuthorities(token));
  }

  private OAuth2AccessToken createAccessToken(final JsonObject token, final String tokenString) {
    OAuth2AccessToken accessToken = new OAuth2AccessTokenImpl(token, tokenString);
    return accessToken;
  }
View Full Code Here

        return false;
      }
      // create an OAuth2Authentication
      OAuth2Authentication auth = new OAuth2Authentication(createStoredRequest(tokenResponse), createAuthentication(tokenResponse));
      // create an OAuth2AccessToken
      OAuth2AccessToken token = createAccessToken(tokenResponse, accessToken);

      if (token.getExpiration().after(new Date())) {
        // Store them in the cache
        authCache.put(accessToken, new TokenCacheObject(token, auth));

        return true;
      }
View Full Code Here

TOP

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

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.