List of usage examples for org.w3c.dom Attr getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.apache.ws.security.message.EnvelopeIdResolver.java
/** * This is the workhorse method used to resolve resources. * <p/>//from w w w . j a v a 2 s . c o m * * @param * @param BaseURI * @return TODO * @throws ResourceResolverException */ public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException { doDebug = log.isDebugEnabled(); String uriNodeValue = uri.getNodeValue(); if (doDebug) { log.debug("enter engineResolve, look for: " + uriNodeValue); } Document doc = uri.getOwnerDocument(); /* * URI="#chapter1" * Identifies a node-set containing the element with ID attribute * value 'chapter1' of the XML resource containing the signature. * XML Signature (and its applications) modify this node-set to * include the element plus all descendants including namespaces and * attributes -- but not comments. */ /* * First check to see if the element that we require is a SecurityTokenReference * that is stored in WSDocInfo. */ String id = uriNodeValue.substring(1); Element selectedElem = null; if (wsDocInfo != null) { selectedElem = wsDocInfo.getSecurityTokenReference(id); } /* * Then lookup the SOAP Body element (processed by default) and * check if it contains a matching Id */ if (selectedElem == null) { SOAPConstants sc = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement()); selectedElem = WSSecurityUtil.findBodyElement(doc, sc); if (selectedElem == null) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Body element not found" }, uri, BaseURI); } String cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); /* * If Body Id match fails, look for a generic Id (without a namespace) * that matches the URI. If that lookup fails, try to get a namespace * qualified Id that matches the URI. */ if (!id.equals(cId)) { cId = null; if ((selectedElem = WSSecurityUtil.getElementByWsuId(doc, uriNodeValue)) != null) { cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); } else if ((selectedElem = WSSecurityUtil.getElementByGenId(doc, uriNodeValue)) != null) { cId = selectedElem.getAttribute("Id"); } if (cId == null) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Id not found" }, uri, BaseURI); } } } XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setMIMEType("text/xml"); try { URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue()); result.setSourceURI(uriNew.toString()); } catch (URI.MalformedURIException ex) { result.setSourceURI(BaseURI); } if (doDebug) { log.debug("exit engineResolve, result: " + result); } return result; }
From source file:xsul.dsig.globus.security.authentication.SOAPBodyIdResolver.java
public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException { String uriNodeValue = uri.getNodeValue(); NodeList resultNodes = null;// ww w . jav a2 s .c o m Document doc = uri.getOwnerDocument(); // this must be done so that Xalan can catch ALL namespaces XMLUtils.circumventBug2650(doc); CachedXPathAPI cXPathAPI = new CachedXPathAPI(); /* * URI="#chapter1" * Identifies a node-set containing the element with ID attribute * value 'chapter1' of the XML resource containing the signature. * XML Signature (and its applications) modify this node-set to * include the element plus all descendents including namespaces and * attributes -- but not comments. */ String id = uriNodeValue.substring(1); Element selectedElem = WSSecurityUtil.findFirstBodyElement(doc); if (selectedElem == null) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Body element not found" }, uri, BaseURI); } String cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); if ((cId == null) || (cId.length() == 0)) { cId = selectedElem.getAttributeNS(WSConstants.SOAP_SEC_NS, "id"); } if (!id.equals(cId)) { selectedElem = (Element) selectedElem.getParentNode(); cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); if ((cId == null) || (cId.length() == 0)) { cId = selectedElem.getAttributeNS(WSConstants.SOAP_SEC_NS, "id"); } if (!id.equals(cId)) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Id not found" }, uri, BaseURI); } } try { resultNodes = cXPathAPI.selectNodeList(selectedElem, Canonicalizer.XPATH_C14N_WITH_COMMENTS_SINGLE_NODE//.XPATH_C14N_OMIT_COMMENTS_SINGLE_NODE ); } catch (javax.xml.transform.TransformerException ex) { throw new ResourceResolverException("generic.EmptyMessage", ex, uri, BaseURI); } Set resultSet = XMLUtils.convertNodelistToSet(resultNodes); XMLSignatureInput result = new XMLSignatureInput(resultSet);//, cXPathAPI); result.setMIMEType("text/xml"); try { URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue()); result.setSourceURI(uriNew.toString()); } catch (URI.MalformedURIException ex) { result.setSourceURI(BaseURI); } return result; }