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

The following examples show how to use org.apache.cxf.BusFactory#setThreadDefaultBus() . 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 File: MTOMSecurityTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAsymmetricBinaryBytesInAttachment() 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, "DoubleItAsymmetricBinaryPort");
    DoubleItMtomPortType port =
            service.getPort(portQName, DoubleItMtomPortType.class);
    updateAddressPort(port, PORT);

    DataSource source = new FileDataSource(new File("src/test/resources/java.jpg"));
    DoubleIt4 doubleIt = new DoubleIt4();
    doubleIt.setNumberToDouble(25);
    assertEquals(50, port.doubleIt4(25, new DataHandler(source)));

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 2
Source File: X509TokenTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSymmetricSignature() 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("DoubleItX509Signature.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSignaturePort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

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

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 3
Source File: ActionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSignedSAML() throws Exception {

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

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

    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignedSAMLPort");
    DoubleItPortType port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    assertEquals(50, port.doubleIt(25));

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 4
Source File: CrossDomainTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCrossDomainMEX() throws Exception {

    if (!portFree) {
        return;
    }

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

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

    URL wsdl = CrossDomainTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItCrossDomainMEXPort");
    DoubleItPortType transportPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT);

    // Transport port
    doubleIt(transportPort, 25);

    ((java.io.Closeable)transportPort).close();
    bus.shutdown(true);
}
 
Example 5
Source File: UsernameTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * 2.1.3 (WSS 1.0) UsernameToken with Mutual X.509v3 Authentication, Sign, Encrypt
 */
@org.junit.Test
public void testAsymmetricSESupporting() 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, "DoubleItAsymmetricSESupportingPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

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

    utPort.doubleIt(25);

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 6
Source File: BinarySecurityTokenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testBadBinarySecurityToken() throws Exception {

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

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

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

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

    try {
        doubleIt(asymmetricBSTPort, 30);
        fail("Expected failure on a bad cert");
    } catch (javax.xml.ws.soap.SOAPFaultException fault) {
        // expected
    }

    ((java.io.Closeable)asymmetricBSTPort).close();
    bus.shutdown(true);
}
 
Example 7
Source File: PolicyAlternativeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * The client uses a Transport binding policy with a Endorsing Supporting X509 Token as well as a
 * Signed Endorsing UsernameToken. Here the client is trying to trick the Service Provider as
 * the UsernameToken signs the wsa:To Header, not the X.509 Token.
 */
@org.junit.Test
public void testTransportUTSupportingSigned() throws Exception {

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

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

    URL wsdl = PolicyAlternativeTest.class.getResource("DoubleItPolicy.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportUTSupportingSignedPort");
    DoubleItPortType transportPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT2);

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

    try {
        transportPort.doubleIt(25);
        fail("Failure expected on not signing a wsa header");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        // expected
    }

    ((java.io.Closeable)transportPort).close();
    bus.shutdown(true);
}
 
