use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method testJweAesGcmDirect.
@Test
public void testJweAesGcmDirect() throws Exception {
String address = "https://localhost:" + PORT + "/jweaesgcmdirect";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<Object>();
// writer
JweWriterInterceptor jweWriter = new JweWriterInterceptor();
jweWriter.setUseJweOutputStream(true);
// reader
JweClientResponseFilter jweReader = new JweClientResponseFilter();
providers.add(jweWriter);
providers.add(jweReader);
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.encryption.properties", "org/apache/cxf/systest/jaxrs/security/jwe.direct.properties");
BookStore bs = bean.create(BookStore.class);
String text = bs.echoText("book");
assertEquals("book", text);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method testJweAesCbcHmac.
@Test
public void testJweAesCbcHmac() throws Exception {
String address = "https://localhost:" + PORT + "/jweaescbchmac";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<Object>();
// writer
JweWriterInterceptor jweWriter = new JweWriterInterceptor();
jweWriter.setUseJweOutputStream(true);
final String cekEncryptionKey = "GawgguFyGrWKav7AX4VKUg";
AesWrapKeyEncryptionAlgorithm keyEncryption = new AesWrapKeyEncryptionAlgorithm(cekEncryptionKey, KeyAlgorithm.A128KW);
jweWriter.setEncryptionProvider(new AesCbcHmacJweEncryption(ContentAlgorithm.A128CBC_HS256, keyEncryption));
// reader
JweClientResponseFilter jweReader = new JweClientResponseFilter();
jweReader.setDecryptionProvider(new AesCbcHmacJweDecryption(new AesWrapKeyDecryptionAlgorithm(cekEncryptionKey)));
providers.add(jweWriter);
providers.add(jweReader);
bean.setProviders(providers);
BookStore bs = bean.create(BookStore.class);
String text = bs.echoText("book");
assertEquals("book", text);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method doTestJweJwkAesCbcHMac.
private void doTestJweJwkAesCbcHMac(String propFile) throws Exception {
String address = "https://localhost:" + PORT + "/jwejwkaescbchmac";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<Object>();
JweWriterInterceptor jweWriter = new JweWriterInterceptor();
jweWriter.setUseJweOutputStream(true);
providers.add(jweWriter);
providers.add(new JweClientResponseFilter());
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.encryption.properties", propFile);
PrivateKeyPasswordProvider provider = new PrivateKeyPasswordProviderImpl("Thus from my lips, by yours, my sin is purged.");
bean.getProperties(true).put("rs.security.key.password.provider", provider);
BookStore bs = bean.create(BookStore.class);
String text = bs.echoText("book");
assertEquals("book", text);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method testJweRsaJwsRsaCert.
@Test
public void testJweRsaJwsRsaCert() throws Exception {
String address = "https://localhost:" + PORT + "/jwejwsrsacert";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSJweJwsTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
bean.setServiceClass(BookStore.class);
bean.setAddress(address);
List<Object> providers = new LinkedList<Object>();
JweWriterInterceptor jweWriter = new JweWriterInterceptor();
jweWriter.setUseJweOutputStream(true);
providers.add(jweWriter);
providers.add(new JweClientResponseFilter());
JwsWriterInterceptor jwsWriter = new JwsWriterInterceptor();
jwsWriter.setUseJwsOutputStream(true);
providers.add(jwsWriter);
providers.add(new JwsClientResponseFilter());
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.keystore.file", "org/apache/cxf/systest/jaxrs/security/certs/jwkPublicSet.txt");
bean.getProperties(true).put("rs.security.signature.out.properties", CLIENT_JWEJWS_PROPERTIES);
bean.getProperties(true).put("rs.security.encryption.in.properties", CLIENT_JWEJWS_PROPERTIES);
PrivateKeyPasswordProvider provider = new PrivateKeyPasswordProviderImpl();
bean.getProperties(true).put("rs.security.signature.key.password.provider", provider);
bean.getProperties(true).put("rs.security.decryption.key.password.provider", provider);
BookStore bs = bean.create(BookStore.class);
WebClient.getConfig(bs).getRequestContext().put("rs.security.keystore.alias.jwe.out", "AliceCert");
WebClient.getConfig(bs).getRequestContext().put("rs.security.keystore.alias.jws.in", "AliceCert");
String text = bs.echoText("book");
assertEquals("book", text);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JweWriterInterceptor in project cxf by apache.
the class JweJwsAlgorithmTest method testBadEncryptingKey.
@org.junit.Test
public void testBadEncryptingKey() 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", "AliceCert");
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));
assertNotEquals(response.getStatus(), 200);
}
Aggregations