Java Code Examples for org.apache.xml.security.transforms.Transforms#getElement()

The following examples show how to use org.apache.xml.security.transforms.Transforms#getElement() . 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: XAdESReferenceValidation.java    From dss with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public List<String> getTransformationNames() {
	if (transforms == null) {
		transforms = new ArrayList<>();
		try {
			Transforms referenceTransforms = reference.getTransforms();
			if (referenceTransforms != null) {
				Element transformsElement = referenceTransforms.getElement();
				NodeList transfromChildNodes = transformsElement.getChildNodes();
				if (transfromChildNodes != null && transfromChildNodes.getLength() > 0) {
					for (int i = 0; i < transfromChildNodes.getLength(); i++) {
						Node transformation = transfromChildNodes.item(i);
						if (Node.ELEMENT_NODE == transformation.getNodeType()) {
							transforms.add(buildTransformationName(transformation));
						}
					}
				}
			}
		} catch (XMLSecurityException e) {
			LOG.warn("Unable to analyze trasnformations", e);
		}
	}
	return transforms;
}
 
Example 2
Source File: DSSXMLUtils.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns bytes of the original referenced data
 * @param reference {@link Reference} to get bytes from
 * @return byte array containing original data
 */
public static byte[] getReferenceOriginalContentBytes(Reference reference) {
	
	try {
		// returns bytes after transformation in case of enveloped signature
		Transforms transforms = reference.getTransforms();
		if (transforms != null) {
			Element transformsElement = transforms.getElement();
			NodeList transformChildNodes = transformsElement.getChildNodes();
			if (transformChildNodes != null && transformChildNodes.getLength() > 0) {
				for (int i = 0; i < transformChildNodes.getLength(); i++) {
					Node transformation = transformChildNodes.item(i);
					if (isEnvelopedTransform(transformation)) {
						return reference.getReferencedBytes();
					}
				    // if enveloped transformations are not applied to the signature go further and 
					// return bytes before transformation
				}
			}
		}
		
	} catch (XMLSecurityException | XMLSecurityRuntimeException e) {
		// if exception occurs during the transformations
		LOG.warn("Signature reference with id [{}] is corrupted or has an invalid format. "
				+ "Original data cannot be obtained. Reason: [{}]", reference.getId(), e.getMessage());
		
	}
	// otherwise bytes before transformation
	return getBytesBeforeTransformation(reference);
}