Example 8
Source File: PartsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSOAPFaultError() throws Exception {

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

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

    URL wsdl = PartsTest.class.getResource("DoubleItParts.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    // This should fail, as the service requires a (bad) header
    QName portQName = new QName(NAMESPACE, "DoubleItRequiredPartsPort2");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        port.doubleIt(25);
        fail("Failure expected on a required header which isn't present");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "RequiredParts: No header element";
        assertTrue(ex.getMessage().contains(error)
                   || ex.getMessage().contains("ToTo must be present"));
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 9
Source File: AsymmetricBindingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUsernameTokenSAML2() throws Exception {

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

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

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

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

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

    doubleIt(asymmetricSaml2Port, 30);
    TokenTestUtils.verifyToken(asymmetricSaml2Port);

    ((java.io.Closeable)asymmetricSaml2Port).close();
    bus.shutdown(true);
}
 
Example 10
Source File: SWAPolicyTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSWAEncryptionContentPolicy() throws Exception {

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

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

    URL wsdl = SWAPolicyTest.class.getResource("DoubleItSwa.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSWAEncryptionContentPolicyPort");
    DoubleItSwaPortType port =
            service.getPort(portQName, DoubleItSwaPortType.class);
    updateAddressPort(port, test.getPort());

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

    DoubleIt3 doubleIt = new DoubleIt3();
    doubleIt.setNumberToDouble(25);
    DoubleItResponse response = port.doubleIt3(doubleIt, "12345".getBytes());
    assertEquals(50, response.getDoubledNumber());

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 11
Source File: Soap12Test.java    From cxf with 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
Source File: GCMTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAESGCM192() throws Exception {
    if (!unrestrictedPoliciesInstalled) {
        return;
    }

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = GCMTest.class.getResource("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, "DoubleItGCM192Port");
    DoubleItPortType gcmPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(gcmPort, test.getPort());


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

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

    ((java.io.Closeable)gcmPort).close();
    bus.shutdown(true);
}
 
Example 13
Source File: HostnameVerificationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testNoSubjectAlternativeNameNoCNMatch() 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, PORT4);

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

    try {
        port.greetMe("Kitty");
        fail("Failure expected with no matching Subject Alt Name or CN");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 14
Source File: SamlSubjectConfTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testBearer() throws Exception {

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

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

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

    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);

    callbackHandler.setCryptoAlias("morpit");
    callbackHandler.setCryptoPassword("password");
    callbackHandler.setCryptoPropertiesFile("morpit.properties");

    ((BindingProvider)port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler
    );
    int result = port.doubleIt(25);
    assertTrue(result == 50);

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 15
Source File: CipherSuitesTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAESIncludedTLSv13ViaCode() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }
    Assume.assumeTrue(JavaUtils.isJava11Compatible());

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.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, PORT);

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

    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    TLSClientParameters tlsParams = new TLSClientParameters();
    TrustManager[] trustManagers = InsecureTrustManager.getNoOpX509TrustManagers();
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);

    tlsParams.setSecureSocketProtocol("TLSv1.3");
    tlsParams.setCipherSuites(Collections.singletonList("TLS_AES_128_GCM_SHA256"));

    conduit.setTlsClientParameters(tlsParams);

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

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 16
Source File: DirectDispatchClientTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startServers() throws Exception {
    staticBus = BusFactory.getDefaultBus();
    BusFactory.setThreadDefaultBus(staticBus);
    assertTrue("server did not launch correctly", launchServer(Server.class, true));
}
 
Example 17
Source File: BindingPropertiesTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testTimestampFirst() throws Exception {

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

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

    URL wsdl = BindingPropertiesTest.class.getResource("DoubleItBindings.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);

    // Successful invocation
    QName portQName = new QName(NAMESPACE, "DoubleItTimestampFirstPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    // TODO Timestamp First/Last validation not working - see WSS-444
    if (!STAX_PORT.equals(test.getPort())) {
        assertEquals(50, port.doubleIt(25));
    }

    // This should fail, as the client is sending the timestamp last
    portQName = new QName(NAMESPACE, "DoubleItTimestampFirstPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        // TODO Timestamp First/Last validation not working - see WSS-444
        if (!STAX_PORT.equals(test.getPort())) {
            port.doubleIt(25);
            fail("Failure expected on on sending the timestamp last");
        }
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "Layout does not match the requirements";
        assertTrue(ex.getMessage().contains(error));
    }

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

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

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

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

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

    try {
        port.doubleIt(25);
        fail("(Policy) Failure expected on not using a client cert");
    } catch (Exception ex) {
        // expected
    }

    // This should work, as we're disable the RequireClientCertificate check via a
    // JAX-WS property
    portQName = new QName(NAMESPACE, "DoubleItNoClientCertRequirementPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

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

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 19
Source File: HttpsTokenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testRequireClientCert() throws Exception {

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

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

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

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

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

    // This should fail, as the client does not use a client cert
    portQName = new QName(NAMESPACE, "DoubleItRequireClientCertPort2");
    port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());

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

    try {
        port.doubleIt(25);
        fail("Failure expected on not using a client cert");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        if (!STAX_PORT.equals(test.getPort())) {
            String error = "HttpsToken";
            assertTrue(ex.getMessage().contains(error));
        }
    }

    ((java.io.Closeable)port).close();
    bus.shutdown(true);
}
 
Example 20
Source File: X509TokenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testTransportSupportingSignedCertConstraints() 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, "DoubleItTransportSupportingSignedCertConstraintsPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    String port = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        port = STAX_PORT2;
    }
    updateAddressPort(x509Port, port);

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

    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
            "bob.properties");
    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");

    try {
        x509Port.doubleIt(25);
        fail("Failure expected on bob");
    } catch (Exception ex) {
        // expected
    }

    x509Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, port);

    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
        "alice.properties");
    ((BindingProvider)x509Port).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "alice");

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

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}