Search in sources :

Example 1 with Unmarshaller

use of org.opensaml.xml.io.Unmarshaller in project cloudstack by apache.

the class SAMLUtils method decodeSAMLResponse.

public static Response decodeSAMLResponse(String responseMessage) throws ConfigurationException, ParserConfigurationException, SAXException, IOException, UnmarshallingException {
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
    byte[] base64DecodedResponse = Base64.decode(responseMessage);
    Document document = docBuilder.parse(new ByteArrayInputStream(base64DecodedResponse));
    Element element = document.getDocumentElement();
    UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
    Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element);
    return (Response) unmarshaller.unmarshall(element);
}
Also used : LoginCmdResponse(org.apache.cloudstack.api.response.LoginCmdResponse) Response(org.opensaml.saml2.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) UnmarshallerFactory(org.opensaml.xml.io.UnmarshallerFactory) Document(org.w3c.dom.Document) Unmarshaller(org.opensaml.xml.io.Unmarshaller)

Example 2 with Unmarshaller

use of org.opensaml.xml.io.Unmarshaller in project OpenAttestation by OpenAttestation.

the class TrustAssertion method readAssertion.

private Assertion readAssertion(Element document) throws UnmarshallingException {
    log.debug("Reading assertion from element {}", document.getTagName());
    UnmarshallerFactory factory = Configuration.getUnmarshallerFactory();
    Unmarshaller unmarshaller = factory.getUnmarshaller(document);
    // UnmarshallingException
    XMLObject xml = unmarshaller.unmarshall(document);
    Assertion samlAssertion = (Assertion) xml;
    return samlAssertion;
}
Also used : Assertion(org.opensaml.saml2.core.Assertion) XMLObject(org.opensaml.xml.XMLObject) UnmarshallerFactory(org.opensaml.xml.io.UnmarshallerFactory) Unmarshaller(org.opensaml.xml.io.Unmarshaller)

Aggregations

Unmarshaller (org.opensaml.xml.io.Unmarshaller)2 UnmarshallerFactory (org.opensaml.xml.io.UnmarshallerFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 LoginCmdResponse (org.apache.cloudstack.api.response.LoginCmdResponse)1 Assertion (org.opensaml.saml2.core.Assertion)1 Response (org.opensaml.saml2.core.Response)1 XMLObject (org.opensaml.xml.XMLObject)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1