Java Code Examples for org.apache.cxf.BusFactory

The following examples show how to use org.apache.cxf.BusFactory. 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: steady   Source File: STSClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureViaEPR() throws Exception {

    final Set<Class<?>> addressingClasses = new HashSet<Class<?>>();
    addressingClasses.add(org.apache.cxf.ws.addressing.wsdl.ObjectFactory.class);
    addressingClasses.add(org.apache.cxf.ws.addressing.ObjectFactory.class);

    JAXBContext ctx = JAXBContextCache.getCachedContextAndSchemas(addressingClasses, null, null, null,
                                                                  true).getContext();
    Unmarshaller um = ctx.createUnmarshaller();
    InputStream inStream = getClass().getResourceAsStream("epr.xml");
    JAXBElement<?> el = (JAXBElement<?>)um.unmarshal(inStream);
    EndpointReferenceType ref = (EndpointReferenceType)el.getValue();

    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient client = new STSClient(bus);
    client.configureViaEPR(ref, false);

    assertEquals("http://localhost:8080/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl",
                 client.getWsdlLocation());
    assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService"),
                 client.getServiceQName());
    assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port"),
                 client.getEndpointQName());
}
 
Example 2
Source Project: steady   Source File: STSClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureViaEPR() throws Exception {

    final Set<Class<?>> addressingClasses = new HashSet<Class<?>>();
    addressingClasses.add(org.apache.cxf.ws.addressing.wsdl.ObjectFactory.class);
    addressingClasses.add(org.apache.cxf.ws.addressing.ObjectFactory.class);

    JAXBContext ctx = JAXBContextCache.getCachedContextAndSchemas(addressingClasses, null, null, null,
                                                                  true).getContext();
    Unmarshaller um = ctx.createUnmarshaller();
    InputStream inStream = getClass().getResourceAsStream("epr.xml");
    JAXBElement<?> el = (JAXBElement<?>)um.unmarshal(inStream);
    EndpointReferenceType ref = (EndpointReferenceType)el.getValue();

    Bus bus = BusFactory.getThreadDefaultBus();
    STSClient client = new STSClient(bus);
    client.configureViaEPR(ref, false);

    assertEquals("http://localhost:8080/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl",
                 client.getWsdlLocation());
    assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService"),
                 client.getServiceQName());
    assertEquals(new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port"),
                 client.getEndpointQName());
}
 
Example 3
Source Project: cxf   Source File: UsernameTokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testPlaintextWSDLOverHTTPS() throws Exception {

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

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

    URL wsdl = new URL("https://localhost:" + PORT + "/DoubleItUTPlaintext?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 4
Source Project: cxf   Source File: MTOMSecurityTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSignedMTOMAction() 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, "DoubleItSignedMTOMActionPort");
    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 5
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSymmetricWithOptionalAddressing() 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("DoubleItX509Addressing.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricAddressingPort");
    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 6
Source Project: cxf   Source File: UsernameTokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSignedEncrypted() 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, "DoubleItSignedEncryptedPort");
    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 7
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testKeyIdentifierEncryptBeforeSigning() 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, "DoubleItKeyIdentifierEncryptBeforeSigningPort");
    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 8
Source Project: cxf   Source File: RetransmissionQueueTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void run()  {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus("/org/apache/cxf/systest/ws/rm/message-loss.xml");
    BusFactory.setDefaultBus(bus);
    LoggingInInterceptor in = new LoggingInInterceptor();
    bus.getInInterceptors().add(in);
    bus.getInFaultInterceptors().add(in);
    LoggingOutInterceptor out = new LoggingOutInterceptor();
    bus.getOutInterceptors().add(out);
    bus.getOutFaultInterceptors().add(out);

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

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

    LOG.info("Published greeter endpoint.");
}
 
Example 9
Source Project: cxf   Source File: RMPolicyWsdlTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void run()  {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus(getConfigPath());
    BusFactory.setDefaultBus(bus);
    setBus(bus);

    ServerRegistry sr = bus.getExtension(ServerRegistry.class);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);

    List<PolicyAssertion> assertions1
        = getAssertions(pe, sr.getServers().get(0));
    assertEquals("2 assertions should be available", 2, assertions1.size());
    List<PolicyAssertion> assertions2 =
        getAssertions(pe, sr.getServers().get(1));
    assertEquals("1 assertion should be available", 1, assertions2.size());

    LOG.info("Published greeter endpoints.");
}
 
Example 10
Source Project: cxf   Source File: AbstractResourceInfo.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void clearAllMaps() {
    Bus bus = BusFactory.getThreadDefaultBus(false);
    if (bus != null) {
        Object property = bus.getProperty(FIELD_PROXY_MAP);
        if (property != null) {
            ((Map)property).clear();
        }
        property = bus.getProperty(SETTER_PROXY_MAP);
        if (property != null) {
            ((Map)property).clear();
        }
        property = bus.getProperty(CONSTRUCTOR_PROXY_MAP);
        if (property != null) {
            ((Map)property).clear();
        }
    }
}
 
