Search in sources :

Example 1 with AuthorizationCodeRegistration

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

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

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

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

the class AuthorizationCodeGrantService method getGrantRepresentation.

public ServerAuthorizationCodeGrant getGrantRepresentation(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preauthorizedToken) {
    AuthorizationCodeRegistration codeReg = createCodeRegistration(state, client, requestedScope, approvedScope, userSubject, preauthorizedToken);
    ServerAuthorizationCodeGrant grant = ((AuthorizationCodeDataProvider) getDataProvider()).createCodeGrant(codeReg);
    if (grant.getExpiresIn() > RECOMMENDED_CODE_EXPIRY_TIME_SECS) {
        LOG.warning("Code expiry time exceeds 10 minutes");
    }
    return grant;
}
Also used : AuthorizationCodeRegistration(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration) AuthorizationCodeDataProvider(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeDataProvider) ServerAuthorizationCodeGrant(org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)

Example 5 with AuthorizationCodeRegistration

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

the class AuthorizationCodeGrantService method createCodeRegistration.

protected AuthorizationCodeRegistration createCodeRegistration(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preauthorizedToken) {
    AuthorizationCodeRegistration codeReg = new AuthorizationCodeRegistration();
    codeReg.setPreauthorizedTokenAvailable(preauthorizedToken != null);
    codeReg.setClient(client);
    codeReg.setRedirectUri(state.getRedirectUri());
    codeReg.setRequestedScope(requestedScope);
    codeReg.setResponseType(state.getResponseType());
    codeReg.setApprovedScope(getApprovedScope(requestedScope, approvedScope));
    codeReg.setSubject(userSubject);
    codeReg.setAudience(state.getAudience());
    codeReg.setNonce(state.getNonce());
    codeReg.setClientCodeChallenge(state.getClientCodeChallenge());
    codeReg.setClientCodeChallengeMethod(state.getClientCodeChallengeMethod());
    codeReg.getExtraProperties().putAll(state.getExtraProperties());
    return codeReg;
}
Also used : AuthorizationCodeRegistration(org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration)

Aggregations

Test (org.junit.Test)5 Client (org.apache.cxf.rs.security.oauth2.common.Client)4 ServerAuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)4 AuthorizationCodeRegistration (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeRegistration)3 Ignore (org.junit.Ignore)2 AuthorizationCodeDataProvider (org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeDataProvider)1