use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtAccessTokenConverterTests method testRefreshTokenAccessTokenIdWhenDoubleEnhanced.
@Test
public void testRefreshTokenAccessTokenIdWhenDoubleEnhanced() throws Exception {
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);
token = tokenEnhancer.enhance(token, authentication);
assertNotNull(token.getValue());
assertNotNull(token.getRefreshToken());
JsonParser parser = JsonParserFactory.create();
Map<String, Object> claims = parser.parseMap(JwtHelper.decode(token.getRefreshToken().getValue()).getClaims());
assertEquals(Arrays.asList("read"), claims.get(AccessTokenConverter.SCOPE));
assertEquals("FOO", claims.get(AccessTokenConverter.ATI));
assertEquals("Wrong claims: " + claims, "BAR", claims.get(AccessTokenConverter.JTI));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtTokenStoreTests method testAccessTokenIsNotARefreshToken.
@Test
public void testAccessTokenIsNotARefreshToken() throws Exception {
DefaultOAuth2AccessToken original = new DefaultOAuth2AccessToken("FOO");
original.setExpiration(new Date());
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) enhancer.enhance(original, expectedAuthentication);
expected.expect(InvalidTokenException.class);
assertNull(tokenStore.readRefreshToken(token.getValue()));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class DefaultTokenServicesWithInMemoryTests method testExpiredRefreshToken.
@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);
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class DefaultTokenServicesWithInMemoryTests method testNoRefreshTokenIfNotAuthorized.
@Test
public void testNoRefreshTokenIfNotAuthorized() throws Exception {
// create access token
getTokenServices().setAccessTokenValiditySeconds(1);
getTokenServices().setClientDetailsService(new ClientDetailsService() {
public ClientDetails loadClientByClientId(String clientId) throws OAuth2Exception {
BaseClientDetails client = new BaseClientDetails();
client.setAccessTokenValiditySeconds(1);
client.setAuthorizedGrantTypes(Arrays.asList("authorization_code"));
return client;
}
});
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false, Collections.singleton("read")), new TestAuthentication("test2", false));
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(expectedAuthentication);
assertNull(token.getRefreshToken());
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project spring-security-oauth by spring-projects.
the class TokenStoreBaseTests method testRefreshTokenIsNotStoredDuringAccessToken.
@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());
assertNull(getTokenStore().readRefreshToken("refreshToken"));
}
Aggregations