Search in sources :

Example 66 with XMLObject

use of org.opensaml.core.xml.XMLObject in project ddf by codice.

the class AssertionConsumerService method extractSamlResponse.

private org.opensaml.saml.saml2.core.Response extractSamlResponse(String samlResponse) {
    org.opensaml.saml.saml2.core.Response response = null;
    try {
        Document responseDoc = StaxUtils.read(new ByteArrayInputStream(samlResponse.getBytes(StandardCharsets.UTF_8)));
        XMLObject responseXmlObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
        if (responseXmlObject instanceof org.opensaml.saml.saml2.core.Response) {
            response = (org.opensaml.saml.saml2.core.Response) responseXmlObject;
        }
    } catch (XMLStreamException | WSSecurityException e) {
        LOGGER.debug("Failed to convert AuthN response string to object.", e);
    }
    return response;
}
Also used : XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) Response(javax.ws.rs.core.Response) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 67 with XMLObject

use of org.opensaml.core.xml.XMLObject in project midpoint by Evolveum.

the class MidpointAssertingPartyMetadataConverter method entityDescriptor.

private EntityDescriptor entityDescriptor(InputStream inputStream) {
    Document document = document(inputStream);
    Element element = document.getDocumentElement();
    Unmarshaller unmarshaller = this.registry.getUnmarshallerFactory().getUnmarshaller(element);
    if (unmarshaller == null) {
        throw new Saml2Exception("Unsupported element of type " + element.getTagName());
    }
    try {
        XMLObject object = unmarshaller.unmarshall(element);
        if (object instanceof EntitiesDescriptor) {
            return ((EntitiesDescriptor) object).getEntityDescriptors().get(0);
        }
        if (object instanceof EntityDescriptor) {
            return (EntityDescriptor) object;
        }
    } catch (Exception ex) {
        throw new Saml2Exception(ex);
    }
    throw new Saml2Exception("Unsupported element of type " + element.getTagName());
}
Also used : Element(org.w3c.dom.Element) XMLObject(org.opensaml.core.xml.XMLObject) Document(org.w3c.dom.Document) Unmarshaller(org.opensaml.core.xml.io.Unmarshaller) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Saml2Exception(org.springframework.security.saml2.Saml2Exception) CertificateException(java.security.cert.CertificateException)

Example 68 with XMLObject

use of org.opensaml.core.xml.XMLObject in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProvider method getAssertionAttributes.

private static Map<String, List<Object>> getAssertionAttributes(Assertion assertion) {
    Map<String, List<Object>> attributeMap = new LinkedHashMap<>();
    for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) {
        for (Attribute attribute : attributeStatement.getAttributes()) {
            List<Object> attributeValues = new ArrayList<>();
            for (XMLObject xmlObject : attribute.getAttributeValues()) {
                Object attributeValue = getXmlObjectValue(xmlObject);
                if (attributeValue != null) {
                    attributeValues.add(attributeValue);
                }
            }
            attributeMap.put(attribute.getName(), attributeValues);
        }
    }
    return attributeMap;
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) ArrayList(java.util.ArrayList) XMLObject(org.opensaml.core.xml.XMLObject) List(java.util.List) ArrayList(java.util.ArrayList) XMLObject(org.opensaml.core.xml.XMLObject) XSString(org.opensaml.core.xml.schema.XSString) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XMLObject (org.opensaml.core.xml.XMLObject)68 Element (org.w3c.dom.Element)27 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)21 Document (org.w3c.dom.Document)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 Attribute (org.opensaml.saml.saml2.core.Attribute)14 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)10 IOException (java.io.IOException)9 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 XSString (org.opensaml.core.xml.schema.XSString)7 Assertion (org.opensaml.saml.saml2.core.Assertion)7 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)7 HashMap (java.util.HashMap)6 List (java.util.List)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 LogoutSecurityException (ddf.security.samlp.LogoutSecurityException)4