use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtAccessTokenConverterTests method testEnhanceAccessToken.
@Test
public void testEnhanceAccessToken() {
OAuth2Authentication authentication = new OAuth2Authentication(createOAuth2Request("foo", null), userAuthentication);
OAuth2AccessToken token = tokenEnhancer.enhance(new DefaultOAuth2AccessToken("FOO"), authentication);
assertNotNull(token.getValue());
assertEquals("FOO", token.getAdditionalInformation().get(AccessTokenConverter.JTI));
String claims = JwtHelper.decode(token.getValue()).getClaims();
assertTrue("Wrong claims: " + claims, claims.contains("\"" + AccessTokenConverter.JTI + "\":\"FOO\""));
assertTrue("Wrong claims: " + claims, claims.contains("\"" + UserAuthenticationConverter.USERNAME + "\""));
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtAccessTokenConverterTests method testScopePreserved.
@Test
public void testScopePreserved() {
OAuth2Authentication authentication = new OAuth2Authentication(createOAuth2Request("foo", Collections.singleton("read")), userAuthentication);
DefaultOAuth2AccessToken original = new DefaultOAuth2AccessToken("FOO");
original.setScope(authentication.getOAuth2Request().getScope());
OAuth2AccessToken token = tokenEnhancer.enhance(original, authentication);
assertNotNull(token.getValue());
assertEquals(Collections.singleton("read"), token.getScope());
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtAccessTokenConverterTests method testExpiringRefreshTokenAdded.
@Test
public void testExpiringRefreshTokenAdded() 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 DefaultExpiringOAuth2RefreshToken("BAR", new Date(0)));
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));
assertEquals(0, 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.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class JwtTokenStoreTests method testAccessTokenCannotBeExtractedFromAuthentication.
@Test
public void testAccessTokenCannotBeExtractedFromAuthentication() throws Exception {
OAuth2AccessToken accessToken = tokenStore.getAccessToken(expectedAuthentication);
assertEquals(null, accessToken);
}
use of org.springframework.security.oauth2.common.OAuth2AccessToken in project spring-security-oauth by spring-projects.
the class TokenStoreBaseTests method testFindAccessTokensByClientId.
@Test
public void testFindAccessTokensByClientId() {
String clientId = "id" + UUID.randomUUID();
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(clientId, false), new TestAuthentication("test2", false));
OAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);
Collection<OAuth2AccessToken> actualOAuth2AccessTokens = getTokenStore().findTokensByClientId(clientId);
assertEquals(1, actualOAuth2AccessTokens.size());
}
Aggregations