简体   繁体   English

将SAML2 AuthnRequest转换为Java类

[英]Convert SAML2 AuthnRequest to Java classes

I'm using OpenSAML 2.6.5 as SAML2 library. 我正在使用OpenSAML 2.6.5作为SAML2库。 I've not found documentation about how to marshall the string (XML document) representing the AuthnRequest that comes from the Service Provider. 我没有找到有关如何编组代表来自服务提供商的AuthnRequest的字符串(XML文档)的文档。 Can anyone help me? 谁能帮我?

To read request from SP, you need to encode and unmarshall the incoming String, like this: 要从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