繁体   English   中英

将SAML2 AuthnRequest转换为Java类

[英]Convert SAML2 AuthnRequest to Java classes

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

要从SP读取请求,您需要对传入的String进行编码和解组,如下所示:

    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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM