use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowWithKey.
@org.junit.Test
public void testAuthorizationCodeFlowWithKey() throws Exception {
String address = "https://localhost:" + port + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, "openid");
assertNotNull(code);
// Now get the access token
client = WebClient.create(address, "consumer-id", "this-is-a-secret", null);
ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code);
assertNotNull(accessToken.getTokenKey());
assertTrue(accessToken.getApprovedScope().contains("openid"));
String idToken = accessToken.getParameters().get("id_token");
assertNotNull(idToken);
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(idToken);
// Now get the key to validate the token
client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
client.accept("application/json");
client.path("keys/");
Response response = client.get();
JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class);
assertTrue(jwtConsumer.verifySignatureWith(jsonWebKeys.getKeys().get(0), SignatureAlgorithm.RS256));
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class OIDCKeysServiceTest method testGetRSAPublicKey.
@org.junit.Test
public void testGetRSAPublicKey() throws Exception {
URL busFile = OIDCFlowTest.class.getResource("client.xml");
String address = "https://localhost:" + JCACHE_SERVER.getPort() + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString());
client.accept("application/json");
client.path("keys/");
Response response = client.get();
JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class);
assertEquals(1, jsonWebKeys.getKeys().size());
JsonWebKey jsonWebKey = jsonWebKeys.getKeys().get(0);
assertEquals(KeyType.RSA, jsonWebKey.getKeyType());
assertEquals("alice", jsonWebKey.getKeyId());
assertNotNull(jsonWebKey.getProperty("n"));
assertNotNull(jsonWebKey.getProperty("e"));
// Check we don't send the private key back
checkPrivateKeyParametersNotPresent(jsonWebKeys);
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class OIDCKeysServiceTest method testGetJWKECPublicKey.
@org.junit.Test
public void testGetJWKECPublicKey() throws Exception {
URL busFile = OIDCFlowTest.class.getResource("client.xml");
String address = "https://localhost:" + JCACHE_SERVER.getPort() + "/services3/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString());
client.accept("application/json");
client.path("keys/");
Response response = client.get();
JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class);
assertEquals(1, jsonWebKeys.getKeys().size());
JsonWebKey jsonWebKey = jsonWebKeys.getKeys().get(0);
assertEquals(KeyType.EC, jsonWebKey.getKeyType());
assertEquals("ECKey", jsonWebKey.getKeyId());
assertNotNull(jsonWebKey.getProperty("x"));
assertNotNull(jsonWebKey.getProperty("y"));
// Check we don't send the private key back
checkPrivateKeyParametersNotPresent(jsonWebKeys);
}
use of org.apache.cxf.rs.security.jose.jwk.JsonWebKeys in project cxf by apache.
the class OIDCKeysServiceTest method testGetJWKHMAC.
@org.junit.Test
public void testGetJWKHMAC() throws Exception {
URL busFile = OIDCFlowTest.class.getResource("client.xml");
String address = "https://localhost:" + JCACHE_SERVER.getPort() + "/services4/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString());
client.accept("application/json");
client.path("keys/");
Response response = client.get();
JsonWebKeys jsonWebKeys = response.readEntity(JsonWebKeys.class);
// We don't allow sending secret keys back from the key service by default
assertNull(jsonWebKeys.getKeys());
}
Aggregations