use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceTest method testReadAuthenticationForRefreshToken.
@Test
@Transactional
public void testReadAuthenticationForRefreshToken() throws Exception {
OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("some-long-oauth2-refresh-value-1");
OAuth2Authentication oAuth2Authentication = orcidTokenStoreService.readAuthenticationForRefreshToken(refreshToken);
assertNotNull(oAuth2Authentication);
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceTest method testRemoveRefreshToken.
@Test
@Transactional
public void testRemoveRefreshToken() throws Exception {
OAuth2AccessToken token = orcidTokenStoreService.readAccessToken("some-long-oauth2-token-value-3");
orcidTokenStoreService.removeRefreshToken(token.getRefreshToken());
OAuth2RefreshToken refreshToken = orcidTokenStoreService.readRefreshToken("some-long-oauth2-refresh-value-3");
assertNull(refreshToken);
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesImpl method createAccessToken.
@Override
public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws AuthenticationException {
OrcidOauth2AuthInfo authInfo = new OrcidOauth2AuthInfo(authentication);
String userOrcid = authInfo.getUserOrcid();
DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
int validitySeconds = getAccessTokenValiditySeconds(authentication.getOAuth2Request());
if (validitySeconds > 0) {
accessToken.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L)));
}
accessToken.setScope(authentication.getOAuth2Request().getScope());
if (customTokenEnhancer != null) {
accessToken = new DefaultOAuth2AccessToken(customTokenEnhancer.enhance(accessToken, authentication));
}
if (this.isSupportRefreshToken(authentication.getOAuth2Request())) {
OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken(UUID.randomUUID().toString());
accessToken.setRefreshToken(refreshToken);
}
orcidTokenStore.storeAccessToken(accessToken, authentication);
LOGGER.info("Creating new access token: clientId={}, scopes={}, userOrcid={}", new Object[] { authInfo.getClientId(), authInfo.getScopes(), userOrcid });
return accessToken;
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken in project spring-security-oauth by spring-projects.
the class JaxbOAuth2AccessTokenMessageConverterTests method assertTokenEquals.
private static void assertTokenEquals(OAuth2AccessToken expected, OAuth2AccessToken actual) {
assertEquals(expected.getTokenType(), actual.getTokenType());
assertEquals(expected.getValue(), actual.getValue());
OAuth2RefreshToken expectedRefreshToken = expected.getRefreshToken();
if (expectedRefreshToken == null) {
assertNull(actual.getRefreshToken());
} else {
assertEquals(expectedRefreshToken.getValue(), actual.getRefreshToken().getValue());
}
assertEquals(expected.getScope(), actual.getScope());
Date expectedExpiration = expected.getExpiration();
if (expectedExpiration == null) {
assertNull(actual.getExpiration());
} else {
assertEquals(expectedExpiration.getTime(), actual.getExpiration().getTime());
}
}
use of org.springframework.security.oauth2.core.OAuth2RefreshToken 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);
}
Aggregations