use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project jdk8u_jdk by JetBrains.
the class DOMXPathTransform method marshalParams.
public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
super.marshalParams(parent, context);
XPathFilterParameterSpec xp = (XPathFilterParameterSpec) getParameterSpec();
Element xpathElem = DOMUtils.createElement(ownerDoc, "XPath", XMLSignature.XMLNS, DOMUtils.getSignaturePrefix(context));
xpathElem.appendChild(ownerDoc.createTextNode(xp.getXPath()));
// add namespace attributes, if necessary
@SuppressWarnings("unchecked") Set<Map.Entry<String, String>> entries = xp.getNamespaceMap().entrySet();
for (Map.Entry<String, String> entry : entries) {
xpathElem.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + entry.getKey(), entry.getValue());
}
transformElem.appendChild(xpathElem);
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignerProcessor method getParentForEnvelopedCase.
protected Element getParentForEnvelopedCase(Document doc, Message inMessage) throws Exception {
//NOPMD
if (getConfiguration().getParentXpath() != null) {
XPathFilterParameterSpec xp = getConfiguration().getParentXpath();
XPathExpression exp;
try {
exp = XmlSignatureHelper.getXPathExpression(xp);
} catch (XPathExpressionException e) {
throw new XmlSignatureException("The parent XPath " + getConfiguration().getParentXpath().getXPath() + " is wrongly configured: The XPath " + xp.getXPath() + " is invalid.", e);
}
NodeList list = (NodeList) exp.evaluate(doc.getDocumentElement(), XPathConstants.NODESET);
if (list == null || list.getLength() == 0) {
throw new XmlSignatureException("The parent XPath " + xp.getXPath() + " returned no result. Check the configuration of the XML signer component.");
}
int length = list.getLength();
for (int i = 0; i < length; i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
// return the first element
return (Element) node;
}
}
throw new XmlSignatureException("The parent XPath " + xp.getXPath() + " returned no element. Check the configuration of the XML signer component.");
} else {
// parent local name is not null!
NodeList parents = doc.getElementsByTagNameNS(getConfiguration().getParentNamespace(), getConfiguration().getParentLocalName());
if (parents == null || parents.getLength() == 0) {
throw new XmlSignatureFormatException(String.format("Incoming message has wrong format: The parent element with the local name %s and the namespace %s was not found in the message to build an enveloped XML signature.", getConfiguration().getParentLocalName(), getConfiguration().getParentNamespace()));
}
// return the first element
return (Element) parents.item(0);
}
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignatureHelper method getXPathTransform.
/**
* Returns a configuration for an XPATH transformation which needs a
* namespace map.
*
* @param xpath
* XPATH expression
* @param namespaceMap
* namespace map, key is the prefix, value is the namespace, can
* be <code>null</code>
* @throws IllegalArgumentException
* if <tt>xpath</tt> is <code>null</code>
* @return XPATH transformation
*/
public static AlgorithmMethod getXPathTransform(String xpath, Map<String, String> namespaceMap) {
if (xpath == null) {
throw new IllegalArgumentException("xpath is null");
}
XmlSignatureTransform transformXPath = new XmlSignatureTransform();
transformXPath.setAlgorithm(Transform.XPATH);
XPathFilterParameterSpec params = getXpathFilter(xpath, namespaceMap);
transformXPath.setParameterSpec(params);
return transformXPath;
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project jdk8u_jdk by JetBrains.
the class DOMXPathTransform method unmarshalParams.
private void unmarshalParams(Element paramsElem) {
String xPath = paramsElem.getFirstChild().getNodeValue();
// create a Map of namespace prefixes
NamedNodeMap attributes = paramsElem.getAttributes();
if (attributes != null) {
int length = attributes.getLength();
Map<String, String> namespaceMap = new HashMap<String, String>(length);
for (int i = 0; i < length; i++) {
Attr attr = (Attr) attributes.item(i);
String prefix = attr.getPrefix();
if (prefix != null && prefix.equals("xmlns")) {
namespaceMap.put(attr.getLocalName(), attr.getValue());
}
}
this.params = new XPathFilterParameterSpec(xPath, namespaceMap);
} else {
this.params = new XPathFilterParameterSpec(xPath);
}
}
Aggregations