Search in sources :

Example 91 with Service

use of javax.xml.ws.Service in project cxf by apache.

the class AsymmetricBindingTest method testUsernameTokenSAML1.

@org.junit.Test
public void testUsernameTokenSAML1() 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, "DoubleItAsymmetricSAML1Port");
    DoubleItPortType asymmetricSaml1Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(asymmetricSaml1Port, test.getPort());
    TokenTestUtils.updateSTSPort((BindingProvider) asymmetricSaml1Port, test.getStsPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(asymmetricSaml1Port);
    }
    doubleIt(asymmetricSaml1Port, 25);
    ((java.io.Closeable) asymmetricSaml1Port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 92 with Service

use of javax.xml.ws.Service in project cxf by apache.

the class AsymmetricBindingTest method testUsernameTokenSAML1Encrypted.

@org.junit.Test
public void testUsernameTokenSAML1Encrypted() 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, "DoubleItAsymmetricSAML1EncryptedPort");
    DoubleItPortType asymmetricSaml1EncryptedPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(asymmetricSaml1EncryptedPort, test.getPort());
    TokenTestUtils.updateSTSPort((BindingProvider) asymmetricSaml1EncryptedPort, test.getStsPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(asymmetricSaml1EncryptedPort);
    }
    // Set the X509Certificate manually on the STSClient (just to test that we can)
    BindingProvider bindingProvider = (BindingProvider) asymmetricSaml1EncryptedPort;
    STSClient stsClient = (STSClient) bindingProvider.getRequestContext().get(SecurityConstants.STS_CLIENT);
    if (stsClient == null) {
        stsClient = (STSClient) bindingProvider.getRequestContext().get("ws-" + SecurityConstants.STS_CLIENT);
    }
    Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
    CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
    cryptoType.setAlias("myclientkey");
    X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
    stsClient.setUseKeyCertificate(certs[0]);
    doubleIt(asymmetricSaml1EncryptedPort, 40);
    ((java.io.Closeable) asymmetricSaml1EncryptedPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) CryptoType(org.apache.wss4j.common.crypto.CryptoType) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) STSClient(org.apache.cxf.ws.security.trust.STSClient) Crypto(org.apache.wss4j.common.crypto.Crypto) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 93 with Service

use of javax.xml.ws.Service in project cxf by apache.

the class BearerTest method testSAML2Bearer.

@org.junit.Test
public void testSAML2Bearer() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = BearerTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = BearerTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2BearerPort");
    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, 45);
    ((java.io.Closeable) transportSaml2Port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 94 with Service

use of javax.xml.ws.Service in project cxf by apache.

the class IntermediaryCachingPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) {
    if (transportPort == null) {
        // Re-use the same proxy
        URL wsdl = IntermediaryCachingPortTypeImpl.class.getResource("DoubleIt.wsdl");
        Service service = Service.create(wsdl, SERVICE_QNAME);
        QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
        transportPort = service.getPort(portQName, DoubleItPortType.class);
        try {
            updateAddressPort(transportPort, IntermediaryTransformationCachingTest.PORT2);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if ("standalone".equals(System.getProperty("sts.deployment"))) {
            Map<String, Object> context = ((BindingProvider) transportPort).getRequestContext();
            STSClient stsClient = (STSClient) context.get(SecurityConstants.STS_CLIENT);
            if (stsClient == null) {
                stsClient = (STSClient) context.get("ws-" + SecurityConstants.STS_CLIENT);
            }
            if (stsClient != null) {
                String location = stsClient.getWsdlLocation();
                if (location.contains("8080")) {
                    stsClient.setWsdlLocation(location.replace("8080", IntermediaryTransformationCachingTest.STSPORT2));
                } else if (location.contains("8443")) {
                    stsClient.setWsdlLocation(location.replace("8443", IntermediaryTransformationCachingTest.STSPORT));
                }
            }
        }
    }
    Principal pr = wsc.getUserPrincipal();
    Assert.assertNotNull("Principal must not be null", pr);
    Assert.assertNotNull("Principal.getName() must not return null", pr.getName());
    // Disable the STSClient after the second invocation
    if (i > 1) {
        BindingProvider p = (BindingProvider) transportPort;
        STSClient stsClient = new STSClient(null);
        stsClient.setOnBehalfOf(new ReceivedTokenCallbackHandler());
        p.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    }
    i++;
    return transportPort.doubleIt(numberToDouble);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) QName(javax.xml.namespace.QName) ReceivedTokenCallbackHandler(org.apache.cxf.ws.security.trust.delegation.ReceivedTokenCallbackHandler) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Principal(java.security.Principal)

Example 95 with Service

use of javax.xml.ws.Service in project cxf by apache.

the class IntermediaryPortTypeImpl method doubleIt.

public int doubleIt(int numberToDouble) {
    Principal pr = wsc.getUserPrincipal();
    Assert.assertNotNull("Principal must not be null", pr);
    Assert.assertNotNull("Principal.getName() must not return null", pr.getName());
    URL wsdl = IntermediaryPortTypeImpl.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2Port");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    try {
        updateAddressPort(transportPort, IntermediaryTransformationTest.PORT2);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if ("standalone".equals(System.getProperty("sts.deployment"))) {
        Map<String, Object> context = ((BindingProvider) transportPort).getRequestContext();
        STSClient stsClient = (STSClient) context.get(SecurityConstants.STS_CLIENT);
        if (stsClient == null) {
            stsClient = (STSClient) context.get("ws-" + SecurityConstants.STS_CLIENT);
        }
        if (stsClient != null) {
            String location = stsClient.getWsdlLocation();
            if (location.contains("8080")) {
                stsClient.setWsdlLocation(location.replace("8080", IntermediaryTransformationTest.STSPORT2));
            } else if (location.contains("8443")) {
                stsClient.setWsdlLocation(location.replace("8443", IntermediaryTransformationTest.STSPORT));
            }
        }
    }
    return transportPort.doubleIt(numberToDouble);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) QName(javax.xml.namespace.QName) WebService(javax.jws.WebService) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) Principal(java.security.Principal) URL(java.net.URL)

Aggregations

Service (javax.xml.ws.Service)598 URL (java.net.URL)547 QName (javax.xml.namespace.QName)524 Bus (org.apache.cxf.Bus)399 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)384 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)361 Test (org.junit.Test)143 BindingProvider (javax.xml.ws.BindingProvider)63 Client (org.apache.cxf.endpoint.Client)43 HashMap (java.util.HashMap)36 SamlCallbackHandler (org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler)31 STSClient (org.apache.cxf.ws.security.trust.STSClient)28 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)25 WebServiceException (javax.xml.ws.WebServiceException)20 WebService (javax.jws.WebService)18 IOException (java.io.IOException)16 File (java.io.File)15 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)15 Greeter (org.apache.hello_world_soap_http.Greeter)15 KeystorePasswordCallback (org.apache.cxf.systest.ws.common.KeystorePasswordCallback)14