Search in sources :

Example 81 with Service

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

the class DifferentRealmTest method testRealmTransform.

/**
 * In this test, a token is issued by the first STS in realm "A". The second STS is configured
 * to trust realm "A" (via a cert constraint) and so authentication succeeds. The service
 * endpoint also sends a tokenType (SAML2) to the second STS, and so the IdentityMapper is
 * invoked to transform the authenticated principal into a principal in the current realm.
 */
@org.junit.Test
public void testRealmTransform() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = DifferentRealmTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = DifferentRealmTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItRealmTransformPort");
    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 82 with Service

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

the class SAMLRenewTest method testRenewExpiredTokens.

@org.junit.Test
public void testRenewExpiredTokens() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SAMLRenewTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SAMLRenewTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName saml1PortQName = new QName(NAMESPACE, "DoubleItTransportSaml1Port");
    DoubleItPortType saml1Port = service.getPort(saml1PortQName, DoubleItPortType.class);
    updateAddressPort(saml1Port, PORT);
    QName saml1BearerPortQName = new QName(NAMESPACE, "DoubleItTransportSaml1BearerPort");
    DoubleItPortType saml1BearerPort = service.getPort(saml1BearerPortQName, DoubleItPortType.class);
    updateAddressPort(saml1BearerPort, PORT);
    QName saml2PortQName = new QName(NAMESPACE, "DoubleItTransportSaml2Port");
    DoubleItPortType saml2Port = service.getPort(saml2PortQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, PORT);
    QName saml2NoRenewPortQName = new QName(NAMESPACE, "DoubleItTransportSaml2NoRenewPort");
    DoubleItPortType saml2NoRenewPort = service.getPort(saml2NoRenewPortQName, DoubleItPortType.class);
    updateAddressPort(saml2NoRenewPort, PORT);
    QName saml2IntermediaryPortQName = new QName(NAMESPACE, "DoubleItTransportSaml2IntermediaryPort");
    DoubleItPortType saml2IntermediaryPort = service.getPort(saml2IntermediaryPortQName, DoubleItPortType.class);
    updateAddressPort(saml2IntermediaryPort, PORT);
    ((BindingProvider) saml2IntermediaryPort).getRequestContext().put(SecurityConstants.USERNAME, "alice");
    // Make initial successful invocation(s)
    doubleIt(saml1Port, 25);
    doubleIt(saml1BearerPort, 30);
    doubleIt(saml2Port, 35);
    doubleIt(saml2NoRenewPort, 35);
    doubleIt(saml2IntermediaryPort, 40);
    // Now sleep to expire the token(s)
    Thread.sleep(8 * 1000);
    // The IssuedTokenInterceptorProvider should renew the token
    BindingProvider p = (BindingProvider) saml1Port;
    STSClient stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT);
    stsClient.setTtl(300);
    doubleIt(saml1Port, 25);
    try {
        // The IssuedTokenInterceptorProvider should renew the token - but it should fail on
        // lack of Proof-of-Possession
        doubleIt(saml1BearerPort, 30);
        fail("Expected failure on no Proof-of-Possession");
    } catch (Exception ex) {
    // expected
    }
    // The IssuedTokenInterceptorProvider should renew the token
    p = (BindingProvider) saml2Port;
    stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT);
    stsClient.setTtl(300);
    doubleIt(saml2Port, 35);
    // Renew should fail here, but it should fall back to issue
    doubleIt(saml2NoRenewPort, 35);
    doubleIt(saml2IntermediaryPort, 40);
    ((java.io.Closeable) saml1Port).close();
    ((java.io.Closeable) saml1BearerPort).close();
    ((java.io.Closeable) saml2Port).close();
    ((java.io.Closeable) saml2IntermediaryPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 83 with Service

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

the class JaxwsBasicAuthTest method testBadBasicAuth.

@org.junit.Test
public void testBadBasicAuth() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JaxwsBasicAuthTest.class.getResource("cxf-bad-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = JaxwsBasicAuthTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        doubleIt(port, 30);
        fail("Expected failure on a bad password");
    } catch (javax.xml.ws.soap.SOAPFaultException fault) {
        String message = fault.getMessage();
        assertTrue(message.contains("STS Authentication failed") || message.contains("Validation of security token failed"));
    }
    ((java.io.Closeable) port).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 84 with Service

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

the class SecureConversationTest method testSecureConversationSymmetric.

@org.junit.Test
public void testSecureConversationSymmetric() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SecureConversationTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SecureConversationTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSecureConvPort");
    DoubleItPortType symmetricPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(symmetricPort, PORT2);
    doubleIt(symmetricPort, 30);
    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 85 with Service

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

the class Soap12Test method testSAML2.

@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);
}
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