Search in sources :

Example 6 with ServerAuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant in project cxf by apache.

the class JCacheCodeDataProviderTest method testAddGetDeleteCodeGrants2.

@Ignore
@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());
    provider.createCodeGrant(atr);
    List<ServerAuthorizationCodeGrant> grants = provider.getCodeGrants(c, c.getResourceOwnerSubject());
    assertNotNull(grants);
    assertEquals(1, grants.size());
    provider.removeClient(c.getClientId());
    grants = provider.getCodeGrants(c, c.getResourceOwnerSubject());
    assertNotNull(grants);
    assertEquals(0, grants.size());
}
Also used : Client(org.apache.cxf.rs.security.oauth2.common.Client) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with ServerAuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant 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 8 with ServerAuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant 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 9 with ServerAuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant in project cxf by apache.

the class CodeGrantEncryptingDataProvider method createCodeGrant.

@Override
public ServerAuthorizationCodeGrant createCodeGrant(AuthorizationCodeRegistration reg) throws OAuthServiceException {
    ServerAuthorizationCodeGrant grant = new ServerAuthorizationCodeGrant(reg.getClient(), 123);
    grant.setAudience(reg.getAudience());
    String encrypted = ModelEncryptionSupport.encryptCodeGrant(grant, key);
    grant.setCode(encrypted);
    grants.add(encrypted);
    return grant;
}
Also used : ServerAuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)

Example 10 with ServerAuthorizationCodeGrant

use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant in project cxf by apache.

the class CryptoUtilsTest method testEncryptDecryptCodeGrant.

@Test
public void testEncryptDecryptCodeGrant() throws Exception {
    AuthorizationCodeRegistration codeReg = new AuthorizationCodeRegistration();
    codeReg.setAudience("http://bar");
    codeReg.setClient(p.getClient("1"));
    ServerAuthorizationCodeGrant grant = p.createCodeGrant(codeReg);
    ServerAuthorizationCodeGrant grant2 = p.removeCodeGrant(grant.getCode());
    assertEquals("http://bar", grant2.getAudience());
    assertEquals("1", grant2.getClient().getClientId());
}
Also used : AuthorizationCodeRegistration(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration) ServerAuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant) Test(org.junit.Test)

Aggregations

ServerAuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)10 Client (org.apache.cxf.rs.security.oauth2.common.Client)6 Test (org.junit.Test)6 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)3 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)2 AuthorizationCodeRegistration (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration)2 Ignore (org.junit.Ignore)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 URI (java.net.URI)1 CacheException (javax.cache.CacheException)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 JSONProvider (org.apache.cxf.jaxrs.provider.json.JSONProvider)1 AbstractFormImplicitResponse (org.apache.cxf.rs.security.oauth2.common.AbstractFormImplicitResponse)1 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)1 FormAuthorizationResponse (org.apache.cxf.rs.security.oauth2.common.FormAuthorizationResponse)1 OOBAuthorizationResponse (org.apache.cxf.rs.security.oauth2.common.OOBAuthorizationResponse)1 AuthorizationCodeDataProvider (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeDataProvider)1 RefreshToken (org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)1