Example 11
Source Project: cxf   Source File: ServiceInvocationAckBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void setupGreeter(String cfgResource) throws NumberFormatException, MalformedURLException {

        SpringBusFactory bf = new SpringBusFactory();

        controlBus = bf.createBus();
        BusFactory.setDefaultBus(controlBus);

        ControlService cs = new ControlService();
        control = cs.getControlPort();
        updateAddressPort(control, getPort());

        assertTrue("Failed to start greeter", control.startGreeter(cfgResource));

        System.setProperty("db.name", getPrefix());
        greeterBus = bf.createBus(cfgResource);
        BusFactory.setDefaultBus(greeterBus);
        System.clearProperty("db.name");
        LOG.fine("Initialised greeter bus with configuration: " + cfgResource);

        GreeterService gs = new GreeterService();

        greeter = gs.getGreeterPort();
        updateAddressPort(greeter, getPort());
        LOG.fine("Created greeter client.");

    }
 
Example 12
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testAsymmetricEncryptBeforeSigningNoEnc() 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, "DoubleItAsymmetricEncryptBeforeSigningNoEncPort");
    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 13
Source Project: cxf   Source File: ClientMtomXopWithJMSTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startServers() throws Exception {
    Object implementor = new TestMtomJMSImpl();
    bus = BusFactory.getDefaultBus();

    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    PooledConnectionFactory cfp = new PooledConnectionFactory(cf);
    cff = new ConnectionFactoryFeature(cfp);

    EndpointImpl ep = (EndpointImpl)Endpoint.create(implementor);
    ep.getFeatures().add(cff);
    ep.getInInterceptors().add(new TestMultipartMessageInterceptor());
    ep.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    //ep.getInInterceptors().add(new LoggingInInterceptor());
    //ep.getOutInterceptors().add(new LoggingOutInterceptor());
    SOAPBinding jaxWsSoapBinding = (SOAPBinding)ep.getBinding();
    jaxWsSoapBinding.setMTOMEnabled(true);
    ep.publish();
}
 
Example 14
Source Project: cxf   Source File: BusExtensionLoadingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the ExtensionManagerBus can be built using a given classloader
 *
 * @throws Exception
 */
@Test
public void testBusConstructionWithoutTCCL() throws Exception {
    ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(new TestClassLoader());
        BusFactory factory = new CXFBusFactory() {
            public Bus createBus(Map<Class<?>, Object> e, Map<String, Object> properties) {
                return new ExtensionManagerBus(e, properties, this.getClass().getClassLoader());
            }
        };
        Bus bus = factory.createBus();
        assertNotNullExtensions(bus);
        bus.shutdown(true);
    } finally {
        Thread.currentThread().setContextClassLoader(origClassLoader);
    }
}
 
