use of org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class JwtAccessTokenConverterTests method testRefreshTokenAdded.
@Test
public void testRefreshTokenAdded() 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"));
original.setExpiration(new Date());
OAuth2AccessToken token = tokenEnhancer.enhance(original, 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("BAR", claims.get(AccessTokenConverter.JTI));
assertNull(claims.get(AccessTokenConverter.EXP));
tokenEnhancer.afterPropertiesSet();
assertTrue(tokenEnhancer.isRefreshToken(tokenEnhancer.extractAccessToken(token.getRefreshToken().getValue(), tokenEnhancer.decode(token.getRefreshToken().getValue()))));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken 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.DefaultOAuth2RefreshToken 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"));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class TokenStoreBaseTests method testStoreRefreshToken.
@Test
public /**
* NB: This used to test expiring refresh tokens. That test has been moved to sub-classes since not all stores support the functionality
*/
void testStoreRefreshToken() {
String refreshToken = "testToken" + UUID.randomUUID();
DefaultOAuth2RefreshToken expectedRefreshToken = new DefaultOAuth2RefreshToken(refreshToken);
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
getTokenStore().storeRefreshToken(expectedRefreshToken, expectedAuthentication);
OAuth2RefreshToken actualExpiringRefreshToken = getTokenStore().readRefreshToken(refreshToken);
assertEquals(expectedRefreshToken, actualExpiringRefreshToken);
assertEquals(expectedAuthentication, getTokenStore().readAuthenticationForRefreshToken(expectedRefreshToken));
getTokenStore().removeRefreshToken(expectedRefreshToken);
assertNull(getTokenStore().readRefreshToken(refreshToken));
assertNull(getTokenStore().readAuthentication(expectedRefreshToken.getValue()));
}
use of org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesImpl method toOAuth2AccessToken.
private OAuth2AccessToken toOAuth2AccessToken(OrcidOauth2TokenDetail token) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(token.getTokenValue());
result.setExpiration(token.getTokenExpiration());
result.setRefreshToken(new DefaultOAuth2RefreshToken(token.getRefreshTokenValue()));
result.setScope(OAuth2Utils.parseParameterList(token.getScope()));
result.setTokenType(token.getTokenType());
result.setValue(token.getTokenValue());
Map<String, Object> additionalInfo = new HashMap<String, Object>();
if (token.getProfile() != null) {
additionalInfo.put(OrcidOauth2Constants.ORCID, token.getProfile().getId());
additionalInfo.put(OrcidOauth2Constants.NAME, profileEntityManager.retrivePublicDisplayName(token.getProfile().getId()));
}
result.setAdditionalInformation(additionalInfo);
return result;
}
Aggregations