Search in sources :

Example 91 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class SamlTokenTest method testSaml2OverAsymmetric.

@org.junit.Test
public void testSaml2OverAsymmetric() 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, "DoubleItSaml2AsymmetricPort");
    DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }
    try {
        saml2Port.doubleIt(25);
        fail("Expected failure on an invocation with no SAML Assertion");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("No SAML CallbackHandler available"));
    }
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler(false));
    try {
        saml2Port.doubleIt(25);
        fail("Expected failure on an invocation with a SAML1 Assertion");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("Wrong SAML Version") || ex.getMessage().contains("enforces SamlVersion20Profile11 but we got 1.1"));
    }
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler());
    int result = saml2Port.doubleIt(25);
    assertTrue(result == 50);
    // Don't send any Token...failure expected
    portQName = new QName(NAMESPACE, "DoubleItSaml2AsymmetricPort2");
    saml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, PORT);
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler());
    try {
        saml2Port.doubleIt(25);
        fail("Failure expected on no token");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        String error = "The received token does not match the token inclusion requirement";
        assertTrue(ex.getMessage().contains(error));
    }
    ((java.io.Closeable) saml2Port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SamlCallbackHandler(org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType)

Example 92 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class SamlTokenTest method testSaml2EndorsingEncryptedOverTransport.

@org.junit.Test
public void testSaml2EndorsingEncryptedOverTransport() 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, "DoubleItSaml2EndorsingEncryptedTransportPort");
    DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
    String portNumber = PORT2;
    if (STAX_PORT.equals(test.getPort())) {
        portNumber = STAX_PORT2;
    }
    updateAddressPort(saml2Port, portNumber);
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    int result = saml2Port.doubleIt(25);
    assertTrue(result == 50);
    ((java.io.Closeable) saml2Port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SamlCallbackHandler(org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler) 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 93 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class SamlTokenTest method testSaml1SelfSignedOverTransportSP11.

@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);
}
Also used : Bus(org.apache.cxf.Bus) SamlCallbackHandler(org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler) 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 DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class SamlTokenTest method testAsymmetricSamlInitiator.

@org.junit.Test
public void testAsymmetricSamlInitiator() 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, "DoubleItAsymmetricSamlInitiatorPort");
    DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    int result = saml2Port.doubleIt(25);
    assertTrue(result == 50);
    ((java.io.Closeable) saml2Port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SamlCallbackHandler(org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler) 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 95 with DoubleItPortType

use of org.example.contract.doubleit.DoubleItPortType in project cxf by apache.

the class SamlTokenTest method testSymmetricSV.

/**
 * 2.3.2.4 (WSS1.1) SAML1.1/2.0 Sender Vouches with X.509 Certificate, Sign, Encrypt
 */
@org.junit.Test
public void testSymmetricSV() 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, "DoubleItSymmetricSVPort");
    DoubleItPortType samlPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(samlPort, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(samlPort);
    }
    // TODO Endorsing Streaming not supported yet Streaming
    if (!test.isStreaming()) {
        samlPort.doubleIt(25);
    }
    ((java.io.Closeable) samlPort).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

URL (java.net.URL)360 QName (javax.xml.namespace.QName)360 Service (javax.xml.ws.Service)360 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)360 Bus (org.apache.cxf.Bus)354 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)352 SamlCallbackHandler (org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler)31 Client (org.apache.cxf.endpoint.Client)22 STSClient (org.apache.cxf.ws.security.trust.STSClient)21 HashMap (java.util.HashMap)20 BindingProvider (javax.xml.ws.BindingProvider)17 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)15 WSS4JStaxOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor)13 KeystorePasswordCallback (org.apache.cxf.systest.ws.common.KeystorePasswordCallback)9 Test (org.junit.Test)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 BusException (org.apache.cxf.BusException)8 EndpointException (org.apache.cxf.endpoint.EndpointException)8 TokenStore (org.apache.cxf.ws.security.tokenstore.TokenStore)8 WebService (javax.jws.WebService)5