Example 15
Source Project: cxf   Source File: JMSTransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
public static void startBusAndJMS(String brokerURI) {
    try {
        transactionManager = new GeronimoTransactionManager();
    } catch (XAException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    bus = BusFactory.getDefaultBus();
    registerTransactionManager();
    ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory(brokerURI);
    cf1.setRedeliveryPolicy(redeliveryPolicy());
    JcaPooledConnectionFactory pcf = new JcaPooledConnectionFactory();
    pcf.setTransactionManager(transactionManager);
    pcf.setConnectionFactory(cf1);
    cf = pcf;
    cff = new ConnectionFactoryFeature(pcf);
}
 
Example 16
Source Project: cxf   Source File: StaxEndorsingServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    URL busFile = StaxEndorsingServer.class.getResource("stax-endorsing-server.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    setBus(busLocal);

    try {
        new StaxEndorsingServer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 17
Source Project: cxf   Source File: ControlImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean startGreeter(String cfgResource) {
    SpringBusFactory bf = new SpringBusFactory();
    System.setProperty("db.name", dbName);
    if (StringUtils.isEmpty(cfgResource)) {
        greeterBus = bf.createBus();
    } else {
        greeterBus = bf.createBus(cfgResource);
    }
    System.clearProperty("db.name");
    BusFactory.setDefaultBus(greeterBus);
    LOG.info("Initialised bus " + greeterBus + " with cfg file resource: " + cfgResource);
    LOG.fine("greeterBus inInterceptors: " + greeterBus.getInInterceptors());

    LoggingFeature lf = new LoggingFeature();
    lf.setPrettyLogging(true);
    lf.initialize(greeterBus);

    if (cfgResource.indexOf("provider") == -1) {
        endpoint = Endpoint.publish(address, implementor);
        LOG.info("Published greeter endpoint.");
    } else {
        endpoint = Endpoint.publish(address, new GreeterProvider());
        LOG.info("Published greeter provider.");
    }

    return true;
}
 
Example 18
Source Project: cxf   Source File: HTTPGetTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testHTTPGetSignedBody() throws Exception {
    if (!TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        return;
    }

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

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

    String address = "http://localhost:" + PORT + "/DoubleItSignBody/DoubleIt";
    WebClient client = WebClient.create(address);
    client.query("numberToDouble", "20");
    /*
    XMLSource result = client.get(XMLSource.class);
    result.setBuffering(true);

    String input = result.getNode("//doubledNumber", String.class);
    assertTrue(input.startsWith("<doubledNumber>40"));
    */

    try {
        client.get(XMLSource.class);
        fail("Failure expected on security policy failure");
    } catch (Exception ex) {
        // expected
    }

    bus.shutdown(true);
}
 
Example 19
Source Project: cxf   Source File: SamlTokenTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSaml1SelfSignedOverTransportSP11() 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, "DoubleItSaml1SelfSignedTransportSP11Port");
    DoubleItPortType saml1Port =
            service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml1Port, portNumber);

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

    ((BindingProvider)saml1Port).getRequestContext().put(
        SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler(false, true)
    );
    int result = saml1Port.doubleIt(25);
    assertTrue(result == 50);

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

    try {
        new Server();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 21
Source Project: cxf   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    URL busFile = Server.class.getResource("cxf-service.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    setBus(busLocal);

    try {
        new Server();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 22
Source Project: cxf   Source File: JAASTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUnsuccessfulAuthorizationPassthroughInvocation() 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, "DoubleItUTPort3");
    DoubleItPortType utPort =
        service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, PORT);

    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.USERNAME, "bob");
    ((BindingProvider)utPort).getRequestContext().put(
        SecurityConstants.PASSWORD, "trombone");

    try {
        doubleIt(utPort, 25);
        fail("Failure expected on an incorrect role");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 23
Source Project: cxf   Source File: JAASServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    URL busFile = JAASServer.class.getResource("server-continuation.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    busLocal.getInInterceptors().add(this.createTestJaasLoginInterceptor());
    busLocal.getInInterceptors().add(new BeforeServiceInvokerInterceptor());
    setBus(busLocal);

    try {
        new JAASServer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 24
Source Project: cxf   Source File: RevocationServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void run() {
    SpringBusFactory bf = new SpringBusFactory();
    Bus springBus = bf.createBus(SERVER_CONFIG_FILE);
    BusFactory.setDefaultBus(springBus);
    setBus(springBus);

    try {
        new BookServerOAuth2RevocationJCacheJWT();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 25
Source Project: cxf   Source File: SAMLDelegationTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSAMLOnBehalfOf() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SAMLDelegationTest.class.getResource("cxf-client.xml");

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

    // Get a token from the UT endpoint first
    SecurityToken token =
        requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, bus,
                             DEFAULT_ADDRESS, "Transport_UT_Port");
    assertEquals(SAML2_TOKEN_TYPE, token.getTokenType());
    assertNotNull(token.getToken());

    // Use the first token as OnBehalfOf to get another token

    // First try with the UT endpoint. This should fail as there is no Delegation Handler.
    try {
        requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, token.getToken(), bus,
                                 DEFAULT_ADDRESS, true, "Transport_UT_Port");
        fail("Failure expected on no delegation handler");
    } catch (Exception ex) {
        // expected
    }

    // Now send to the Transport endpoint.
    SecurityToken token2 =
        requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, token.getToken(), bus,
                             DEFAULT_ADDRESS, true, "Transport_Port");
    assertEquals(SAML2_TOKEN_TYPE, token2.getTokenType());
    assertNotNull(token2.getToken());

    bus.shutdown(true);
}
 
Example 26
Source Project: cxf   Source File: HTTPGetTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testSignedBodyTimestamp() throws Exception {
    if (!TestUtilities.checkUnrestrictedPoliciesInstalled()) {
        return;
    }

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

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

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

    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;");

    bus.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

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

    bus.shutdown(true);
}
 
Example 27
Source Project: cxf   Source File: JAASTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testUnsuccessfulAuthentication() 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, PORT);

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

    try {
        doubleIt(utPort, 25);
        fail("Failure expected on an incorrect password");
    } catch (Exception ex) {
        // expected
    }

    ((java.io.Closeable)utPort).close();
    bus.shutdown(true);
}
 
Example 28
Source Project: cxf   Source File: X509TokenTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testAsymmetricEndorsing() 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, "DoubleItAsymmetricEndorsingPort");
    DoubleItPortType x509Port =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(x509Port, test.getPort());

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

    if (!test.isStreaming() && !STAX_PORT.equals(test.getPort())) {
        assertEquals(50, x509Port.doubleIt(25));
    }

    ((java.io.Closeable)x509Port).close();
    bus.shutdown(true);
}
 
Example 29
Source Project: cxf   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
protected Server() throws Exception {
    System.out.println("Starting Server");

    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = Server.class.getResource("/server.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);

    Object implementor = new GreeterImpl();
    String address = "http://localhost:9000/SoapContext/SoapPort";
    Endpoint.publish(address, implementor, new LoggingFeature());
}
 
Example 30
Source Project: cxf   Source File: X509SymmetricBindingTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testX509SAML2Endorsing() throws Exception {

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

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

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

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

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

    // TODO Streaming client is not including a separate main Signature
    if (!test.isStreaming()) {
        doubleIt(symmetricSaml2Port, 30);
    }

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