Search in sources :

Example 1 with SignatureProperties

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());
}
Also used : Bus(org.apache.cxf.Bus) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) HashMap(java.util.HashMap) XmlSecInInterceptor(org.apache.cxf.rs.security.xml.XmlSecInInterceptor) XmlSecOutInterceptor(org.apache.cxf.rs.security.xml.XmlSecOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Book(org.apache.cxf.systest.jaxrs.security.Book) SignatureProperties(org.apache.cxf.rs.security.xml.SignatureProperties) Test(org.junit.Test)

Aggregations

URL (java.net.URL)1 HashMap (java.util.HashMap)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 SignatureProperties (org.apache.cxf.rs.security.xml.SignatureProperties)1 XmlSecInInterceptor (org.apache.cxf.rs.security.xml.XmlSecInInterceptor)1 XmlSecOutInterceptor (org.apache.cxf.rs.security.xml.XmlSecOutInterceptor)1 Book (org.apache.cxf.systest.jaxrs.security.Book)1 Test (org.junit.Test)1