se.idsec.sigval.xml.utils.XMLSigUtils Maven / Gradle / Ivy
/*
* Copyright (c) 2020. IDsec Solutions AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package se.idsec.sigval.xml.utils;
import lombok.extern.slf4j.Slf4j;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.List;
/**
* Utility class for common functions related to XML signature processing
*
* @author Martin Lindström ([email protected])
* @author Stefan Santesson ([email protected])
*/
@Slf4j
public class XMLSigUtils {
/**
* Get the signature elements of an XML document
* @param document XML document
* @return signature elements
*/
public static List getSignatures(Document document) {
NodeList signatureElements = document.getElementsByTagNameNS(javax.xml.crypto.dsig.XMLSignature.XMLNS, "Signature");
if (signatureElements.getLength() == 0) {
log.debug("No signatures found");
// We return an empty list of signature results as it is not considered an exception to validate an unsigned document
return new ArrayList<>();
}
List signatures = new ArrayList<>();
for (int i = 0; i < signatureElements.getLength(); i++) {
signatures.add((Element) signatureElements.item(i));
}
return signatures;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy