Search in sources :

Example 1 with BookStore

use of org.apache.cxf.systest.jaxrs.security.BookStore in project cxf by apache.

the class JAXRSXmlSecTest method testEncryptionNoSignature.

@Test
public void testEncryptionNoSignature() throws Exception {
    if (test.streaming) {
        // Only testing the endpoints, not the clients here
        return;
    }
    String address = "https://localhost:" + test.port + "/xmlsec-validate";
    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.ENCRYPT_USERNAME, "bob");
    properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/bob.properties");
    properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties");
    bean.setProperties(properties);
    XmlEncOutInterceptor encInterceptor = new XmlEncOutInterceptor();
    encInterceptor.setKeyIdentifierType(RSSecurityUtils.X509_CERT);
    encInterceptor.setSymmetricEncAlgorithm(XMLCipher.AES_128);
    bean.getOutInterceptors().add(encInterceptor);
    bean.getInInterceptors().add(new XmlEncInInterceptor());
    bean.getInInterceptors().add(new XmlSigInInterceptor());
    bean.setServiceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    try {
        store.addBook(new Book("CXF", 126L));
        fail("Failure expected on no Signature");
    } catch (WebApplicationException ex) {
    // expected
    }
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.BookStore) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) XmlEncOutInterceptor(org.apache.cxf.rs.security.xml.XmlEncOutInterceptor) URL(java.net.URL) XmlSigInInterceptor(org.apache.cxf.rs.security.xml.XmlSigInInterceptor) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Book(org.apache.cxf.systest.jaxrs.security.Book) XmlEncInInterceptor(org.apache.cxf.rs.security.xml.XmlEncInInterceptor) Test(org.junit.Test)

Example 2 with BookStore

use of org.apache.cxf.systest.jaxrs.security.BookStore in project cxf by apache.

the class JAXRSXmlSecTest method testSignatureNoEncryption.

@Test
public void testSignatureNoEncryption() throws Exception {
    if (test.streaming) {
        // Only testing the endpoints, not the clients here
        return;
    }
    String address = "https://localhost:" + test.port + "/xmlsec-validate";
    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.ENCRYPT_USERNAME, "bob");
    properties.put(SecurityConstants.ENCRYPT_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/bob.properties");
    properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties");
    bean.setProperties(properties);
    XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
    bean.getOutInterceptors().add(sigInterceptor);
    bean.getInInterceptors().add(new XmlEncInInterceptor());
    bean.getInInterceptors().add(new XmlSigInInterceptor());
    bean.setServiceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    try {
        store.addBook(new Book("CXF", 126L));
        fail("Failure expected on no Encryption");
    } catch (WebApplicationException ex) {
    // expected
    }
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.BookStore) XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) URL(java.net.URL) XmlSigInInterceptor(org.apache.cxf.rs.security.xml.XmlSigInInterceptor) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Book(org.apache.cxf.systest.jaxrs.security.Book) XmlEncInInterceptor(org.apache.cxf.rs.security.xml.XmlEncInInterceptor) Test(org.junit.Test)

Example 3 with BookStore

use of org.apache.cxf.systest.jaxrs.security.BookStore in project cxf by apache.

the class JAXRSXmlSecTest method testPostBookWithNoSig.

@Test
public void testPostBookWithNoSig() throws Exception {
    if (test.streaming) {
        // Only testing the endpoints, not the clients here
        return;
    }
    String address = "https://localhost:" + test.port + "/xmlsig";
    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);
    bean.setServiceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    try {
        store.addBook(new Book("CXF", 126L));
        fail("Failure expected on no Signature");
    } catch (WebApplicationException ex) {
    // expected
    }
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.BookStore) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) WebApplicationException(javax.ws.rs.WebApplicationException) Book(org.apache.cxf.systest.jaxrs.security.Book) URL(java.net.URL) Test(org.junit.Test)

Example 4 with BookStore

