Java Code Examples for org.opensaml.xml.XMLObject#getDOM()

The following examples show how to use org.opensaml.xml.XMLObject#getDOM() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseMessageDecoder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Log the decoded message to the protocol message logger.
 * 
 * @param messageContext the message context to process
 */
protected void logDecodedMessage(MessageContext messageContext) {
    if(protocolMessageLog.isDebugEnabled() && messageContext.getInboundMessage() != null){
        if (messageContext.getInboundMessage().getDOM() == null) {
            XMLObject message = messageContext.getInboundMessage();
            Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message);
            if (marshaller != null) {
                try {
                    marshaller.marshall(message);
                } catch (MarshallingException e) {
                    log.error("Unable to marshall message for logging purposes: " + e.getMessage());
                }
            }
            else {
                log.error("Unable to marshall message for logging purposes, no marshaller registered for message object: "
                        + message.getElementQName());
            }
            if (message.getDOM() == null) {
                return;
            }
        }
        protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getInboundMessage().getDOM()));
    }
}
 
Example 2
Source File: Decrypter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Ensure that the XMLObject is marshalled.
 * 
 * @param xmlObject the object to check and marshall
 * @throws DecryptionException thrown if there is an error when marshalling the XMLObject
 */
protected void checkAndMarshall(XMLObject xmlObject) throws DecryptionException {
    Element targetElement = xmlObject.getDOM();
    if (targetElement == null) {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
        if (marshaller == null) {
            marshaller =
                    Configuration.getMarshallerFactory().getMarshaller(Configuration.getDefaultProviderQName());
            if (marshaller == null) {
                String errorMsg = "No marshaller available for " + xmlObject.getElementQName();
                log.error(errorMsg);
                throw new DecryptionException(errorMsg);
            }
        }
        try {
            targetElement = marshaller.marshall(xmlObject);
        } catch (MarshallingException e) {
            log.error("Error marshalling target XMLObject", e);
            throw new DecryptionException("Error marshalling target XMLObject", e);
        }
    }
}
 
