我正在开发一项使用另一个 Web 服务的 Web 服务。要使用此其他服务进行身份验证,我必须使用 SAML V2 协议(protocol)。如何在 Java 中以编程方式使用此服务?
我的代码没有 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();
}
最佳答案
您需要构建满足目标服务要求的 SAML 响应并将其包含在调用中。您最好的选择是OpenSAML或其他“产品”,例如 CXF建立在它之上。请参阅How to create a valid SAML 2.0 Assertion with OpenSAML library in Java OpenSAML 示例; CXF 附带了很好的文档和示例。
关于java - 在java中使用SSO身份验证使用服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57924240/