use of org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class AccessTokenProviderChainTests method testSunnyDayWIthExpiredTokenAndExpiredRefreshToken.
@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);
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
}
use of org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class AbstractDefaultTokenServicesTests method testRefreshedTokenNotExpiring.
@Test
public void testRefreshedTokenNotExpiring() throws Exception {
getTokenServices().setRefreshTokenValiditySeconds(0);
OAuth2RefreshToken expectedExpiringRefreshToken = getTokenServices().createAccessToken(createAuthentication()).getRefreshToken();
assertFalse(expectedExpiringRefreshToken instanceof DefaultExpiringOAuth2RefreshToken);
}
use of org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class RedisTokenStorePrefixTests method testExpiringRefreshToken.
@Test
public void testExpiringRefreshToken() throws InterruptedException {
String refreshToken = UUID.randomUUID().toString();
DefaultOAuth2RefreshToken expectedExpiringRefreshToken = new DefaultExpiringOAuth2RefreshToken(refreshToken, new Date(System.currentTimeMillis() + 1500));
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
getTokenStore().storeRefreshToken(expectedExpiringRefreshToken, expectedAuthentication);
OAuth2RefreshToken actualExpiringRefreshToken = getTokenStore().readRefreshToken(refreshToken);
assertEquals(expectedExpiringRefreshToken, actualExpiringRefreshToken);
assertEquals(expectedAuthentication, getTokenStore().readAuthenticationForRefreshToken(expectedExpiringRefreshToken));
// let the token expire
Thread.sleep(1500);
// now it should be gone
assertNull(getTokenStore().readRefreshToken(refreshToken));
assertNull(getTokenStore().readAuthenticationForRefreshToken(expectedExpiringRefreshToken));
}
use of org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class AbstractPersistentDefaultTokenServicesTests method testTokenEnhancerUpdatesStoredTokens.
@Test
public void testTokenEnhancerUpdatesStoredTokens() throws Exception {
final ExpiringOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("testToken", new Date(System.currentTimeMillis() + 100000));
getTokenServices().setTokenEnhancer(new TokenEnhancer() {
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
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()));
}
use of org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class JwtTokenStoreTests method testReadExpiringRefreshToken.
@Test
public void testReadExpiringRefreshToken() throws Exception {
DefaultOAuth2AccessToken original = new DefaultOAuth2AccessToken("FOO");
original.setExpiration(new Date());
convertToRefreshToken(original);
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) enhancer.enhance(original, expectedAuthentication);
assertTrue(tokenStore.readRefreshToken(token.getValue()) instanceof DefaultExpiringOAuth2RefreshToken);
}
Aggregations