简体   繁体   中英

Convert SAML2 AuthnRequest to Java classes

I'm using OpenSAML 2.6.5 as SAML2 library. I've not found documentation about how to marshall the string (XML document) representing the AuthnRequest that comes from the Service Provider. Can anyone help me?

To read request from SP, you need to encode and unmarshall the incoming String, like this:

    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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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