Search in sources :

Example 26 with SamlCallbackHandler

use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.

the class SamlTokenTest method testSaml1Supporting.

@org.junit.Test
public void testSaml1Supporting() 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, "DoubleItSaml1SupportingPort");
    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);
    }
    SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(false, true);
    samlCallbackHandler.setConfirmationMethod(SAML1Constants.CONF_BEARER);
    ((BindingProvider) saml1Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler);
    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 27 with SamlCallbackHandler

use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.

the class SamlTokenTest method testSaml1OverTransport.

@org.junit.Test
public void testSaml1OverTransport() 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, "DoubleItSaml1TransportPort");
    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);
    }
    try {
        saml1Port.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) saml1Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler());
    try {
        saml1Port.doubleIt(25);
        fail("Expected failure on an invocation with a SAML2 Assertion");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("Wrong SAML Version") || ex.getMessage().contains("enforces SamlVersion11Profile11 but we got 2.0"));
    }
    ((BindingProvider) saml1Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler(false));
    int result = saml1Port.doubleIt(25);
    assertTrue(result == 50);
    // Don't send any Token...failure expected
    portQName = new QName(NAMESPACE, "DoubleItSaml1TransportPort2");
    saml1Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml1Port, PORT2);
    ((BindingProvider) saml1Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler(false));
    try {
        saml1Port.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) saml1Port).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 28 with SamlCallbackHandler

use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.

the class SamlTokenTest method testSaml2OverSymmetricSupporting.

// Some negative tests. Send a sender-vouches assertion as a SupportingToken...this will
// fail as the provider will demand that there is a signature covering both the assertion
// and the message body.
@org.junit.Test
public void testSaml2OverSymmetricSupporting() 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, "DoubleItSaml2SymmetricSupportingPort");
    DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }
    ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler());
    try {
        saml2Port.doubleIt(25);
        fail("Expected failure on an invocation with an unsigned SAML SV Assertion");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        assertTrue(ex.getMessage().contains("SamlToken not satisfied") || ex.getMessage().equals(WSSecurityException.UNIFIED_SECURITY_ERR));
    }
    ((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 29 with SamlCallbackHandler

use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.

the class SamlTokenTest method testSaml2EndorsingOverTransportSP11.

@org.junit.Test
public void testSaml2EndorsingOverTransportSP11() 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, "DoubleItSaml2EndorsingTransportSP11Port");
    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 30 with SamlCallbackHandler

use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.

the class SamlTokenTest method testSaml2OverAsymmetricSignedEncryptedEncryptBeforeSigning.

@org.junit.Test
public void testSaml2OverAsymmetricSignedEncryptedEncryptBeforeSigning() 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, "DoubleItSaml2AsymmetricSignedEncryptedEncryptBeforeSigningPort");
    DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(saml2Port);
    }
    // TODO Only working for DOM client + server atm
    if (!test.isStreaming() && PORT.equals(test.getPort())) {
        ((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, new SamlCallbackHandler());
        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)

Aggregations

URL (java.net.URL)31 QName (javax.xml.namespace.QName)31 Service (javax.xml.ws.Service)31 Bus (org.apache.cxf.Bus)31 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)31 SamlCallbackHandler (org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler)31 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)31 ConditionsBean (org.apache.wss4j.common.saml.bean.ConditionsBean)4 ArrayList (java.util.ArrayList)3 AudienceRestrictionBean (org.apache.wss4j.common.saml.bean.AudienceRestrictionBean)3 Client (org.apache.cxf.endpoint.Client)1 SecurityHeaderCacheInterceptor (org.apache.cxf.systest.ws.ut.SecurityHeaderCacheInterceptor)1