use of org.apache.cxf.rs.security.xml.SignatureProperties in project cxf by apache.
the class JAXRSXmlSecTest method testPostBookWithEnvelopedSigKeyName.
@Test
public void testPostBookWithEnvelopedSigKeyName() throws Exception {
// This test only applies to StAX - see CXF-7084
if (!test.streaming || !STAX_PORT.equals(test.port)) {
return;
}
String address = "https://localhost:" + test.port + "/xmlsigkeyname/bookstore/books";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSXmlSecTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
Map<String, Object> properties = new HashMap<>();
properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties");
bean.setProperties(properties);
XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
sigOutInterceptor.setSignRequest(true);
sigOutInterceptor.setKeyInfoMustBeAvailable(true);
SignatureProperties sigProps = new SignatureProperties();
sigProps.setSignatureKeyName("alice-kn");
sigProps.setSignatureKeyIdType("KeyName");
sigOutInterceptor.setSignatureProperties(sigProps);
bean.getOutInterceptors().add(sigOutInterceptor);
XmlSecInInterceptor sigInInterceptor = new XmlSecInInterceptor();
sigInInterceptor.setRequireSignature(true);
bean.setProvider(sigInInterceptor);
WebClient wc = bean.createWebClient();
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
Book book = wc.type("application/xml").post(new Book("CXF", 126L), Book.class);
assertEquals(126L, book.getId());
}
Aggregations