Search in sources :

Example 16 with SamlCallbackHandler

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

the class SamlSubjectConfTest method testHOKNonMatchingCert.

// Sign using "alice"
@org.junit.Test
public void testHOKNonMatchingCert() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlSubjectConfTest.class.getResource("client-auth.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    try {
        port.doubleIt(25);
        fail("Failure expected on a non matching cert (SAML -> TLS)");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) port).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 17 with SamlCallbackHandler

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

the class SamlSubjectConfTest method testBearer.

// 
// Bearer does not require client auth, but it does require an internal signature
// 
@org.junit.Test
public void testBearer() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlSubjectConfTest.class.getResource("client-auth.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
    callbackHandler.setCryptoAlias("morpit");
    callbackHandler.setCryptoPassword("password");
    callbackHandler.setCryptoPropertiesFile("morpit.properties");
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    int result = port.doubleIt(25);
    assertTrue(result == 50);
    ((java.io.Closeable) port).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 18 with SamlCallbackHandler

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

the class SamlSubjectConfTest method testSVNoClientAuthentication.

@org.junit.Test
public void testSVNoClientAuthentication() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlSubjectConfTest.class.getResource("client-noauth.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, false);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    try {
        port.doubleIt(25);
        fail("Failure expected on no client auth");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) port).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 19 with SamlCallbackHandler

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

the class SamlSubjectConfTest method testHOKNoClientAuthentication.

@org.junit.Test
public void testHOKNoClientAuthentication() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlSubjectConfTest.class.getResource("client-noauth.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, true);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_HOLDER_KEY);
    callbackHandler.setCryptoAlias("morpit");
    callbackHandler.setCryptoPassword("password");
    callbackHandler.setCryptoPropertiesFile("morpit.properties");
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    try {
        port.doubleIt(25);
        fail("Failure expected on no client auth");
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
    // expected
    }
    ((java.io.Closeable) port).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 20 with SamlCallbackHandler

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

the class SamlSubjectConfTest method testSVClientAuthentication.

// 
// SV requires client auth. The server is set up not to require client auth to
// test this. SV does not require an internal signature unlike HOK.
// 
@org.junit.Test
public void testSVClientAuthentication() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SamlSubjectConfTest.class.getResource("client-auth.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SamlSubjectConfTest.class.getResource("DoubleItSamlSubjectConf.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSaml2TransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Successful call
    SamlCallbackHandler callbackHandler = new SamlCallbackHandler(true, false);
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
    int result = port.doubleIt(25);
    assertTrue(result == 50);
    ((java.io.Closeable) port).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