Search in sources :

Example 1 with JSONWebKey

use of org.xdi.oxauth.model.jwk.JSONWebKey in project oxAuth by GluuFederation.

the class JwkRestWebServiceHttpTest method requestClientJwks.

@Parameters({ "clientJwksUri" })
@Test
public void requestClientJwks(final String clientJwksUri) throws Exception {
    showTitle("requestJwks");
    JwkClient jwkClient = new JwkClient(clientJwksUri);
    JwkResponse response = jwkClient.exec();
    showClient(jwkClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getEntity(), "Unexpected result: entity is null");
    assertNotNull(response.getJwks(), "Unexpected result: jwks is null");
    assertNotNull(response.getJwks().getKeys(), "Unexpected result: keys is null");
    assertTrue(response.getJwks().getKeys().size() > 0, "Unexpected result: keys is empty");
    for (JSONWebKey JSONWebKey : response.getJwks().getKeys()) {
        assertNotNull(JSONWebKey.getKid(), "Unexpected result: kid is null");
        assertNotNull(JSONWebKey.getUse(), "Unexpected result: use is null");
    }
}
Also used : JSONWebKey(org.xdi.oxauth.model.jwk.JSONWebKey) JwkResponse(org.xdi.oxauth.client.JwkResponse) JwkClient(org.xdi.oxauth.client.JwkClient) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with JSONWebKey

use of org.xdi.oxauth.model.jwk.JSONWebKey in project oxAuth by GluuFederation.

the class JwkResponse method getPublicKey.

@Deprecated
public PublicKey getPublicKey(String keyId) {
    PublicKey publicKey = null;
    JSONWebKey JSONWebKey = getKeyValue(keyId);
    if (JSONWebKey != null) {
        switch(JSONWebKey.getKty()) {
            case RSA:
                publicKey = new RSAPublicKey(JSONWebKey.getN(), JSONWebKey.getE());
                break;
            case EC:
                publicKey = new ECDSAPublicKey(JSONWebKey.getAlg(), JSONWebKey.getX(), JSONWebKey.getY());
                break;
            default:
                break;
        }
    }
    return publicKey;
}
Also used : JSONWebKey(org.xdi.oxauth.model.jwk.JSONWebKey) RSAPublicKey(org.xdi.oxauth.model.crypto.signature.RSAPublicKey) RSAPublicKey(org.xdi.oxauth.model.crypto.signature.RSAPublicKey) ECDSAPublicKey(org.xdi.oxauth.model.crypto.signature.ECDSAPublicKey) PublicKey(org.xdi.oxauth.model.crypto.PublicKey) ECDSAPublicKey(org.xdi.oxauth.model.crypto.signature.ECDSAPublicKey)

Example 3 with JSONWebKey

use of org.xdi.oxauth.model.jwk.JSONWebKey in project oxAuth by GluuFederation.

the class JwkResponse method getKeys.

public List<JSONWebKey> getKeys(SignatureAlgorithm algorithm) {
    List<JSONWebKey> jsonWebKeys = new ArrayList<JSONWebKey>();
    if (SignatureAlgorithmFamily.RSA.equals(algorithm.getFamily())) {
        for (JSONWebKey jsonWebKey : jwks.getKeys()) {
            if (jsonWebKey.getAlg().equals(algorithm)) {
                jsonWebKeys.add(jsonWebKey);
            }
        }
    } else if (SignatureAlgorithmFamily.EC.equals(algorithm.getFamily())) {
        for (JSONWebKey jsonWebKey : jwks.getKeys()) {
            if (jsonWebKey.getAlg().equals(algorithm)) {
                jsonWebKeys.add(jsonWebKey);
            }
        }
    }
    Collections.sort(jsonWebKeys);
    return jsonWebKeys;
}
Also used : JSONWebKey(org.xdi.oxauth.model.jwk.JSONWebKey) ArrayList(java.util.ArrayList)

Example 4 with JSONWebKey

use of org.xdi.oxauth.model.jwk.JSONWebKey in project oxAuth by GluuFederation.

the class JwkRestWebServiceHttpTest method requestJwks.

@Test
public void requestJwks() throws Exception {
    showTitle("requestJwks");
    JwkClient jwkClient = new JwkClient(jwksUri);
    JwkResponse response = jwkClient.exec();
    showClient(jwkClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getEntity(), "Unexpected result: entity is null");
    assertNotNull(response.getJwks(), "Unexpected result: jwks is null");
    assertNotNull(response.getJwks().getKeys(), "Unexpected result: keys is null");
    assertTrue(response.getJwks().getKeys().size() > 0, "Unexpected result: keys is empty");
    for (JSONWebKey JSONWebKey : response.getJwks().getKeys()) {
        assertNotNull(JSONWebKey.getKid(), "Unexpected result: kid is null");
        assertNotNull(JSONWebKey.getUse(), "Unexpected result: use is null");
    }
}
Also used : JSONWebKey(org.xdi.oxauth.model.jwk.JSONWebKey) JwkResponse(org.xdi.oxauth.client.JwkResponse) JwkClient(org.xdi.oxauth.client.JwkClient) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

JSONWebKey (org.xdi.oxauth.model.jwk.JSONWebKey)4 Test (org.testng.annotations.Test)2 BaseTest (org.xdi.oxauth.BaseTest)2 JwkClient (org.xdi.oxauth.client.JwkClient)2 JwkResponse (org.xdi.oxauth.client.JwkResponse)2 ArrayList (java.util.ArrayList)1 Parameters (org.testng.annotations.Parameters)1 PublicKey (org.xdi.oxauth.model.crypto.PublicKey)1 ECDSAPublicKey (org.xdi.oxauth.model.crypto.signature.ECDSAPublicKey)1 RSAPublicKey (org.xdi.oxauth.model.crypto.signature.RSAPublicKey)1