Search in sources :

Example 71 with Service

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

the class CrossDomainTest method testCrossDomainMEX.

// The Service references STS "b". The WSDL of STS "b" has an IssuedToken that references STS "a".
// So the client gets the WSDL of "b" via WS-MEX, which in turn has an IssuedToken policy.
// The client has a configured STSClient for this + uses it to get a token from "a", and in
// turn to use the returned token to get a token from "b", to access the service.
@org.junit.Test
public void testCrossDomainMEX() throws Exception {
    if (!portFree) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CrossDomainTest.class.getResource("cxf-client.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);
}
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 72 with Service

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

the class CustomParameterTest method testCustomParameterInRST2Validator.

// Here the custom parameter in the RST is parsed by the CustomUTValidator
@org.junit.Test
public void testCustomParameterInRST2Validator() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterPort");
    DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportClaimsPort, PORT);
    TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/UT?wsdl");
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put("security.sts.token.username", "myclientkey");
    properties.put("security.sts.token.properties", "clientKeystore.properties");
    properties.put("security.sts.token.usecert", "true");
    stsClient.setProperties(properties);
    ((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    // Failing test
    // Add custom content to the RST
    stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-unknown-realm</realm>");
    try {
        doubleIt(transportClaimsPort, 25);
        fail("Failure expected on the wrong realm");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) transportClaimsPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 73 with Service

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

the class CustomParameterTest method testCustomParameterInRSTClaimsHandler.

// Here the custom parameter in the RST is parsed by the CustomClaimsHandler
@org.junit.Test
public void testCustomParameterInRSTClaimsHandler() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterClaimsPort");
    DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportClaimsPort, PORT);
    TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/Transport?wsdl");
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}Transport_Port");
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put("security.sts.token.username", "myclientkey");
    properties.put("security.sts.token.properties", "clientKeystore.properties");
    properties.put("security.sts.token.usecert", "true");
    stsClient.setProperties(properties);
    ((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    // Successful test
    // Add custom content to the RST
    stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-realm</realm>");
    doubleIt(transportClaimsPort, 25);
    ((java.io.Closeable) transportClaimsPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 74 with Service

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

the class CustomParameterTest method testCustomParameterInRSTValidator.

// Here the custom parameter in the RST is parsed by the CustomUTValidator
@org.junit.Test
public void testCustomParameterInRSTValidator() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CustomParameterTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CustomParameterTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomParameterPort");
    DoubleItPortType transportClaimsPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportClaimsPort, PORT);
    TokenTestUtils.updateSTSPort((BindingProvider) transportClaimsPort, STSPORT);
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("https://localhost:" + STSPORT + "/SecurityTokenService/UT?wsdl");
    stsClient.setServiceName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}SecurityTokenService");
    stsClient.setEndpointName("{http://docs.oasis-open.org/ws-sx/ws-trust/200512/}UT_Port");
    Map<String, Object> properties = new HashMap<>();
    properties.put(SecurityConstants.USERNAME, "alice");
    properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    properties.put("security.sts.token.username", "myclientkey");
    properties.put("security.sts.token.properties", "clientKeystore.properties");
    properties.put("security.sts.token.usecert", "true");
    stsClient.setProperties(properties);
    ((BindingProvider) transportClaimsPort).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    // Successful test
    // Add custom content to the RST
    stsClient.setCustomContent("<realm xmlns=\"http://cxf.apache.org/custom\">custom-realm</realm>");
    doubleIt(transportClaimsPort, 25);
    ((java.io.Closeable) transportClaimsPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 75 with Service

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

the class CustomOnBehalfOfTest method testUsernameOnBehalfOfLocal.

@org.junit.Test
public void testUsernameOnBehalfOfLocal() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CustomOnBehalfOfTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = CustomOnBehalfOfTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportCustomBSTLocalPort");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT);
    // Transport port
    ((BindingProvider) transportPort).getRequestContext().put(SecurityConstants.USERNAME, "alice");
    doubleIt(transportPort, 25);
    ((java.io.Closeable) transportPort).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)

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