Java Code Examples for org.apache.cxf.BusFactory#setDefaultBus()

The following examples show how to use org.apache.cxf.BusFactory#setDefaultBus() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   File: MTOMSecurityTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSymmetricBytesInAttachment() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = MTOMSecurityTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);

    int result = port.doubleIt(25);
    assertEquals(result, 50);

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 2
Source Project: cxf   File: UsernameTokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testPlaintext() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = UsernameTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = UsernameTokenTest.class.getResource("DoubleItUt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }

    assertEquals(50, utPort.doubleIt(25));

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 3
Source Project: cxf   File: StaxSTSServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    URL busFile = StaxSTSServer.class.getResource("stax-cxf-sts.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    setBus(busLocal);

    try {
        new StaxSTSServer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source Project: cxf   File: SamlTokenTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml2OverSymmetricSupporting() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2SymmetricSupportingPort");
    DoubleItPortType saml2Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }

    ((BindingProvider)saml2Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler()
    );

    try {
        saml2Port.doubleIt(25);
        fail("Expected failure on an invocation with an unsigned SAML SV Assertion");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("SamlToken not satisfied")
                   || ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
    }

    ((java.io.Closeable)saml2Port).close();
    bus.shutdown(true);
}
 
Example 5
Source Project: cxf   File: GCMTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAESGCM256MGFSHA256Digest() throws Exception {
    if (!unrestrictedPoliciesInstalled) {
        return;
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = GCMTest.class.getResource("mgf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = GCMTest.class.getResource("DoubleItGCM.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItGCM256MGFSHA256DigestPort");
    DoubleItPortType gcmPort =
            service.getPort(portQName, DoubleItPortType.class);

    String port = MGF_PORT;
    if (STAX_PORT.equals(test.getPort())) {
        port = MGF_STAX_PORT;
    }
    updateAddressPort(gcmPort, port);

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(gcmPort);
    }

    assertEquals(50, gcmPort.doubleIt(25));

    ((java.io.Closeable)gcmPort).close();
    bus.shutdown(true);
}
 
Example 6
Source Project: cxf   File: SSLv3Test.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSSL3ClientToEndpointWithSSL3Allowed() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SSLv3Test.class.getResource("sslv3-client-allow.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT4);

    port.greetMe("Kitty");

    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
 
Example 7
Source Project: cxf   File: X509TokenTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 2.2.1 (WSS1.0) X.509 Certificates, Sign, Encrypt
 */
@org.junit.Test
public void testAsymmetricSignEncrypt() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = X509TokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricSignEncryptPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(x509Port);
    }

    x509Port.doubleIt(25);

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 8
Source Project: cxf   File: SamlTokenTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 2.3.1.2 (WSS1.0) SAML1.1 Assertion (Sender Vouches) over SSL
 */
@org.junit.Test
public void testTLSSenderVouches() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlTokenTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SamlTokenTest.class.getResource("DoubleItSaml.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTLSSenderVouchesPort");
    DoubleItPortType samlPort =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(samlPort, portNumber);

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(samlPort);
    }

    samlPort.doubleIt(25);

    ((java.io.Closeable)samlPort).close();
    bus.shutdown(true);
}
 
Example 9
Source Project: cxf   File: Server2.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    URL busFile = Server2.class.getResource("cxf-service2.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    setBus(busLocal);

    try {
        new Server2();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source Project: cxf   File: JAASTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
@org.junit.Ignore
public void testSuccessfulInvocationConfig() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JAASTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = JAASTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItUTPort");
    DoubleItPortType utPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT2);

    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.USERNAME, "alice");
    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.PASSWORD, "clarinet");

    doubleIt(utPort, 25);

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 11
Source Project: cxf   File: Soap12Test.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSAML2() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = Soap12Test.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = Soap12Test.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
    DoubleItPortType transportSaml2Port =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportSaml2Port, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider)transportSaml2Port, test.getStsPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportSaml2Port);
    }

    doubleIt(transportSaml2Port, 30);

    ((java.io.Closeable)transportSaml2Port).close();
    bus.shutdown(true);
}
 
Example 12
@Test
public void testWithSecurityInPolicy() throws Exception {
    LOG.fine("Creating greeter client");

    try (ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/rm/sec/client-policy.xml")) {

        Bus bus = (Bus)context.getBean("bus");
        BusFactory.setDefaultBus(bus);
        BusFactory.setThreadDefaultBus(bus);

        Greeter greeter = (Greeter)context.getBean("GreeterCombinedClient");

        RMManager manager = bus.getExtension(RMManager.class);
        boolean empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue is not empty", empty);

        LOG.fine("Invoking greeter");
        greeter.greetMeOneWay("one");

        Thread.sleep(3000);

        empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue not empty", empty);

    }
}
 
