use of org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken in project cxf by apache.
the class JPAOAuthDataProviderTest method tearDownClient.
protected void tearDownClient(String clientId) {
if (getProvider() == null) {
return;
}
Client client = getProvider().getClient(clientId);
if (client != null) {
List<RefreshToken> refreshTokens = getProvider().getRefreshTokens(client, null);
for (RefreshToken refreshToken : refreshTokens) {
getProvider().revokeToken(client, refreshToken.getTokenKey(), refreshToken.getTokenType());
}
List<ServerAccessToken> accessTokens = getProvider().getAccessTokens(client, null);
for (ServerAccessToken accessToken : accessTokens) {
getProvider().revokeToken(client, accessToken.getTokenKey(), accessToken.getTokenType());
}
getProvider().removeClient(clientId);
}
}
use of org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken in project cxf by apache.
the class JPAOAuthDataProviderTest method testAddGetDeleteRefreshToken.
@Test
public void testAddGetDeleteRefreshToken() {
Client c = addClient("101", "bob");
AccessTokenRegistration atr = new AccessTokenRegistration();
atr.setClient(c);
atr.setApprovedScope(Arrays.asList("a", "refreshToken"));
atr.setSubject(c.getResourceOwnerSubject());
ServerAccessToken at = getProvider().createAccessToken(atr);
ServerAccessToken at2 = getProvider().getAccessToken(at.getTokenKey());
assertEquals(at.getTokenKey(), at2.getTokenKey());
List<OAuthPermission> scopes = at2.getScopes();
assertNotNull(scopes);
assertEquals(2, scopes.size());
OAuthPermission perm = scopes.get(0);
assertEquals("a", perm.getPermission());
OAuthPermission perm2 = scopes.get(1);
assertEquals("refreshToken", perm2.getPermission());
RefreshToken rt = getProvider().getRefreshToken(at2.getRefreshToken());
assertNotNull(rt);
assertEquals(at2.getTokenKey(), rt.getAccessTokens().get(0));
List<RefreshToken> tokens = getProvider().getRefreshTokens(c, c.getResourceOwnerSubject());
assertNotNull(tokens);
assertEquals(1, tokens.size());
assertEquals(rt.getTokenKey(), tokens.get(0).getTokenKey());
getProvider().revokeToken(c, rt.getTokenKey(), OAuthConstants.REFRESH_TOKEN);
assertNull(getProvider().getRefreshToken(rt.getTokenKey()));
}
use of org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken in project cxf by apache.
the class EncryptingDataProvider method createRefreshToken.
private void createRefreshToken(ServerAccessToken token) {
RefreshToken refreshToken = new RefreshToken(token.getClient(), "refresh", 1200L, OAuthUtils.getIssuedAt());
String encryptedRefreshToken = ModelEncryptionSupport.encryptRefreshToken(refreshToken, key);
token.setRefreshToken(encryptedRefreshToken);
}
use of org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken in project cxf by apache.
the class AbstractOAuthDataProvider method doCreateNewRefreshToken.
protected RefreshToken doCreateNewRefreshToken(ServerAccessToken at) {
RefreshToken rt = new RefreshToken(at.getClient(), refreshTokenLifetime);
if (at.getAudiences() != null) {
List<String> audiences = new LinkedList<String>();
audiences.addAll(at.getAudiences());
rt.setAudiences(audiences);
}
rt.setGrantType(at.getGrantType());
if (at.getScopes() != null) {
List<OAuthPermission> scopes = new LinkedList<OAuthPermission>();
scopes.addAll(at.getScopes());
rt.setScopes(scopes);
}
rt.setGrantCode(at.getGrantCode());
rt.setNonce(at.getNonce());
rt.setSubject(at.getSubject());
rt.setClientCodeVerifier(at.getClientCodeVerifier());
return rt;
}
use of org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken in project cxf by apache.
the class AbstractOAuthDataProvider method removeClientTokens.
protected void removeClientTokens(Client c) {
List<RefreshToken> refreshTokens = getRefreshTokens(c, null);
if (refreshTokens != null) {
for (RefreshToken rt : refreshTokens) {
revokeRefreshToken(rt.getTokenKey());
}
}
List<ServerAccessToken> accessTokens = getAccessTokens(c, null);
if (accessTokens != null) {
for (ServerAccessToken at : accessTokens) {
revokeAccessToken(at.getTokenKey());
}
}
}
Aggregations