Java Code Examples for com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput#setSourceURI()
The following examples show how to use
com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput#setSourceURI() .
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: ResolverLocalFilesystem.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 2
Source File: ResolverLocalFilesystem.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 3
Source File: ResolverLocalFilesystem.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 4
Source File: ResolverLocalFilesystem.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 5
Source File: ResolverLocalFilesystem.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 6
Source File: ResolverLocalFilesystem.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 7
Source File: ResolverLocalFilesystem.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 8
Source File: ResolverLocalFilesystem.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 9
Source File: ResolverLocalFilesystem.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 10
Source File: ResolverLocalFilesystem.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 11
Source File: ResolverLocalFilesystem.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 12
Source File: ResolverLocalFilesystem.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * @inheritDoc */ @Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { try { // calculate new URI URI uriNew = getNewURI(context.uriToResolve, context.baseUri); String fileName = ResolverLocalFilesystem.translateUriToFilename(uriNew.toString()); FileInputStream inputStream = new FileInputStream(fileName); XMLSignatureInput result = new XMLSignatureInput(inputStream); result.setSourceURI(uriNew.toString()); return result; } catch (Exception e) { throw new ResourceResolverException("generic.EmptyMessage", e, context.attr, context.baseUri); } }
Example 13
Source File: DOMURIDereferencer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 14
Source File: DOMURIDereferencer.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 15
Source File: DOMURIDereferencer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 16
Source File: DOMURIDereferencer.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 17
Source File: DOMURIDereferencer.java From hottub with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, secVal); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 18
Source File: DOMURIDereferencer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 19
Source File: DOMURIDereferencer.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } Node referencedElem = dcc.getElementById(id); if (referencedElem != null) { if (secVal) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " were detected"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, secVal); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }
Example 20
Source File: DOMURIDereferencer.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public Data dereference(URIReference uriRef, XMLCryptoContext context) throws URIReferenceException { if (uriRef == null) { throw new NullPointerException("uriRef cannot be null"); } if (context == null) { throw new NullPointerException("context cannot be null"); } DOMURIReference domRef = (DOMURIReference) uriRef; Attr uriAttr = (Attr) domRef.getHere(); String uri = uriRef.getURI(); DOMCryptoContext dcc = (DOMCryptoContext) context; String baseURI = context.getBaseURI(); boolean secVal = Utils.secureValidation(context); if (secVal && Policy.restrictReferenceUriScheme(uri)) { throw new URIReferenceException( "Uri " + uri + " is forbidden when secure validation is enabled"); } // Check if same-document URI and already registered on the context if (uri != null && uri.length() != 0 && uri.charAt(0) == '#') { String id = uri.substring(1); if (id.startsWith("xpointer(id(")) { int i1 = id.indexOf('\''); int i2 = id.indexOf('\'', i1+1); id = id.substring(i1+1, i2); } // check if element is registered by Id Node referencedElem = uriAttr.getOwnerDocument().getElementById(id); if (referencedElem == null) { // see if element is registered in DOMCryptoContext referencedElem = dcc.getElementById(id); } if (referencedElem != null) { if (secVal && Policy.restrictDuplicateIds()) { Element start = referencedElem.getOwnerDocument().getDocumentElement(); if (!XMLUtils.protectAgainstWrappingAttack(start, (Element)referencedElem, id)) { String error = "Multiple Elements with the same ID " + id + " detected when secure validation" + " is enabled"; throw new URIReferenceException(error); } } XMLSignatureInput result = new XMLSignatureInput(referencedElem); if (!uri.substring(1).startsWith("xpointer(id(")) { result.setExcludeComments(true); } result.setMIMEType("text/xml"); if (baseURI != null && baseURI.length() > 0) { result.setSourceURI(baseURI.concat(uriAttr.getNodeValue())); } else { result.setSourceURI(uriAttr.getNodeValue()); } return new ApacheNodeSetData(result); } } try { ResourceResolver apacheResolver = ResourceResolver.getInstance(uriAttr, baseURI, false); XMLSignatureInput in = apacheResolver.resolve(uriAttr, baseURI, false); if (in.isOctetStream()) { return new ApacheOctetStreamData(in); } else { return new ApacheNodeSetData(in); } } catch (Exception e) { throw new URIReferenceException(e); } }