use of org.apache.cxf.systest.jaxrs.security.BookStore in project cxf by apache.

the class JAXRSXmlSecTest method testOldConfiguration.

@Test
public void testOldConfiguration() throws Exception {
    String address = "https://localhost:" + test.port + "/xmlsig";
    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> newProperties = new HashMap<>();
    newProperties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
    newProperties.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
    String cryptoUrl = "org/apache/cxf/systest/jaxrs/security/alice.properties";
    newProperties.put(SecurityConstants.SIGNATURE_PROPERTIES, cryptoUrl);
    bean.setProperties(newProperties);
    if (test.streaming) {
        XmlSecOutInterceptor sigInterceptor = new XmlSecOutInterceptor();
        sigInterceptor.setSignRequest(true);
        bean.getOutInterceptors().add(sigInterceptor);
    } else {
        XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
        bean.getOutInterceptors().add(sigInterceptor);
    }
    bean.setServiceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    Book book = store.addBook(new Book("CXF", 126L));
    assertEquals(126L, book.getId());
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.BookStore) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) HashMap(java.util.HashMap) Book(org.apache.cxf.systest.jaxrs.security.Book) XmlSecOutInterceptor(org.apache.cxf.rs.security.xml.XmlSecOutInterceptor) URL(java.net.URL) Test(org.junit.Test)

Example 5 with BookStore

use of org.apache.cxf.systest.jaxrs.security.BookStore in project cxf by apache.

the class JAXRSXmlSecTest method doTestSignatureProxy.

private void doTestSignatureProxy(String address, boolean enveloping, String cryptoUrlPrefix, boolean streaming, Map<String, Object> properties) throws Exception {
    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> newProperties = new HashMap<>(properties);
    if (newProperties.isEmpty()) {
        newProperties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback");
        newProperties.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
        String cryptoUrl = "org/apache/cxf/systest/jaxrs/security/alice.properties";
        if (cryptoUrlPrefix != null) {
            cryptoUrl = cryptoUrlPrefix + this.getClass().getResource("/" + cryptoUrl).toURI().getPath();
        }
        newProperties.put(SecurityConstants.SIGNATURE_PROPERTIES, cryptoUrl);
    }
    bean.setProperties(newProperties);
    if (streaming) {
        XmlSecOutInterceptor sigInterceptor = new XmlSecOutInterceptor();
        sigInterceptor.setSignRequest(true);
        bean.getOutInterceptors().add(sigInterceptor);
    } else {
        XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor();
        if (enveloping) {
            sigInterceptor.setStyle(XmlSigOutInterceptor.ENVELOPING_SIG);
        }
        bean.getOutInterceptors().add(sigInterceptor);
    }
    bean.setServiceClass(BookStore.class);
    BookStore store = bean.create(BookStore.class);
    Book book = store.addBook(new Book("CXF", 126L));
    assertEquals(126L, book.getId());
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.security.BookStore) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) HashMap(java.util.HashMap) Book(org.apache.cxf.systest.jaxrs.security.Book) XmlSecOutInterceptor(org.apache.cxf.rs.security.xml.XmlSecOutInterceptor) URL(java.net.URL)

Aggregations

URL (java.net.URL)5 Bus (org.apache.cxf.Bus)5 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)5 Book (org.apache.cxf.systest.jaxrs.security.Book)5 BookStore (org.apache.cxf.systest.jaxrs.security.BookStore)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 XmlSigOutInterceptor (org.apache.cxf.rs.security.xml.XmlSigOutInterceptor)3 XmlEncInInterceptor (org.apache.cxf.rs.security.xml.XmlEncInInterceptor)2 XmlSecOutInterceptor (org.apache.cxf.rs.security.xml.XmlSecOutInterceptor)2 XmlSigInInterceptor (org.apache.cxf.rs.security.xml.XmlSigInInterceptor)2 XmlEncOutInterceptor (org.apache.cxf.rs.security.xml.XmlEncOutInterceptor)1