The OIOSAML Trust client can be used to invoke OIOIDWS (OIO Identity-based web services). These services require extra security headers in the soap requests, and this client can issue requests containing the correct headers and signatures.
Under normal circumstances, the client is used in conjunction with a OIOSAML.java enabled web application. However, this is not a strict requirement, but the default {@link dk.itst.oiosaml.trust.TrustClient} constructor cannot be used, as it expects the OIOSAML.java filter to be enabled.
oiosaml-trust.certificate.location=certificate/sts-certificate oiosaml-trust.certificate.password=Test1234 oiosaml-trust.certificate.alias=mykey
In other words, the configuration must specify a keystore with the STS certificate, password for the keystore and an alias if the keystore contains multiple certificates.
Furthermore, depending on how the IdP works, set:
oiosaml-trust.bootstrap.base64=true|falseThis property controls how the bootstrap attribute is read from the user's assertion. If the property is set to true (the default), the client expects the bootstrap attribute value to be a base64 encoded string. Otherwise, the client expects regular XML as the attribute value.
A usage example:
String serviceEndpointAddress = "http://localhost:8080/poc-provider/EchoService";
TrustClient tokenClient = new TrustClient();
tokenClient.setSoapVersion(SOAPConstants.SOAP11_NS);
tokenClient.setUseReferenceForOnBehalfOf(false);
tokenClient.setIssuer(SPMetadata.getInstance().getEntityID());
tokenClient.setAppliesTo(serviceEndpointAddress);
// retrieve token from sts
Assertion stsToken = tokenClient.getToken(null);
String stsXml = XMLHelper.nodeToString(stsToken);
System.out.println("Received token from STS: " + stsXml);
// send service request
// jaxb generated class
Echo request = new Echo();
tokenClient.getServiceClient().sendRequest(request,
JAXBContext.newInstance(Echo.class, EchoResponse.class),
serviceEndpointAddress,
"http://provider.poc.saml.itst.dk/EchoService/echoRequest",
null,
new ResultHandler<EchoResponse>() {
public void handleResult(EchoResponse result) throws Exception {
System.out.println("Client request: " + tokenClient.getLastRequestXML());
System.out.println("Response: " + result.getOutput());
}
});
The main class for the client is {@link dk.itst.oiosaml.trust.TrustClient}. By default, no other classes are necessary.
The general usage pattern is to call getToken(), which contacts the STS to get a new service token on behalf of the current user (using a WS-Trust Issue request). The token is stored in the client, and when sendRequest() is called, the token is added to the request automatically.
The STS address is retrieved from an EndpointReference (EPR) element. By default, the client expects that the current UserAssertion contains the EPR an attribute called "urn:liberty:disco:2006-08:DiscoveryEPR". One of the elements in the EPR is the STS endpoint location. The EPR also contains a SAML assertion identifying the user, which is sent to the STS.
client.addFaultHander("urn:test", "fault", new FaultHandler() {
public void handleFault(QName faultCode, String faultMessage, XMLObject detail) {
assertEquals("test", faultMessage);
assertEquals("urn:test", detail.getElementQName().getNamespaceURI());
assertEquals("fault", detail.getElementQName().getLocalPart());
// do something
}
});
Fault handlers are configured based in the namespace and local name of the fault detail element. If a fault handler is executed, the normal resulthandler is not executed.
By default, all header elements and the body are signed. If this is not the intended behaviour, it is possible to configure signing using a {@link dk.itst.oiosaml.trust.SigningPolicy}, which can be injected into the TrustClient.
The SigningPolicy specifies which elements (identified by their QNames) should be signed. The policy also has a default policy which matches all elements which have not been described explicitely.
An example:SigningPolicy policy = new SigningPolicy(false); policy.addPolicy(To.ELEMENT_NAME, true); policy.addPolicy(ReplyTo.ELEMENT_NAME, true); tokenClient.setSigningPolicy(policy);