private String getValueFromAttributeStatements(final Assertion assertion, final String name) { final List<AttributeStatement> attributeStatements = assertion.getAttributeStatements(); for (AttributeStatement attributeStatement : attributeStatements) { final List<Attribute> attributes = attributeStatement.getAttributes(); for (Attribute attribute : attributes) { if (name.equals(attribute.getName())) { return attribute.getAttributeValues().get(0).getDOM().getTextContent(); } } } return ""; }
/** * Prepares the given DOM caching XMLObject for adoption into another document. If the XMLObject has a parent then * all visible namespaces used by the given XMLObject and its descendants are declared within that subtree and the * parent's DOM is invalidated. * * @param domCachingObject the XMLObject to prepare for adoption * * @throws MarshallingException thrown if a namespace within the XMLObject's DOM subtree can not be resolved. */ private void prepareForAdoption(XMLObject domCachingObject) throws MarshallingException { if (domCachingObject.getParent() != null) { log.trace("Rooting all visible namespaces of XMLObject {} before adding it to new parent Element", domCachingObject.getElementQName()); try { XMLHelper.rootNamespaces(domCachingObject.getDOM()); } catch (XMLParserException e) { String errorMsg = "Unable to root namespaces of cached DOM element, " + domCachingObject.getElementQName(); log.error(errorMsg, e); throw new MarshallingException(errorMsg, e); } log.trace("Release DOM of XMLObject parent"); domCachingObject.releaseParentDOM(true); } } }
/** * Assigned the parent, given at list construction, to the given element if the element does not have a parent or * its parent matches the one given at list construction time. * * @param element the element to set the parent on * * @throws IllegalArgumentException thrown if the given element already has a parent and it is different than the * parent given at list construction time */ protected void setParent(ElementType element) throws IllegalArgumentException { XMLObject elemParent = element.getParent(); if (elemParent != null && elemParent != parent) { throw new IllegalArgumentException(element.getElementQName() + " is already the child of another XMLObject and may not be inserted in to this list"); } element.setParent(parent); element.releaseParentDOM(true); } }
/** * Deregister an ID-to-XMLObject mapping for one of this object's owner's children. * * @param id the ID attribute value of the XMLObject child to deregister */ public void deregisterIDMapping(String id) { if (id == null) { return; } idMappings.remove(id); if (owner.hasParent()) { owner.getParent().getIDIndex().deregisterIDMapping(id); } }
log.debug("Marshalling XMLObject"); if (xmlObject.getDOM() != null) { log.debug("XMLObject already had cached DOM, returning that element"); return xmlObject.getDOM(); if (marshaller == null) { log.error("Unable to marshall XMLOBject, no marshaller registered for object: " + xmlObject.getElementQName());
Element domElement; log.trace("Starting to marshall {} as child of {}", xmlObject.getElementQName(), XMLHelper.getNodeQName(parentElement)); 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()); log.trace("Appending DOM of XMLObject {} as child of parent element {}", xmlObject.getElementQName(), XMLHelper.getNodeQName(parentElement)); XMLHelper.appendChildElement(parentElement, domElement); xmlObject.getElementQName()); Document owningDocument = parentElement.getOwnerDocument(); domElement = XMLHelper.constructElement(owningDocument, xmlObject.getElementQName()); domElement = marshallInto(xmlObject, domElement); log.trace("Setting created element to DOM cache for XMLObject {}", xmlObject.getElementQName()); xmlObject.setDOM(domElement); xmlObject.releaseParentDOM(true);
/** * {@inheritDoc} */ protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException { log.debug("Ignoring unknown element {}", childXMLObject.getElementQName()); }
/** * Recursive method used to validate all the children of the given XMLObject that implement * {@link ValidatingXMLObject}. Note, this can be a very expensive operation. * * @param xmlObject xmlObject whose descendants should be validated * * @throws ValidationException thrown if one of the child objects do not validate */ protected void validateChildren(XMLObject xmlObject) throws ValidationException { for (XMLObject childObject : xmlObject.getOrderedChildren()) { if (childObject == null) { continue; } if (childObject instanceof ValidatingXMLObject) { ((ValidatingXMLObject) childObject).validate(false); } else { log.debug("{} does not implement ValidatingXMLObject, ignoring it.", childObject.getElementQName()); } if (childObject.hasChildren()) { validateChildren(childObject); } } } }
/** * Evaluates the registered validators against the given XMLObject and it's children. * * @param xmlObject the XMLObject to validate * * @throws ValidationException thrown if the element is not valid */ public void validate(XMLObject xmlObject) throws ValidationException { if (xmlObject == null) { return; } log.debug("Beginning to verify XMLObject {} and its children", xmlObject.getElementQName()); performValidation(xmlObject); List<XMLObject> children = xmlObject.getOrderedChildren(); if (children != null) { for (XMLObject child : children) { validate(child); } } }
/** * Get the prefix bound to the specified namespace URI within the scope of the specified * XMLObject. * * @param xmlObject the XMLObject from which to search * @param namespaceURI the namespace URI to search * @return the prefix bound to the namespace URI, or none if not found */ public static String lookupNamespacePrefix(XMLObject xmlObject, String namespaceURI) { XMLObject current = xmlObject; while (current != null) { for (Namespace ns : current.getNamespaces()) { if (DatatypeHelper.safeEquals(ns.getNamespaceURI(), namespaceURI)) { return ns.getNamespacePrefix(); } } current = current.getParent(); } return null; }
List<XMLObject> children = getOwner().getOrderedChildren(); if (children != null) { for(XMLObject child : getOwner().getOrderedChildren()) { if (child != null) { Set<Namespace> childNamespaces = child.getNamespaceManager().getAllNamespacesInSubtreeScope(); if (childNamespaces != null && ! childNamespaces.isEmpty()) { namespaces.addAll(childNamespaces);
/** {@inheritDoc} */ public String remove(Object key) { String removedValue = attributes.remove(key); if (removedValue != null) { releaseDOM(); QName attributeName = (QName) key; if (isIDAttribute(attributeName) || Configuration.isIDAttribute(attributeName)) { attributeOwner.getIDIndex().deregisterIDMapping(removedValue); } attributeOwner.getNamespaceManager().deregisterAttributeName(attributeName); checkAndDeregisterQNameValue(attributeName, removedValue); } return removedValue; }
/** * Populates the given set with the non-visibly used namespace prefixes used by the given XMLObject * and all of its descendants, as determined by the signature content object's namespace manager. * * @param namespacePrefixes the namespace prefix set to be populated * @param signatureContent the XMLObject whose namespace prefixes will be used to populate the set */ private void populateNamespacePrefixes(Set<String> namespacePrefixes, XMLObject signatureContent) { for (String prefix: signatureContent.getNamespaceManager().getNonVisibleNamespacePrefixes()) { if (prefix != null) { // For the default namespace prefix, exclusive c14n uses the special token "#default". // Apache xmlsec requires this to be represented in the set with the // (completely undocumented) string "xmlns". if (NamespaceManager.DEFAULT_NS_TOKEN.equals(prefix)) { namespacePrefixes.add("xmlns"); } else { namespacePrefixes.add(prefix); } } } } }
/** * Checks to see if the given XMLObject is still valid. An XMLObject is valid if, and only if, itself and every * ancestral {@link TimeBoundSAMLObject} is valid. * * @param xmlObject the XML object tree to check * * @return true of the tree is valid, false if not */ public static boolean isValid(XMLObject xmlObject) { if (xmlObject instanceof TimeBoundSAMLObject) { TimeBoundSAMLObject timeBoundObject = (TimeBoundSAMLObject) xmlObject; if (!timeBoundObject.isValid()) { return false; } } XMLObject parent = xmlObject.getParent(); if (parent != null) { return isValid(parent); } return true; }
List<XMLObject> children = xmlObject.getOrderedChildren(); if (children != null) { for (XMLObject child : xmlObject.getOrderedChildren()) { if (child != null) { earliestExpiration = getEarliestExpiration(child, earliestExpiration, now);
log.debug("Marshalling XMLObject"); if (xmlObject.getDOM() != null) { log.debug("XMLObject already had cached DOM, returning that element"); return xmlObject.getDOM(); if (marshaller == null) { log.error("Unable to marshall XMLOBject, no marshaller registered for object: " + xmlObject.getElementQName());
/** * {@inheritDoc} */ protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException { log.debug("Ignoring unknown element {}", childXMLObject.getElementQName()); }
/** * Recursive method used to validate all the children of the given XMLObject that implement * {@link ValidatingXMLObject}. Note, this can be a very expensive operation. * * @param xmlObject xmlObject whose descendants should be validated * * @throws ValidationException thrown if one of the child objects do not validate */ protected void validateChildren(XMLObject xmlObject) throws ValidationException { for (XMLObject childObject : xmlObject.getOrderedChildren()) { if (childObject == null) { continue; } if (childObject instanceof ValidatingXMLObject) { ((ValidatingXMLObject) childObject).validate(false); } else { log.debug("{} does not implement ValidatingXMLObject, ignoring it.", childObject.getElementQName()); } if (childObject.hasChildren()) { validateChildren(childObject); } } } }
/** * Deregister an ID-to-XMLObject mapping for one of this object's owner's children. * * @param id the ID attribute value of the XMLObject child to deregister */ public void deregisterIDMapping(String id) { if (id == null) { return; } idMappings.remove(id); if (owner.hasParent()) { owner.getParent().getIDIndex().deregisterIDMapping(id); } }