Example 3
Source File: XMLObjectHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Marshall an XMLObject.  If the XMLObject already has a cached DOM via {@link XMLObject#getDOM()},
 * that Element will be returned.  Otherwise the object will be fully marshalled and that Element returned.
 * 
 * @param xmlObject the XMLObject to marshall
 * @return the marshalled Element
 * @throws MarshallingException if there is a problem marshalling the XMLObject
 */
public static Element marshall(XMLObject xmlObject) throws MarshallingException {
    Logger log = getLogger();
    log.debug("Marshalling XMLObject");
    
    if (xmlObject.getDOM() != null) {
        log.debug("XMLObject already had cached DOM, returning that element");
        return xmlObject.getDOM();
    }

    Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
    if (marshaller == null) {
        log.error("Unable to marshall XMLOBject, no marshaller registered for object: "
                + xmlObject.getElementQName());
    }
    
    Element messageElem = marshaller.marshall(xmlObject);
    
    if (log.isTraceEnabled()) {
        log.trace("Marshalled XMLObject into DOM:");
        log.trace(XMLHelper.nodeToString(messageElem));
    }
    
    return messageElem;
}
 
Example 4
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml1.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml1.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml1.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml1.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml1.core.Attribute attribute : attributes) {
                
                if (attribute.getAttributeName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 5
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml2.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml2.core.Attribute attribute : attributes) {
                
                if (attribute.getName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 6
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml1.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml1.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml1.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml1.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml1.core.Attribute attribute : attributes) {
                
                if (attribute.getAttributeName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 7
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml2.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml2.core.Attribute attribute : attributes) {
                
                if (attribute.getName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 8
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml1.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml1.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml1.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml1.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml1.core.Attribute attribute : attributes) {
                
                if (attribute.getAttributeName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 9
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml2.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml2.core.Attribute attribute : attributes) {
                
                if (attribute.getName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 10
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml1.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml1.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml1.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml1.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml1.core.Attribute attribute : attributes) {
                
                if (attribute.getAttributeName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 11
Source File: SAMLUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
private static List<String> parseRolesInAssertion(org.opensaml.saml2.core.Assertion assertion,
            String roleAttributeName) {
        List<org.opensaml.saml2.core.AttributeStatement> attributeStatements = 
            assertion.getAttributeStatements();
        if (attributeStatements == null || attributeStatements.isEmpty()) {
            return null;
        }
        List<String> roles = new ArrayList<String>();
        
        for (org.opensaml.saml2.core.AttributeStatement statement : attributeStatements) {
            
            List<org.opensaml.saml2.core.Attribute> attributes = statement.getAttributes();
            for (org.opensaml.saml2.core.Attribute attribute : attributes) {
                
                if (attribute.getName().equals(roleAttributeName)) {
                    for (XMLObject attributeValue : attribute.getAttributeValues()) {
                        Element attributeValueElement = attributeValue.getDOM();
                        String value = attributeValueElement.getTextContent();
                        roles.add(value);                    
                    }
                    if (attribute.getAttributeValues().size() > 1) {
//                        Don't search for other attributes with the same name if                         
//                        <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
//                             AttributeNamespace="http://schemas.xmlsoap.org/claims" AttributeName="roles">
//                        <saml:AttributeValue>Value1</saml:AttributeValue>
//                        <saml:AttributeValue>Value2</saml:AttributeValue>
//                        </saml:Attribute>
                        break;
                    }
                }
                
            }
        }
        return Collections.unmodifiableList(roles);
    }
 
Example 12
Source File: Encrypter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Ensure that the XMLObject is marshalled.
 * 
 * @param xmlObject the object to check and marshall
 * @throws EncryptionException thrown if there is an error when marshalling the XMLObject
 */
protected void checkAndMarshall(XMLObject xmlObject) throws EncryptionException {
    Element targetElement = xmlObject.getDOM();
    if (targetElement == null) {
        Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(xmlObject);
        try {
            targetElement = marshaller.marshall(xmlObject);
        } catch (MarshallingException e) {
            log.error("Error marshalling target XMLObject", e);
            throw new EncryptionException("Error marshalling target XMLObject", e);
        }
    }
}
 
Example 13
Source File: AbstractXMLObjectMarshaller.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Element marshall(XMLObject xmlObject, Document document) throws MarshallingException {
    Element domElement;

    log.trace("Starting to marshall {}", xmlObject.getElementQName());

    if (document == null) {
        throw new MarshallingException("Given document may not be null");
    }

    checkXMLObjectIsTarget(xmlObject);

    log.trace("Checking if {} contains a cached DOM representation", xmlObject.getElementQName());
    domElement = xmlObject.getDOM();
    if (domElement != null) {

        prepareForAdoption(xmlObject);

        if (domElement.getOwnerDocument() != document) {
            log.trace("Adopting DOM of XMLObject into given Document");
            XMLHelper.adoptElement(domElement, document);
        }

        log.trace("Setting DOM of XMLObject as document element of given Document");
        setDocumentElement(document, domElement);

        return domElement;
    }

    log.trace("{} does not contain a cached DOM representation. Creating Element to marshall into.",
            xmlObject.getElementQName());
    domElement = XMLHelper.constructElement(document, xmlObject.getElementQName());

    log.trace("Setting created element as document root");
    // we need to do this before the rest of the marshalling so that signing and other ID dependent operations have
    // a path to the document root
    setDocumentElement(document, domElement);

    domElement = marshallInto(xmlObject, domElement);

    log.trace("Setting created element to DOM cache for XMLObject {}", xmlObject.getElementQName());
    xmlObject.setDOM(domElement);
    xmlObject.releaseParentDOM(true);

    return domElement;
}
 
Example 14
Source File: AbstractXMLObjectMarshaller.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public Element marshall(XMLObject xmlObject, Element parentElement) throws MarshallingException {
    Element domElement;

    log.trace("Starting to marshall {} as child of {}", xmlObject.getElementQName(),
            XMLHelper.getNodeQName(parentElement));

    if (parentElement == null) {
        throw new MarshallingException("Given parent element is null");
    }

    checkXMLObjectIsTarget(xmlObject);

    log.trace("Checking if {} contains a cached DOM representation", xmlObject.getElementQName());
    domElement = xmlObject.getDOM();
    if (domElement != null) {
        log.trace("{} contains a cached DOM representation", xmlObject.getElementQName());

        prepareForAdoption(xmlObject);

        log.trace("Appending DOM of XMLObject {} as child of parent element {}", xmlObject.getElementQName(),
                XMLHelper.getNodeQName(parentElement));
        XMLHelper.appendChildElement(parentElement, domElement);

        return domElement;
    }

    log.trace("{} does not contain a cached DOM representation. Creating Element to marshall into.",
            xmlObject.getElementQName());
    Document owningDocument = parentElement.getOwnerDocument();
    domElement = XMLHelper.constructElement(owningDocument, xmlObject.getElementQName());

    log.trace("Appending newly created element to given parent element");
    // we need to do this before the rest of the marshalling so that signing and other ID dependent operations have
    // a path to the document root
    XMLHelper.appendChildElement(parentElement, domElement);
    domElement = marshallInto(xmlObject, domElement);

    log.trace("Setting created element to DOM cache for XMLObject {}", xmlObject.getElementQName());
    xmlObject.setDOM(domElement);
    xmlObject.releaseParentDOM(true);

    return domElement;

}