Search in sources :

Example 6 with Client

use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.

the class JCacheOAuthDataProviderTest method testAddGetDeleteClient.

@Test
public void testAddGetDeleteClient() {
    Client c = addClient("12345", "alice");
    Client c2 = provider.getClient(c.getClientId());
    compareClients(c, c2);
    c2.setClientSecret("567");
    provider.setClient(c2);
    Client c22 = provider.getClient(c.getClientId());
    compareClients(c2, c22);
    provider.removeClient(c.getClientId());
    Client c3 = provider.getClient(c.getClientId());
    assertNull(c3);
}
Also used : Client(org.apache.cxf.rs.security.oauth2.common.Client) Test(org.junit.Test)

Example 7 with Client

use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.

the class JCacheOAuthDataProviderTest method testAddGetDeleteRefreshToken.

@Ignore
@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 = provider.createAccessToken(atr);
    ServerAccessToken at2 = provider.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 = provider.getRefreshToken(at2.getRefreshToken());
    assertNotNull(rt);
    assertEquals(at2.getTokenKey(), rt.getAccessTokens().get(0));
    List<RefreshToken> tokens = provider.getRefreshTokens(c, c.getResourceOwnerSubject());
    assertNotNull(tokens);
    assertEquals(1, tokens.size());
    assertEquals(rt.getTokenKey(), tokens.get(0).getTokenKey());
    provider.revokeToken(c, rt.getTokenKey(), OAuthConstants.REFRESH_TOKEN);
    assertNull(provider.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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Client

use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.

the class JPAOAuthDataProviderTest method testAddGetDeleteAccessToken2.

@Test
public void testAddGetDeleteAccessToken2() {
    Client c = addClient("102", "bob");
    AccessTokenRegistration atr = new AccessTokenRegistration();
    atr.setClient(c);
    atr.setApprovedScope(Collections.singletonList("a"));
    atr.setSubject(c.getResourceOwnerSubject());
    getProvider().createAccessToken(atr);
    List<ServerAccessToken> tokens = getProvider().getAccessTokens(c, null);
    assertNotNull(tokens);
    assertEquals(1, tokens.size());
    getProvider().removeClient(c.getClientId());
    tokens = getProvider().getAccessTokens(c, null);
    assertNotNull(tokens);
    assertEquals(0, tokens.size());
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) Client(org.apache.cxf.rs.security.oauth2.common.Client) AccessTokenRegistration(org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration) Test(org.junit.Test)

Example 9 with Client

use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.

the class JPAOAuthDataProviderTest method testAddGetDeleteClients.

@Test
public void testAddGetDeleteClients() {
    Client c = addClient("12345", "alice");
    Client c2 = addClient("56789", "alice");
    Client c3 = addClient("09876", "bob");
    List<Client> aliceClients = getProvider().getClients(new UserSubject("alice"));
    assertNotNull(aliceClients);
    assertEquals(2, aliceClients.size());
    compareClients(c, aliceClients.get(0).getClientId().equals("12345") ? aliceClients.get(0) : aliceClients.get(1));
    compareClients(c2, aliceClients.get(0).getClientId().equals("56789") ? aliceClients.get(0) : aliceClients.get(1));
    List<Client> bobClients = getProvider().getClients(new UserSubject("bob"));
    assertNotNull(bobClients);
    assertEquals(1, bobClients.size());
    Client bobClient = bobClients.get(0);
    compareClients(c3, bobClient);
    List<Client> allClients = getProvider().getClients(null);
    assertNotNull(allClients);
    assertEquals(3, allClients.size());
    getProvider().removeClient(c.getClientId());
    getProvider().removeClient(c2.getClientId());
    getProvider().removeClient(c3.getClientId());
    allClients = getProvider().getClients(null);
    assertNotNull(allClients);
    assertEquals(0, allClients.size());
}
Also used : UserSubject(org.apache.cxf.rs.security.oauth2.common.UserSubject) Client(org.apache.cxf.rs.security.oauth2.common.Client) Test(org.junit.Test)

Example 10 with Client

use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.

the class JPAOAuthDataProviderTest method addClient.

protected Client addClient(String clientId, String userLogin) {
    Client c = new Client();
    c.setRedirectUris(Collections.singletonList("http://client/redirect"));
    c.setClientId(clientId);
    c.setClientSecret("123");
    c.setResourceOwnerSubject(new UserSubject(userLogin));
    getProvider().setClient(c);
    return c;
}
Also used : UserSubject(org.apache.cxf.rs.security.oauth2.common.UserSubject) Client(org.apache.cxf.rs.security.oauth2.common.Client)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)112 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)100 Response (javax.ws.rs.core.Response)79 Client (org.apache.cxf.rs.security.oauth2.common.Client)75 Form (javax.ws.rs.core.Form)64 URL (java.net.URL)59 OAuthAuthorizationData (org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)36 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)36 Test (org.junit.Test)35 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)27 UserSubject (org.apache.cxf.rs.security.oauth2.common.UserSubject)25 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)22 OAuthPermission (org.apache.cxf.rs.security.oauth2.common.OAuthPermission)21 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)16 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)15 ArrayList (java.util.ArrayList)13 TokenIntrospection (org.apache.cxf.rs.security.oauth2.common.TokenIntrospection)12 RefreshToken (org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)12 Book (org.apache.cxf.systest.jaxrs.security.Book)11 Consumes (javax.ws.rs.Consumes)8