gpt4 book ai didi

java - 将 SAML2 AuthnRequest 转换为 Java 类

转载 作者:行者123 更新时间:2023-12-01 11:12:21 26 4
gpt4 key购买 nike

我使用 OpenSAML 2.6.5 作为 SAML2 库。我还没有找到有关如何编码表示来自服务提供商的 AuthnRequest 的字符串(XML 文档)的文档。谁能帮我吗?

最佳答案

要读取来自 SP 的请求,您需要对传入的字符串进行编码和解码,如下所示:

    DefaultBootstrap.bootstrap(); //crucial in SAML2
byte[] decodedSamlAsBytes = Base64.decode(incomingEncodedSaml);

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();

Document document = docBuilder.parse(new ByteArrayInputStream(decodedSamlAsBytes));
Element element = document.getDocumentElement();

UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
XMLObject requestXmlObj = unmarshaller.unmarshall(element);
AuthnRequest request = (AuthnRequest) requestXmlObj;

关于java - 将 SAML2 AuthnRequest 转换为 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32206298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com