0

I'm developing a web service that consumes another one. To authenticate with this other service, I have to use the SAML V2 protocol. How to programmatically consume this service in Java ?

My code without SSO:

HttpClient client = builder.build();

URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setScheme(test.getScheme());
uriBuilder.setHost(test.getHost());
uriBuilder.setPort(test.getPort());
uriBuilder.setPath("Path");
uriBuilder.addParameter("id","theID");
uriBuilder.addParameter("param", "param");
try {
  HttpUriRequest request = new HttpGet(uriBuilder.build());
  HttpResponse response = client.execute(request);
  return EntityUtils.toString(response.getEntity());
} catch (IOException | URISyntaxException e) {
  e.printStackTrace();
}
Pmsa
  • 5
  • 3

1 Answers1

0

You'll need to build a SAML response that meets the requirements of the target service and include it in the call. Your best option is OpenSAML or another "product" such as CXF that builds on top of it. See How to create a valid SAML 2.0 Assertion with OpenSAML library in Java for an OpenSAML example; CXF ships with good docs and examples.

identigral
  • 3,920
  • 16
  • 31