Bus bus = bf.createBus(busFile.toString());
SpringBusFactory.setDefaultBus(bus);
SpringBusFactory.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);
updateAddressPort(saml1Port, PORT2);
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(
"ws-security.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"));
}
((BindingProvider)saml1Port).getRequestContext().put(
"ws-security.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(
"ws-security.saml-callback-handler", new SamlCallbackHandler(false)
);