use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.
the class SamlTokenTest method testSaml1SelfSignedOverTransport.
@org.junit.Test
public void testSaml1SelfSignedOverTransport() 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, "DoubleItSaml1SelfSignedTransportPort");
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);
}
use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.
the class SamlTokenTest method testSaml2OverAsymmetricEncrypted.
@org.junit.Test
public void testSaml2OverAsymmetricEncrypted() 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, "DoubleItSaml2AsymmetricEncryptedPort");
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_BEARER);
((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);
}
use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.
the class SamlTokenTest method testAudienceRestrictionServiceName.
@org.junit.Test
public void testAudienceRestrictionServiceName() 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, "DoubleItSaml2TransportPort2");
DoubleItPortType saml2Port = service.getPort(portQName, DoubleItPortType.class);
String portNumber = PORT2;
if (STAX_PORT.equals(test.getPort())) {
portNumber = STAX_PORT2;
}
updateAddressPort(saml2Port, portNumber);
// Create a SAML Token with an AudienceRestrictionCondition
ConditionsBean conditions = new ConditionsBean();
List<AudienceRestrictionBean> audienceRestrictions = new ArrayList<>();
AudienceRestrictionBean audienceRestriction = new AudienceRestrictionBean();
audienceRestriction.setAudienceURIs(Collections.singletonList(service.getServiceName().toString()));
audienceRestrictions.add(audienceRestriction);
conditions.setAudienceRestrictions(audienceRestrictions);
SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
callbackHandler.setConditions(conditions);
((BindingProvider) saml2Port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
saml2Port.doubleIt(25);
}
use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.
the class SamlSubjectConfTest method testHOKClientAuthentication.
//
// HOK requires client auth + a internally signed token. The server is set up not to
// require client auth to test this.
//
@org.junit.Test
public void testHOKClientAuthentication() 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_HOLDER_KEY);
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);
// Don't sign the Assertion
callbackHandler = new SamlCallbackHandler(true, false);
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 a unsigned assertion");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.apache.cxf.systest.ws.saml.client.SamlCallbackHandler in project cxf by apache.
the class SamlSubjectConfTest method testUnsignedBearer.
@org.junit.Test
public void testUnsignedBearer() 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_BEARER);
((BindingProvider) port).getRequestContext().put(SecurityConstants.SAML_CALLBACK_HANDLER, callbackHandler);
try {
port.doubleIt(25);
fail("Failure expected on an unsigned bearer token");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
((java.io.Closeable) port).close();
bus.shutdown(true);
}
Aggregations