Reputation:
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?
Upvotes: 0
Views: 1378
Reputation: 11
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;
Upvotes: 1