Search in sources :

Example 11 with SpringBusFactory

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

the class CxfEndpointUtils method createBus.

/**
     * Create a CXF bus with either BusFactory or SpringBusFactory if Camel Context
     * is SpringCamelContext.  In the latter case, this method updates the bus 
     * configuration with the applicationContext which SpringCamelContext holds 
     * 
     * @param context - the Camel Context
     */
public static Bus createBus(CamelContext context) {
    BusFactory busFactory = BusFactory.newInstance();
    if (context instanceof SpringCamelContext) {
        SpringCamelContext springCamelContext = (SpringCamelContext) context;
        ApplicationContext applicationContext = springCamelContext.getApplicationContext();
        busFactory = new SpringBusFactory(applicationContext);
    }
    return busFactory.createBus();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) BusFactory(org.apache.cxf.BusFactory) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory)

Example 12 with SpringBusFactory

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

the class CamelDestinationTest method testCamelDestinationConfiguration.

@Test
public void testCamelDestinationConfiguration() throws Exception {
    QName testEndpointQName = new QName("http://camel.apache.org/camel-test", "port");
    // set up the bus with configure file
    SpringBusFactory bf = new SpringBusFactory();
    BusFactory.setDefaultBus(null);
    Bus bus = bf.createBus("/org/apache/camel/component/cxf/transport/CamelDestination.xml");
    BusFactory.setDefaultBus(bus);
    endpointInfo.setAddress("camel://direct:EndpointA");
    endpointInfo.setName(testEndpointQName);
    CamelDestination destination = new CamelDestination(null, bus, null, endpointInfo);
    assertEquals("{http://camel.apache.org/camel-test}port.camel-destination", destination.getBeanName());
    CamelContext context = destination.getCamelContext();
    assertNotNull("The camel context which get from camel destination is not null", context);
    assertEquals("Get the wrong camel context", context.getName(), "dest_context");
    assertEquals("The camel context should has two routers", context.getRoutes().size(), 2);
    bus.shutdown(false);
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 13 with SpringBusFactory

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

the class StsIssueTest method testBearerWebSsoTokenSaml2.

/**
     * Test the Web SSO Token
     */
public void testBearerWebSsoTokenSaml2(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();
    // Create a Username Token
    UsernameToken oboToken = new UsernameToken(false, doc, WSConstants.PASSWORD_TEXT);
    // Workout the details of how to fill out the username token
    // ID - the Key that tells the validator its an SSO token
    // Name - the SSO ticket
    oboToken.setID(CAS_ID);
    oboToken.setName("ST-098ASDF13245WERT");
    // 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.writeAttribute(URI, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uid");
    writer.writeEndElement();
    Element claims = writer.getDocument().getDocumentElement();
    // 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 : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document) URL(java.net.URL)

Example 14 with SpringBusFactory

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

the class StsIssueTest method testBearerUsernameTokenSaml2.

/**
     * Test the Username Token
     */
public void testBearerUsernameTokenSaml2(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();
    // Create a Username Token
    UsernameToken oboToken = new UsernameToken(false, doc, WSConstants.PASSWORD_TEXT);
    oboToken.setName("pangerer");
    oboToken.setPassword("password");
    // 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.writeAttribute(URI, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uid");
    writer.writeEndElement();
    Element claims = writer.getDocument().getDocumentElement();
    // 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 : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) UsernameToken(org.apache.wss4j.dom.message.token.UsernameToken) Document(org.w3c.dom.Document) URL(java.net.URL)

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