Search in sources :

Example 1 with SamlEnvelopedOutInterceptor

use of org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor in project cxf by apache.

the class JAXRSSamlAuthorizationTest method createWebClient.

private WebClient createWebClient(String address, Map<String, Object> extraProperties) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(address);
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAXRSSamlAuthorizationTest.class.getResource("client.xml");
    Bus springBus = bf.createBus(busFile.toString());
    bean.setBus(springBus);
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.SamlCallbackHandler");
    if (extraProperties != null) {
        properties.putAll(extraProperties);
    }
    bean.setProperties(properties);
    bean.getOutInterceptors().add(new SamlEnvelopedOutInterceptor());
    return bean.createWebClient();
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) HashMap(java.util.HashMap) SamlEnvelopedOutInterceptor(org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor) URL(java.net.URL)

Example 2 with SamlEnvelopedOutInterceptor

use of org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor in project cxf by apache.

the class JAXRSSamlTest method doTestEnvelopedSAMLToken.

public void doTestEnvelopedSAMLToken(boolean signed, CallbackHandler samlCallbackHandler) throws Exception {
    String address = "https://localhost:" + PORT + "/samlxml/bookstore/books";
    WebClient wc = createWebClient(address, new SamlEnvelopedOutInterceptor(!signed), null, samlCallbackHandler);
    XmlSigOutInterceptor xmlSig = new XmlSigOutInterceptor();
    if (signed) {
        xmlSig.setStyle(XmlSigOutInterceptor.DETACHED_SIG);
    }
    WebClient.getConfig(wc).getOutInterceptors().add(xmlSig);
    wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
    try {
        Book book = wc.post(new Book("CXF", 125L), Book.class);
        assertEquals(125L, book.getId());
    } catch (WebApplicationException ex) {
        fail(ex.getMessage());
    } catch (ProcessingException ex) {
        if (ex.getCause() != null && ex.getCause().getMessage() != null) {
            fail(ex.getCause().getMessage());
        } else {
            fail(ex.getMessage());
        }
    }
}
Also used : XmlSigOutInterceptor(org.apache.cxf.rs.security.xml.XmlSigOutInterceptor) WebApplicationException(javax.ws.rs.WebApplicationException) Book(org.apache.cxf.systest.jaxrs.security.Book) SamlEnvelopedOutInterceptor(org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

SamlEnvelopedOutInterceptor (org.apache.cxf.rs.security.saml.SamlEnvelopedOutInterceptor)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)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 XmlSigOutInterceptor (org.apache.cxf.rs.security.xml.XmlSigOutInterceptor)1 Book (org.apache.cxf.systest.jaxrs.security.Book)1