use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class AuthorizationCodeServicesBaseTests method testCreateAuthorizationCode.
@Test
public void testCreateAuthorizationCode() {
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false);
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(storedOAuth2Request, new TestAuthentication("test2", false));
String code = getAuthorizationCodeServices().createAuthorizationCode(expectedAuthentication);
assertNotNull(code);
OAuth2Authentication actualAuthentication = getAuthorizationCodeServices().consumeAuthorizationCode(code);
assertEquals(expectedAuthentication, actualAuthentication);
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class AbstractDefaultTokenServicesTests method testRevokedTokenNotAvailable.
@Test
public void testRevokedTokenNotAvailable() throws Exception {
OAuth2Authentication authentication = createAuthentication();
OAuth2AccessToken token = getTokenServices().createAccessToken(authentication);
getTokenServices().revokeToken(token.getValue());
Collection<OAuth2AccessToken> tokens = getTokenStore().findTokensByClientIdAndUserName(authentication.getOAuth2Request().getClientId(), authentication.getUserAuthentication().getName());
assertFalse(tokens.contains(token));
assertTrue(tokens.isEmpty());
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class AbstractDefaultTokenServicesTests method testRefreshTokenRequestHasRefreshFlag.
@Test
public void testRefreshTokenRequestHasRefreshFlag() throws Exception {
ExpiringOAuth2RefreshToken expectedExpiringRefreshToken = (ExpiringOAuth2RefreshToken) getTokenServices().createAccessToken(createAuthentication()).getRefreshToken();
TokenRequest tokenRequest = new TokenRequest(Collections.singletonMap("client_id", "id"), "id", Collections.singleton("read"), null);
final AtomicBoolean called = new AtomicBoolean(false);
getTokenServices().setTokenEnhancer(new TokenEnhancer() {
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
assertTrue(authentication.getOAuth2Request().isRefresh());
called.set(true);
return accessToken;
}
});
getTokenServices().refreshAccessToken(expectedExpiringRefreshToken.getValue(), tokenRequest);
assertTrue(called.get());
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class AdminController method enhance.
private Collection<OAuth2AccessToken> enhance(Collection<OAuth2AccessToken> tokens) {
Collection<OAuth2AccessToken> result = new ArrayList<OAuth2AccessToken>();
for (OAuth2AccessToken prototype : tokens) {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(prototype);
OAuth2Authentication authentication = tokenStore.readAuthentication(token);
if (authentication == null) {
continue;
}
String clientId = authentication.getOAuth2Request().getClientId();
if (clientId != null) {
Map<String, Object> map = new HashMap<String, Object>(token.getAdditionalInformation());
map.put("client_id", clientId);
token.setAdditionalInformation(map);
result.add(token);
}
}
return result;
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class RedisTokenStoreMockTests method storeRefreshTokenRemoveRefreshTokenVerifyKeysRemoved.
// gh-572
@Test
public void storeRefreshTokenRemoveRefreshTokenVerifyKeysRemoved() {
OAuth2RefreshToken oauth2RefreshToken = new DefaultOAuth2RefreshToken("refresh-token-" + UUID.randomUUID());
OAuth2Authentication oauth2Authentication = new OAuth2Authentication(request, authentication);
tokenStore.storeRefreshToken(oauth2RefreshToken, oauth2Authentication);
ArgumentCaptor<byte[]> keyArgs = ArgumentCaptor.forClass(byte[].class);
verify(connection, times(2)).set(keyArgs.capture(), any(byte[].class));
tokenStore.removeRefreshToken(oauth2RefreshToken);
for (byte[] key : keyArgs.getAllValues()) {
verify(connection).del(key);
}
}
Aggregations