Search in sources :

Example 6 with SpringBusFactory

use of org.apache.cxf.bus.spring.SpringBusFactory in project camel by apache.

the class WSAddressingTest method testWSAddressing.

@Test
public void testWSAddressing() throws Exception {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(getClientAddress());
    clientBean.setServiceClass(Greeter.class);
    SpringBusFactory bf = new SpringBusFactory();
    URL cxfConfig = null;
    if (getCxfClientConfig() != null) {
        cxfConfig = ClassLoaderUtils.getResource(getCxfClientConfig(), this.getClass());
    }
    proxyFactory.setBus(bf.createBus(cxfConfig));
    Greeter client = (Greeter) proxyFactory.create();
    String result = client.greetMe("world!");
    assertEquals("Get a wrong response", "Hello world!", result);
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) URL(java.net.URL) Test(org.junit.Test)

Example 7 with SpringBusFactory

use of org.apache.cxf.bus.spring.SpringBusFactory in project camel by apache.

the class Server method prepare.

public void prepare() throws Exception {
    // Set a system property used to configure the server.  The examples all run on port 9091; 
    // however, the unit tests must run on a dynamic port.  As such, we make the port configurable
    // in the Spring context.
    System.setProperty("port", "9001");
    // setup the Camel context for the Camel transport
    // START SNIPPET: e1
    SpringBusFactory bf = new SpringBusFactory();
    BusFactory.setDefaultBus(null);
    Bus bus = bf.createBus("/org/apache/camel/example/camel/transport/CamelDestination.xml");
    BusFactory.setDefaultBus(bus);
// END SNIPPET: e1
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory)

Example 8 with SpringBusFactory

use of org.apache.cxf.bus.spring.SpringBusFactory in project ddf by codice.

the class StsIssueTest method testBearerPkiTokenSaml2.

/**
     * Test the User PKI Token
     */
public void testBearerPkiTokenSaml2(StsPortTypes portType) throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = StsIssueTest.class.getResource("/cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    // Build the Claims object
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement(WST, CLAIMS, STSUtils.WST_NS_05_12);
    writer.writeNamespace(WST, STSUtils.WST_NS_05_12);
    writer.writeNamespace(IC, IDENTITY_URI);
    writer.writeAttribute(DIALECT, IDENTITY_URI);
    // Add the Role claim
    writer.writeStartElement(IC, CLAIM_TYPE, IDENTITY_URI);
    writer.writeAttribute("URI", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
    writer.writeEndElement();
    Element claims = writer.getDocument().getDocumentElement();
    // Alerternatively we can use a certificate to request a SAML
    X509Security oboToken = new X509Security(doc);
    Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
    CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
    cryptoType.setAlias("client");
    X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
    if (null != certs) {
        oboToken.setX509Certificate(certs[0]);
        // Get a token
        SecurityToken token = requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, oboToken.getElement(), bus, StsAddresses.valueOf(portType.toString()).toString(), WsdlLocations.valueOf(portType.toString()).toString(), EndPoints.valueOf(portType.toString()).toString(), claims);
        if (token != null) {
            validateSecurityToken(token);
        }
    }
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) CryptoType(org.apache.wss4j.common.crypto.CryptoType) Document(org.w3c.dom.Document) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Crypto(org.apache.wss4j.common.crypto.Crypto) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) X509Security(org.apache.wss4j.common.token.X509Security)

Example 9 with SpringBusFactory

use of org.apache.cxf.bus.spring.SpringBusFactory in project camel by apache.

the class WSSecurityRouteTest method testUsernameToken.

@Test
public void testUsernameToken() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterUsernameTokenPort();
    ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + CXFTestSupport.getPort2() + "/WSSecurityRouteTest/GreeterUsernameTokenPort");
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.camel.hello_world_soap_http.Greeter) GreeterService(org.apache.camel.hello_world_soap_http.GreeterService) URL(java.net.URL) Test(org.junit.Test)

Example 10 with SpringBusFactory

use of org.apache.cxf.bus.spring.SpringBusFactory in project camel by apache.

the class WSSecurityRouteTest method testSecurityPolicy.

@Test
public void testSecurityPolicy() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = WSSecurityRouteTest.class.getResource("../client/wssec.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterSecurityPolicyPort();
    ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + CXFTestSupport.getPort2() + "/WSSecurityRouteTest/GreeterSecurityPolicyPort");
    assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security"));
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.camel.hello_world_soap_http.Greeter) GreeterService(org.apache.camel.hello_world_soap_http.GreeterService) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)14 URL (java.net.URL)10 Bus (org.apache.cxf.Bus)10 Test (org.junit.Test)8 Greeter (org.apache.camel.hello_world_soap_http.Greeter)4 GreeterService (org.apache.camel.hello_world_soap_http.GreeterService)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 W3CDOMStreamWriter (org.apache.cxf.staxutils.W3CDOMStreamWriter)3 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 QName (javax.xml.namespace.QName)2 CamelContext (org.apache.camel.CamelContext)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)2 UsernameToken (org.apache.wss4j.dom.message.token.UsernameToken)2 X509Certificate (java.security.cert.X509Certificate)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1