Package org.mitre.oauth2.model

Examples of org.mitre.oauth2.model.OAuth2AccessTokenEntity


    OAuth2Request clientAuth = new OAuth2Request(null, clientId, null, true, Sets.newHashSet(SystemScopeService.OFFLINE_ACCESS), null, null, null, null);
    Mockito.when(authentication.getOAuth2Request()).thenReturn(clientAuth);
    Mockito.when(client.isAllowRefresh()).thenReturn(true);

    OAuth2AccessTokenEntity token = service.createAccessToken(authentication);

    // Note: a refactor may be appropriate to only save refresh tokens once to the repository during creation.
    Mockito.verify(tokenRepository, Mockito.atLeastOnce()).saveRefreshToken(Matchers.any(OAuth2RefreshTokenEntity.class));
    assertThat(token.getRefreshToken(), is(notNullValue()));

  }
View Full Code Here


    Mockito.when(client.getAccessTokenValiditySeconds()).thenReturn(accessTokenValiditySeconds);
    Mockito.when(client.getRefreshTokenValiditySeconds()).thenReturn(refreshTokenValiditySeconds);

    long start = System.currentTimeMillis();
    OAuth2AccessTokenEntity token = service.createAccessToken(authentication);
    long end = System.currentTimeMillis();

    // Accounting for some delta for time skew on either side.
    Date lowerBoundAccessTokens = new Date(start + (accessTokenValiditySeconds * 1000L) - DELTA);
    Date upperBoundAccessTokens = new Date(end + (accessTokenValiditySeconds * 1000L) + DELTA);
    Date lowerBoundRefreshTokens = new Date(start + (refreshTokenValiditySeconds * 1000L) - DELTA);
    Date upperBoundRefreshTokens = new Date(end + (refreshTokenValiditySeconds * 1000L) + DELTA);

    assertTrue(token.getExpiration().after(lowerBoundAccessTokens) && token.getExpiration().before(upperBoundAccessTokens));
    assertTrue(token.getRefreshToken().getExpiration().after(lowerBoundRefreshTokens) && token.getRefreshToken().getExpiration().before(upperBoundRefreshTokens));
  }
View Full Code Here

  }

  @Test
  public void createAccessToken_checkClient() {

    OAuth2AccessTokenEntity token = service.createAccessToken(authentication);

    assertThat(token.getClient().getClientId(), equalTo(clientId));
  }
View Full Code Here

  }

  @Test
  public void createAccessToken_checkScopes() {

    OAuth2AccessTokenEntity token = service.createAccessToken(authentication);

    assertThat(token.getScope(), equalTo(scope));
  }
View Full Code Here

    AuthenticationHolderEntity authHolder = Mockito.mock(AuthenticationHolderEntity.class);
    Mockito.when(authHolder.getAuthentication()).thenReturn(authentication);

    Mockito.when(authenticationHolderRepository.save(Matchers.any(AuthenticationHolderEntity.class))).thenReturn(authHolder);

    OAuth2AccessTokenEntity token = service.createAccessToken(authentication);

    assertThat(token.getAuthenticationHolder().getAuthentication(), equalTo(authentication));
    Mockito.verify(authenticationHolderRepository).save(Matchers.any(AuthenticationHolderEntity.class));
  }
View Full Code Here

  }

  @Test
  public void refreshAccessToken_verifyAcessToken() {

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    Mockito.verify(tokenRepository).clearAccessTokensForRefreshToken(refreshToken);

    assertThat(token.getClient(), equalTo(client));
    assertThat(token.getRefreshToken(), equalTo(refreshToken));
    assertThat(token.getAuthenticationHolder(), equalTo(storedAuthHolder));

    Mockito.verify(tokenEnhancer).enhance(token, storedAuthentication);
    Mockito.verify(tokenRepository).saveAccessToken(token);
  }
View Full Code Here

  }

  @Test
  public void refreshAccessToken_requestingSameScope() {

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));
  }
View Full Code Here

    Set<String> lessScope = Sets.newHashSet("openid", "profile");

    tokenRequest.setScope(lessScope);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(lessScope));
  }
View Full Code Here

    Set<String> emptyScope = Sets.newHashSet();

    tokenRequest.setScope(emptyScope);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));
  }
View Full Code Here

  @Test
  public void refreshAccessToken_requestingNullScope() {

    tokenRequest.setScope(null);

    OAuth2AccessTokenEntity token = service.refreshAccessToken(refreshTokenValue, tokenRequest);

    assertThat(token.getScope(), equalTo(storedScope));

  }
View Full Code Here

TOP

Related Classes of org.mitre.oauth2.model.OAuth2AccessTokenEntity

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.