Search in sources :

Example 61 with ServerAccessToken

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

the class ModelEncryptionSupport method recreateAccessToken.

private static ServerAccessToken recreateAccessToken(OAuthDataProvider provider, String newTokenKey, String[] parts) {
    @SuppressWarnings("serial") final ServerAccessToken newToken = new ServerAccessToken(provider.getClient(parts[4]), parts[1], newTokenKey == null ? parts[0] : newTokenKey, Long.parseLong(parts[2]), Long.parseLong(parts[3])) {
    };
    newToken.setRefreshToken(getStringPart(parts[5]));
    newToken.setGrantType(getStringPart(parts[6]));
    newToken.setAudiences(parseSimpleList(parts[7]));
    newToken.setParameters(parseSimpleMap(parts[8]));
    // Permissions
    if (!parts[9].trim().isEmpty()) {
        List<OAuthPermission> perms = new LinkedList<OAuthPermission>();
        String[] allPermParts = parts[9].split("\\.");
        for (int i = 0; i + 4 < allPermParts.length; i = i + 5) {
            OAuthPermission perm = new OAuthPermission(allPermParts[i], allPermParts[i + 1]);
            perm.setDefaultPermission(Boolean.parseBoolean(allPermParts[i + 2]));
            perm.setHttpVerbs(parseSimpleList(allPermParts[i + 3]));
            perm.setUris(parseSimpleList(allPermParts[i + 4]));
            perms.add(perm);
        }
        newToken.setScopes(perms);
    }
    // Client verifier:
    newToken.setClientCodeVerifier(parts[10]);
    // UserSubject:
    newToken.setSubject(recreateUserSubject(parts[11]));
    newToken.setExtraProperties(parseSimpleMap(parts[12]));
    return newToken;
}
Also used : OAuthPermission(org.apache.cxf.rs.security.oauth2.common.OAuthPermission) ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) LinkedList(java.util.LinkedList)

Example 62 with ServerAccessToken

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

the class TokenGrantHandlerTest method testSimpleGrantSupported.

@Test
public void testSimpleGrantSupported() {
    SimpleGrantHandler handler = new SimpleGrantHandler();
    handler.setDataProvider(new OAuthDataProviderImpl());
    ServerAccessToken t = handler.createAccessToken(createClient("a"), createMap("a"));
    assertTrue(t instanceof BearerAccessToken);
}
Also used : ServerAccessToken(org.apache.cxf.rs.security.oauth2.common.ServerAccessToken) BearerAccessToken(org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken) Test(org.junit.Test)

Aggregations

ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)41 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)19 Client (org.apache.cxf.rs.security.oauth2.common.Client)16 Test (org.junit.Test)16 OAuthPermission (org.apache.cxf.rs.security.oauth2.common.OAuthPermission)13 RefreshToken (org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken)12 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)10 UserSubject (org.apache.cxf.rs.security.oauth2.common.UserSubject)9 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)6 ServerAuthorizationCodeGrant (org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant)6 BearerAccessToken (org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 JoseJwtConsumer (org.apache.cxf.rs.security.jose.jwt.JoseJwtConsumer)3 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)3 Ignore (org.junit.Ignore)3