use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method createJweJwsBookStore.
private BookStore createJweJwsBookStore(String address, JwsSignatureProvider jwsSigProvider, List<?> mbProviders) throws Exception {
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();
if (jwsSigProvider != null) {
jwsWriter.setSignatureProvider(jwsSigProvider);
}
jwsWriter.setUseJwsOutputStream(true);
providers.add(jwsWriter);
providers.add(new JwsClientResponseFilter());
if (mbProviders != null) {
providers.addAll(mbProviders);
}
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.encryption.out.properties", SERVER_JWEJWS_PROPERTIES);
bean.getProperties(true).put("rs.security.signature.out.properties", CLIENT_JWEJWS_PROPERTIES);
bean.getProperties(true).put("rs.security.encryption.in.properties", CLIENT_JWEJWS_PROPERTIES);
bean.getProperties(true).put("rs.security.signature.in.properties", SERVER_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);
return bean.create(BookStore.class);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JAXRSJweJwsTest method doTestJwsJwkRSA.
private void doTestJwsJwkRSA(String address, boolean includePublicKey, boolean includeKeyId) throws Exception {
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>();
JwsWriterInterceptor jwsWriter = new JwsWriterInterceptor();
jwsWriter.setUseJwsOutputStream(true);
providers.add(jwsWriter);
providers.add(new JwsClientResponseFilter());
bean.setProviders(providers);
bean.getProperties(true).put("rs.security.signature.out.properties", "org/apache/cxf/systest/jaxrs/security/alice.jwk.properties");
bean.getProperties(true).put("rs.security.signature.in.properties", "org/apache/cxf/systest/jaxrs/security/bob.jwk.properties");
if (includePublicKey) {
bean.getProperties(true).put("rs.security.signature.include.public.key", true);
}
if (includeKeyId) {
bean.getProperties(true).put("rs.security.signature.include.key.id", true);
}
BookStore bs = bean.create(BookStore.class);
String text = bs.echoText("book");
assertEquals("book", text);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JweJwsAlgorithmTest method testUnsignedTokenFailure.
@org.junit.Test
public void testUnsignedTokenFailure() throws Exception {
URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
JwsWriterInterceptor writerInterceptor = new JwsWriterInterceptor();
writerInterceptor.setSignatureProvider(new NoneJwsSignatureProvider());
providers.add(writerInterceptor);
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<>();
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/jwkPrivateSet.txt");
properties.put("rs.security.signature.algorithm", "none");
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JweJwsAlgorithmTest method testWrongSignatureAlgorithmKeyIncluded.
@org.junit.Test
public void testWrongSignatureAlgorithmKeyIncluded() throws Exception {
URL busFile = JweJwsAlgorithmTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwsWriterInterceptor());
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<>();
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/jwkPrivateSet.txt");
properties.put("rs.security.signature.algorithm", "PS256");
properties.put("rs.security.signature.include.public.key", true);
WebClient.getConfig(client).getRequestContext().putAll(properties);
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
use of org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor in project cxf by apache.
the class JweJwsReferenceTest method testSignatureIncludeCertSha1NegativeTest.
@org.junit.Test
public void testSignatureIncludeCertSha1NegativeTest() throws Exception {
URL busFile = JweJwsReferenceTest.class.getResource("client.xml");
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJsonProvider());
providers.add(new JwsWriterInterceptor());
String address = "http://localhost:" + PORT + "/jwsincludecertsha1/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", "morpit");
properties.put("rs.security.keystore.password", "password");
properties.put("rs.security.key.password", "password");
properties.put("rs.security.keystore.file", "keys/Morpit.jks");
properties.put("rs.security.signature.include.cert.sha1", "true");
WebClient.getConfig(client).getRequestContext().putAll(properties);
// Failure expected as we are signing using a cert not trusted by cxfca.jks
Response response = client.post(new Book("book", 123L));
assertNotEquals(response.getStatus(), 200);
}
Aggregations