如何从<samlresponse>获取<samlassertion>使用OpenSAML库?</samlresponse> </samlassertion>

时间:2015-04-13 19:03:20

标签: saml-2.0 spring-saml opensaml

我正在寻找将读取SAMLResponse的Java代码并检索SAMLAssertion以进一步发送。我发现http://sureshatt.blogspot.in/2012/11/how-to-read-saml-20-response-with.html此链接读取SAMLResponse,但不确定它是否真的只能检索我想要的SAMLAssertion。

有人请我提供java测试/示例java代码吗?

1 个答案:

答案 0 :(得分:0)

您可以使用Open SAML库(OpenSAML-J库提供工具来支持使用安全断言标记语言(SAML)的开发人员。) maven依赖项供您参考。

<dependency>
    <groupId>org.opensaml</groupId>
    <artifactId>opensaml</artifactId>
    <version>2.6.4</version>
</dependency>

获得SAMLResponse(将是一个编码的字符串)后,使用Open SAML可以使用Base64解码器对其进行解码,一旦解码,您需要分别解组响应和元素。完成后,您需要输入强制转换为响应对象,然后从响应对象中获取断言。所以这个断言将包括NameId,Issuer,Audience,Signature等。

//Casting the response to the SAML 2.0 Response message.
Response response = (Response) responseXmlObj;

我希望这是您原始查询的内容,并且我使用了您提供的链接中的相同代码,并且工作正常。