Search in sources :

Example 51 with Client

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

the class JPACodeDataProviderTest method addClient.

private Client addClient(String clientId, String userLogin) {
    Client c = new Client();
    c.setRedirectUris(Collections.singletonList("http://client/redirect"));
    c.setClientId(clientId);
    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)

Example 52 with Client

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

the class JPACodeDataProviderTest method testAddGetDeleteCodeGrants.

@Test
public void testAddGetDeleteCodeGrants() {
    Client c = addClient("111", "bob");
    AuthorizationCodeRegistration atr = new AuthorizationCodeRegistration();
    atr.setClient(c);
    atr.setApprovedScope(Collections.singletonList("a"));
    atr.setSubject(c.getResourceOwnerSubject());
    ServerAuthorizationCodeGrant grant = getProvider().createCodeGrant(atr);
    List<ServerAuthorizationCodeGrant> grants = getProvider().getCodeGrants(c, c.getResourceOwnerSubject());
    assertNotNull(grants);
    assertEquals(1, grants.size());
    assertEquals(grant.getCode(), grants.get(0).getCode());
    grants = getProvider().getCodeGrants(c, null);
    assertNotNull(grants);
    assertEquals(1, grants.size());
    assertEquals(grant.getCode(), grants.get(0).getCode());
    ServerAuthorizationCodeGrant grant2 = getProvider().removeCodeGrant(grant.getCode());
    assertEquals(grant.getCode(), grant2.getCode());
    grants = getProvider().getCodeGrants(c, null);
    assertNotNull(grants);
    assertEquals(0, grants.size());
}
Also used : Client(org.apache.cxf.rs.security.oauth2.common.Client) Test(org.junit.Test)

Example 53 with Client

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

the class JPACodeDataProviderTest method testAddGetDeleteCodeGrants2.

@Test
public void testAddGetDeleteCodeGrants2() {
    Client c = addClient("111", "bob");
    AuthorizationCodeRegistration atr = new AuthorizationCodeRegistration();
    atr.setClient(c);
    atr.setApprovedScope(Collections.singletonList("a"));
    atr.setSubject(c.getResourceOwnerSubject());
    getProvider().createCodeGrant(atr);
    List<ServerAuthorizationCodeGrant> grants = getProvider().getCodeGrants(c, c.getResourceOwnerSubject());
    assertNotNull(grants);
    assertEquals(1, grants.size());
    getProvider().removeClient(c.getClientId());
    grants = getProvider().getCodeGrants(c, c.getResourceOwnerSubject());
    assertNotNull(grants);
    assertEquals(0, grants.size());
}
Also used : Client(org.apache.cxf.rs.security.oauth2.common.Client) Test(org.junit.Test)

Example 54 with Client

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

the class JPACodeDataProviderTest method testResetClient.

@Test
public void testResetClient() {
    Client c = addClient("111", "bob");
    c.setClientSecret("newSecret");
    getProvider().setClient(c);
    Client savedClient = getProvider().getClient(c.getClientId());
    assertEquals(c.getClientSecret(), savedClient.getClientSecret());
}
Also used : Client(org.apache.cxf.rs.security.oauth2.common.Client) Test(org.junit.Test)

Example 55 with Client

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

the class ModelEncryptionSupport method recreateClientInternal.

private static Client recreateClientInternal(String sequence) {
    String[] parts = getParts(sequence);
    Client c = new Client(parts[0], parts[1], Boolean.parseBoolean(parts[2]), getStringPart(parts[3]), getStringPart(parts[4]));
    c.setApplicationDescription(getStringPart(parts[5]));
    c.setApplicationLogoUri(getStringPart(parts[6]));
    c.setApplicationCertificates(parseSimpleList(parts[7]));
    c.setAllowedGrantTypes(parseSimpleList(parts[8]));
    c.setRedirectUris(parseSimpleList(parts[9]));
    c.setRegisteredScopes(parseSimpleList(parts[10]));
    c.setRegisteredAudiences(parseSimpleList(parts[11]));
    c.setProperties(parseSimpleMap(parts[12]));
    c.setSubject(recreateUserSubject(parts[13]));
    return c;
}
Also used : 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