Search in sources :

Example 11 with RefreshToken

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);
    }
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken) Client(org.apache.cxf.rs.security.oauth2.common.Client)

Example 12 with RefreshToken

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()));
}
Also used : OAuthPermission(org.apache.cxf.rs.security.oauth2.common.OAuthPermission) ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken) Client(org.apache.cxf.rs.security.oauth2.common.Client) AccessTokenRegistration(org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration) Test(org.junit.Test)

Example 13 with RefreshToken

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);
}
Also used : RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)

Example 14 with RefreshToken

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;
}
Also used : OAuthPermission(org.apache.cxf.rs.security.oauth2.common.OAuthPermission) RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken) LinkedList(java.util.LinkedList)

Example 15 with RefreshToken

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());
        }
    }
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) RefreshToken(org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)

Aggregations

RefreshToken (org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)13 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)10 Client (org.apache.cxf.rs.security.oauth2.common.Client)6 OAuthPermission (org.apache.cxf.rs.security.oauth2.common.OAuthPermission)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)4 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)3 Test (org.junit.Test)3 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)2 BearerAccessToken (com.nimbusds.oauth2.sdk.token.BearerAccessToken)2 TypelessAccessToken (com.nimbusds.oauth2.sdk.token.TypelessAccessToken)2 ArrayList (java.util.ArrayList)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)2 AccessTokenGrant (org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant)2 RefreshTokenGrant (org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrant)2 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)2 OidcValidationException (org.codice.ddf.security.oidc.validator.OidcValidationException)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1