Example 13
Source Project: cxf   File: DecoupledBareTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus("/org/apache/cxf/systest/ws/rm/decoupled_bare.xml");
    BusFactory.setDefaultBus(bus);
    setBus(bus);

    Object implementor = new DocLitBareGreeterImpl();
    String address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    ep = Endpoint.create(implementor);
    Map<String, Object> properties = new HashMap<>();
    properties.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
    ep.setProperties(properties);
    ep.publish(address);
    LOG.info("Published server endpoint.");
}
 
Example 14
@org.junit.Test
public void testNoSubjectAlternativeNameCNWildcardMatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HostnameVerificationTest.class.getResource("hostname-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);

    updateAddressPort(port, PORT3);

    // Enable Async
    if (async) {
        ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true);
    }

    assertEquals(port.greetMe("Kitty"), "Hello Kitty");

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 15
Source Project: cxf   File: ClaimsTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml1Claims() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ClaimsTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = ClaimsTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1ClaimsPort");
    DoubleItPortType transportClaimsPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportClaimsPort, test.getPort());

    TokenTestUtils.updateSTSPort((BindingProvider)transportClaimsPort, test.getStsPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(transportClaimsPort);
    }

    doubleIt(transportClaimsPort, 25);

    ((java.io.Closeable)transportClaimsPort).close();
    bus.shutdown(true);
}
 
Example 16
Source Project: cxf   File: ManagedEndpointsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    SpringBusFactory bf = new SpringBusFactory();
    serverBus = bf.createBus(SERVER_CFG);
    BusFactory.setDefaultBus(serverBus);
    setBus(serverBus);

    GreeterImpl implementor = new GreeterImpl();
    String address = "http://localhost:" + PORT + "/SoapContext/GreeterPort";

    ep = Endpoint.create(implementor);
    ep.publish(address);

    LOG.info("Published greeter endpoint.");
}
 
Example 17
Source Project: cxf   File: CryptoCoverageCheckerTest.java    License: Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testNotEncryptedUsernameToken() throws Exception {

    if (!unrestrictedPoliciesInstalled) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItEncryptedUsernameTokenPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "UsernameToken Encrypt");
    outProps.put("encryptionPropFile", "bob.properties");
    outProps.put("user", "alice");
    outProps.put("encryptionUser", "bob");
    outProps.put("passwordCallbackClass",
                 "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("encryptionParts",
                 "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;");

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }

    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }

    try {
        port.doubleIt(25);
        fail("Failure expected on not encrypting the UsernameToken");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 18
Source Project: cxf   File: SymmetricBindingTest.java    License: Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testUsernameTokenSAML1Dispatch() throws Exception {

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SymmetricBindingTest.class.getResource("cxf-client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = SymmetricBindingTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSAML1Port");

    Dispatch<DOMSource> dispatch =
        service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD, new AddressingFeature());
    updateAddressPort(dispatch, test.getPort());

    // Setup STSClient
    STSClient stsClient = createDispatchSTSClient(bus);
    String wsdlLocation = "http://localhost:" + test.getStsPort() + "/SecurityTokenService/UT?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);

    // Creating a DOMSource Object for the request
    DOMSource request = createDOMRequest();

    // Make a successful request
    Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
    client.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    //client.getRequestContext().put("find.dispatch.operation", Boolean.TRUE);


    if (test.isStreaming()) {
        client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
        client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    }

    DOMSource response = dispatch.invoke(request);
    assertNotNull(response);

    bus.shutdown(true);
}
 
Example 19
Source Project: cxf   File: CryptoCoverageCheckerTest.java    License: Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testSignedBodyTimestamp() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");

    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItBodyTimestampPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

    Map<String, Object> outProps = new HashMap<>();
    outProps.put("action", "Timestamp Signature");
    outProps.put("signaturePropFile", "alice.properties");
    outProps.put("user", "alice");
    outProps.put("passwordCallbackClass",
                 "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
    outProps.put("signatureParts",
                 "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;"
                 + "{}{http://docs.oasis-open.org/wss/2004/01/oasis-"
                 + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;");

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }

    if (test.isStreaming()) {
        WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
        bus.getOutInterceptors().add(staxOutInterceptor);
    } else {
        WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
        bus.getOutInterceptors().add(outInterceptor);
    }

    assertEquals(50, port.doubleIt(25));

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 20
Source Project: cxf   File: RMManagerConfigurationTest.java    License: Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    bus.shutdown(true);
    BusFactory.setDefaultBus(null);
}