use of javax.xml.crypto.dom.DOMStructure in project camel by apache.
the class XAdESSignatureProperties method get.
@Override
public Output get(Input input) throws Exception {
//NOPMD
XmlSignatureProperties.Output result = new Output();
if (!isAddSignedSignatureProperties() && !isAddSignedDataObjectPropeties()) {
LOG.debug("XAdES signature properties are empty. Therefore no XAdES element will be added to the signature.");
return result;
}
String signedPropertiesId = "_" + UUID.randomUUID().toString();
List<Transform> transforms = Collections.emptyList();
Reference ref = input.getSignatureFactory().newReference("#" + signedPropertiesId, input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), transforms, "http://uri.etsi.org/01903#SignedProperties", null);
Node parent = input.getParent();
Document doc;
if (Node.DOCUMENT_NODE == parent.getNodeType()) {
// enveloping
doc = (Document) parent;
} else {
// enveloped
doc = parent.getOwnerDocument();
}
Element qualifyingProperties = createElement("QualifyingProperties", doc, input);
setIdAttributeFromHeader(XmlSignatureConstants.HEADER_XADES_QUALIFYING_PROPERTIES_ID, qualifyingProperties, input);
String signatureId = input.getSignatureId();
if (signatureId == null || signatureId.isEmpty()) {
LOG.debug("No signature Id configured. Therefore a value is generated.");
// generate one
signatureId = "_" + UUID.randomUUID().toString();
// and set to output
result.setSignatureId(signatureId);
}
setAttribute(qualifyingProperties, "Target", "#" + signatureId);
Element signedProperties = createElement("SignedProperties", doc, input);
qualifyingProperties.appendChild(signedProperties);
setAttribute(signedProperties, "Id", signedPropertiesId);
signedProperties.setIdAttribute("Id", true);
addSignedSignatureProperties(doc, signedProperties, input);
String contentReferenceId = addSignedDataObjectProperties(doc, signedProperties, input);
result.setContentReferenceId(contentReferenceId);
DOMStructure structure = new DOMStructure(qualifyingProperties);
XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(structure), null, null, null);
result.setReferences(Collections.singletonList(ref));
result.setObjects(Collections.singletonList(propertiesObject));
return result;
}
use of javax.xml.crypto.dom.DOMStructure in project camel by apache.
the class XmlSignatureHelper method getXslTranform.
/**
* Returns a configuration for an XSL transformation.
*
* @param is
* input stream of the XSL
* @return XSL transform
* @throws IllegalArgumentException
* if <tt>is</tt> is <code>null</code>
* @throws Exception
* if an error during the reading of the XSL file occurs
*/
public static AlgorithmMethod getXslTranform(InputStream is) throws SAXException, IOException, ParserConfigurationException {
if (is == null) {
throw new IllegalArgumentException("is must not be null");
}
Document doc = parseInput(is);
DOMStructure stylesheet = new DOMStructure(doc.getDocumentElement());
XSLTTransformParameterSpec spec = new XSLTTransformParameterSpec(stylesheet);
XmlSignatureTransform transformXslt = new XmlSignatureTransform();
transformXslt.setAlgorithm(Transform.XSLT);
transformXslt.setParameterSpec(spec);
return transformXslt;
}
use of javax.xml.crypto.dom.DOMStructure in project camel by apache.
the class DefaultXmlSignature2Message method getNodeForMessageBodyInEnvelopingCase.
protected Node getNodeForMessageBodyInEnvelopingCase(Input input) throws Exception {
//NOPMD
Node node;
List<Reference> relevantReferences = getReferencesForMessageMapping(input);
List<XMLObject> relevantObjects = getObjectsForMessageMapping(input);
DOMStructure domStruc = getDomStructureForMessageBody(relevantReferences, relevantObjects);
node = domStruc.getNode();
return node;
}
use of javax.xml.crypto.dom.DOMStructure in project jdk8u_jdk by JetBrains.
the class Marshal method main.
public static void main(String[] args) throws Exception {
KeyInfoFactory fac = KeyInfoFactory.getInstance();
KeyInfo ki = fac.newKeyInfo(Collections.singletonList(fac.newKeyName("foo")), "keyid");
try {
ki.marshal(null, null);
throw new Exception("Should raise a NullPointerException");
} catch (NullPointerException npe) {
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
Element elem = doc.createElementNS("http://acme.org", "parent");
doc.appendChild(elem);
DOMStructure parent = new DOMStructure(elem);
ki.marshal(parent, null);
Element kiElem = DOMUtils.getFirstChildElement(elem);
if (!kiElem.getLocalName().equals("KeyInfo")) {
throw new Exception("Should be KeyInfo element: " + kiElem.getLocalName());
}
Element knElem = DOMUtils.getFirstChildElement(kiElem);
if (!knElem.getLocalName().equals("KeyName")) {
throw new Exception("Should be KeyName element: " + knElem.getLocalName());
}
}
use of javax.xml.crypto.dom.DOMStructure in project poi by apache.
the class RelationshipTransformService method marshalParams.
@Override
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
LOG.log(POILogger.DEBUG, "marshallParams(parent,context)");
DOMStructure domParent = (DOMStructure) parent;
Element parentNode = (Element) domParent.getNode();
// parentNode.setAttributeNS(XML_NS, "xmlns:mdssi", XML_DIGSIG_NS);
Document doc = parentNode.getOwnerDocument();
for (String sourceId : this.sourceIds) {
RelationshipReferenceDocument relRef = RelationshipReferenceDocument.Factory.newInstance();
relRef.addNewRelationshipReference().setSourceId(sourceId);
Node n = relRef.getRelationshipReference().getDomNode();
n = doc.importNode(n, true);
parentNode.appendChild(n);
}
}
Aggregations