use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.
the class ResolverFragment method engineResolveURI.
/**
* Method engineResolve
*
* @inheritDoc
* @param uri
* @param baseURI
*/
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
Document doc = context.attr.getOwnerElement().getOwnerDocument();
Node selectedElem = null;
if (context.uriToResolve.equals("")) {
/*
* Identifies the node-set (minus any comment nodes) of the XML
* resource containing the signature
*/
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "ResolverFragment with empty URI (means complete document)");
}
selectedElem = doc;
} else {
/*
* 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.
*/
String id = context.uriToResolve.substring(1);
selectedElem = doc.getElementById(id);
if (selectedElem == null) {
Object[] exArgs = { id };
throw new ResourceResolverException("signature.Verification.MissingID", exArgs, context.attr, context.baseUri);
}
if (context.secureValidation) {
Element start = context.attr.getOwnerDocument().getDocumentElement();
if (!XMLUtils.protectAgainstWrappingAttack(start, id)) {
Object[] exArgs = { id };
throw new ResourceResolverException("signature.Verification.MultipleIDs", exArgs, context.attr, context.baseUri);
}
}
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Try to catch an Element with ID " + id + " and Element was " + selectedElem);
}
}
XMLSignatureInput result = new XMLSignatureInput(selectedElem);
result.setExcludeComments(true);
result.setMIMEType("text/xml");
if (context.baseUri != null && context.baseUri.length() > 0) {
result.setSourceURI(context.baseUri.concat(context.uriToResolve));
} else {
result.setSourceURI(context.uriToResolve);
}
return result;
}
use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.
the class ResolverLocalFilesystem method engineResolveURI.
/**
* @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);
}
}
use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.
the class ResolverXPointer method engineResolveURI.
/**
* @inheritDoc
*/
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
Node resultNode = null;
Document doc = context.attr.getOwnerElement().getOwnerDocument();
if (isXPointerSlash(context.uriToResolve)) {
resultNode = doc;
} else if (isXPointerId(context.uriToResolve)) {
String id = getXPointerId(context.uriToResolve);
resultNode = doc.getElementById(id);
if (context.secureValidation) {
Element start = context.attr.getOwnerDocument().getDocumentElement();
if (!XMLUtils.protectAgainstWrappingAttack(start, id)) {
Object[] exArgs = { id };
throw new ResourceResolverException("signature.Verification.MultipleIDs", exArgs, context.attr, context.baseUri);
}
}
if (resultNode == null) {
Object[] exArgs = { id };
throw new ResourceResolverException("signature.Verification.MissingID", exArgs, context.attr, context.baseUri);
}
}
XMLSignatureInput result = new XMLSignatureInput(resultNode);
result.setMIMEType("text/xml");
if (context.baseUri != null && context.baseUri.length() > 0) {
result.setSourceURI(context.baseUri.concat(context.uriToResolve));
} else {
result.setSourceURI(context.uriToResolve);
}
return result;
}
use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.
the class Reference method getContentsAfterTransformation.
private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os) throws XMLSignatureException {
try {
Transforms transforms = this.getTransforms();
XMLSignatureInput output = null;
if (transforms != null) {
output = transforms.performTransforms(input, os);
//new XMLSignatureInput(output.getBytes());
this.transformsOutput = output;
//this.transformsOutput.setSourceURI(output.getSourceURI());
} else {
output = input;
}
return output;
} catch (ResourceResolverException ex) {
throw new XMLSignatureException("empty", ex);
} catch (CanonicalizationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidCanonicalizerException ex) {
throw new XMLSignatureException("empty", ex);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
}
use of com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException in project jdk8u_jdk by JetBrains.
the class Reference method getContentsBeforeTransformation.
/**
* Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
* @return the XMLSignatureInput of the source of this reference
* @throws ReferenceNotInitializedException If the resolver found any
* problem resolving the reference
*/
public XMLSignatureInput getContentsBeforeTransformation() throws ReferenceNotInitializedException {
try {
Attr uriAttr = this.constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
ResourceResolver resolver = ResourceResolver.getInstance(uriAttr, this.baseURI, this.manifest.getPerManifestResolvers(), secureValidation);
resolver.addProperties(this.manifest.getResolverProperties());
return resolver.resolve(uriAttr, this.baseURI, secureValidation);
} catch (ResourceResolverException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
}
Aggregations