use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.
the class JAXRSJwsJsonTest method testJweCompactJwsJsonBookBeanHmac.
@Test
public void testJweCompactJwsJsonBookBeanHmac() throws Exception {
if (!SecurityTestUtil.checkUnrestrictedPoliciesInstalled()) {
return;
}
String address = "https://localhost:" + PORT + "/jwejwsjsonhmac";
List<?> extraProviders = Arrays.asList(new JacksonJsonProvider(), new JweWriterInterceptor(), new JweClientResponseFilter());
String jwkStoreProperty = "org/apache/cxf/systest/jaxrs/security/secret.jwk.properties";
Map<String, Object> props = new HashMap<>();
props.put(JoseConstants.RSSEC_SIGNATURE_PROPS, jwkStoreProperty);
props.put(JoseConstants.RSSEC_ENCRYPTION_PROPS, jwkStoreProperty);
BookStore bs = createBookStore(address, props, extraProviders);
Book book = bs.echoBook(new Book("book", 123L));
assertEquals("book", book.getName());
assertEquals(123L, book.getId());
}
use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.
the class JweJwsAlgorithmTest method testSmallEncryptionKeySize.
// 1024 bits not allowed with RSA according to the spec
@org.junit.Test
public void testSmallEncryptionKeySize() throws Exception {
URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JweWriterInterceptor());
String address = "http://localhost:" + PORT + "/jwesmallkey/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jks");
properties.put("rs.security.keystore.alias", "smallkey");
properties.put("rs.security.keystore.password", "security");
properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/smallkeysize.jks");
properties.put("rs.security.encryption.content.algorithm", "A128GCM");
properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.
the class JweJwsAlgorithmTest method testManualSignature.
@org.junit.Test
public void testManualSignature() throws Exception {
URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
String address = "http://localhost:" + PORT + "/jws/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<>();
WebClient.getConfig(client).getRequestContext().putAll(properties);
String header = "eyJhbGciOiJSUzI1NiIsImN0eSI6Impzb24ifQ";
String payload = "eyJCb29rIjp7ImlkIjoxMjMsIm5hbWUiOiJib29rIn19";
String sig = "mZJVPy83atFNxQMeJqkVbR8t1srr9LgKBGT0hgiymjNepRgqedvFG5B8E8UPAzfzNLsos91gGdneUEKrWauU4GoDPTzngX" + "798aDP6lsn5bUoTMKLfaWp9uzHDIzLMjGkabn92nrIpdK4JKDYNjdSUJIT2L97jggg0aoLhJQHVw2LdF1fpYdM-HCyccNW" + "HQbAR7bDZdITZFnDi8b22QfHCqeLV7m4mBvNDtNX337wtoUKyjPYBMoWc12hHDCwQyu_gfW6zFioF5TGx-Ifg8hrFlnyUr" + "vnSdP-FUtXiGeWBIvE_L6gD7DfM4u9hkK757vTjjMR_pF2CW3pfSH-Ha8v0A";
// Successful test
Response response = client.post(header + "." + payload + "." + sig);
assertEquals(response.getStatus(), 200);
Book returnedBook = response.readEntity(Book.class);
assertEquals(returnedBook.getName(), "book");
assertEquals(returnedBook.getId(), 123L);
// No signature
response = client.post(header + "." + payload + ".");
assertNotEquals(response.getStatus(), 200);
// Modified signature
String sig2 = sig.replace('y', 'z');
response = client.post(header + "." + payload + "." + sig2);
assertNotEquals(response.getStatus(), 200);
// Modified payload
String payload2 = payload.replace('y', 'z');
response = client.post(header + "." + payload2 + "." + sig);
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.
the class JweJwsAlgorithmTest method testEncryptionDynamic.
@org.junit.Test
public void testEncryptionDynamic() throws Exception {
URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JweWriterInterceptor());
String address = "http://localhost:" + PORT + "/jweoaepgcm/bookstore/books";
WebClient client = WebClient.create(address, providers, busFile.toString());
client.type("application/json").accept("application/json");
Map<String, Object> properties = new HashMap<>();
properties.put("rs.security.keystore.type", "jwk");
properties.put("rs.security.keystore.alias", "2011-04-29");
properties.put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt");
properties.put("rs.security.encryption.content.algorithm", "A128GCM");
properties.put("rs.security.encryption.key.algorithm", "RSA-OAEP");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertEquals(response.getStatus(), 200);
Book returnedBook = response.readEntity(Book.class);
assertEquals(returnedBook.getName(), "book");
assertEquals(returnedBook.getId(), 123L);
}
use of org.apache.cxf.systest.jaxrs.security.Book in project cxf by apache.
the class JAXRSHTTPSignatureTest method testWrongHTTPMethod.
@Test
public void testWrongHTTPMethod() throws Exception {
URL busFile = JAXRSHTTPSignatureTest.class.getResource("client.xml");
ClientTestFilter signatureFilter = new ClientTestFilter();
signatureFilter.setHttpMethod("GET");
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/alice.jks", this.getClass()), "password".toCharArray());
PrivateKey privateKey = (PrivateKey) keyStore.getKey("alice", "password".toCharArray());
assertNotNull(privateKey);
MessageSigner messageSigner = new MessageSigner(keyId -> privateKey, "alice-key-id");
signatureFilter.setMessageSigner(messageSigner);
String address = "http://localhost:" + PORT + "/httpsig/bookstore/books";
WebClient client = WebClient.create(address, Collections.singletonList(signatureFilter), busFile.toString());
client.type("application/xml").accept("application/xml");
Response response = client.post(new Book("CXF", 126L));
assertEquals(400, response.getStatus());
}
Aggregations