use of org.apache.xml.security.utils.resolver.ResourceResolverException in project OpenAM by OpenRock.
the class OfflineResolver method engineResolve.
/**
* Method engineResolve
*
* @param uri
* @param BaseURI
* @throws ResourceResolverException
*/
public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException {
try {
String URI = uri.getNodeValue();
String newURI = (String) this._uriMap.get(URI);
if (newURI != null) {
InputStream is = new FileInputStream(newURI);
XMLSignatureInput result = new XMLSignatureInput(is);
// XMLSignatureInput result = new XMLSignatureInput(inputStream);
result.setSourceURI(URI);
result.setMIMEType((String) this._mimeMap.get(URI));
return result;
} else {
Object[] exArgs = { "The URI " + URI + " is not configured for offline work" };
throw new ResourceResolverException("generic.EmptyMessage", exArgs, uri, BaseURI);
}
} catch (IOException ex) {
throw new ResourceResolverException("generic.EmptyMessage", ex, uri, BaseURI);
}
}
use of org.apache.xml.security.utils.resolver.ResourceResolverException in project santuario-java by apache.
the class XMLCipherInput method getDecryptBytes.
/**
* Internal method to get bytes in decryption mode
* @return the decrypted bytes
* @throws XMLEncryptionException
*/
private byte[] getDecryptBytes() throws XMLEncryptionException {
String base64EncodedEncryptedOctets = null;
if (cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
// Fun time!
LOG.debug("Found a reference type CipherData");
CipherReference cr = cipherData.getCipherReference();
// Need to wrap the uri in an Attribute node so that we can
// Pass to the resource resolvers
Attr uriAttr = cr.getURIAsAttr();
XMLSignatureInput input = null;
try {
ResourceResolver resolver = ResourceResolver.getInstance(uriAttr, null, secureValidation);
input = resolver.resolve(uriAttr, null, secureValidation);
} catch (ResourceResolverException ex) {
throw new XMLEncryptionException(ex);
}
if (input != null) {
LOG.debug("Managed to resolve URI \"{}\"", cr.getURI());
} else {
LOG.debug("Failed to resolve URI \"{}\"", cr.getURI());
}
// Lets see if there are any transforms
Transforms transforms = cr.getTransforms();
if (transforms != null) {
LOG.debug("Have transforms in cipher reference");
try {
org.apache.xml.security.transforms.Transforms dsTransforms = transforms.getDSTransforms();
dsTransforms.setSecureValidation(secureValidation);
input = dsTransforms.performTransforms(input);
} catch (TransformationException ex) {
throw new XMLEncryptionException(ex);
}
}
try {
return input.getBytes();
} catch (IOException ex) {
throw new XMLEncryptionException(ex);
} catch (CanonicalizationException ex) {
throw new XMLEncryptionException(ex);
}
// retrieve the cipher text
} else if (cipherData.getDataType() == CipherData.VALUE_TYPE) {
base64EncodedEncryptedOctets = cipherData.getCipherValue().getValue();
} else {
throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value");
}
LOG.debug("Encrypted octets:\n{}", base64EncodedEncryptedOctets);
return Base64.getMimeDecoder().decode(base64EncodedEncryptedOctets);
}
use of org.apache.xml.security.utils.resolver.ResourceResolverException in project santuario-java by apache.
the class OfflineResolver method engineResolveURI.
/**
* Method engineResolve
*
* @param context
*
* @throws ResourceResolverException
*/
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
try {
String URI = context.uriToResolve;
if (OfflineResolver._uriMap.containsKey(URI)) {
String newURI = OfflineResolver._uriMap.get(URI);
LOG.debug("Mapped " + URI + " to " + newURI);
InputStream is = new FileInputStream(newURI);
LOG.debug("Available bytes = " + is.available());
XMLSignatureInput result = new XMLSignatureInput(is);
result.setSourceURI(URI);
result.setMIMEType(OfflineResolver._mimeMap.get(URI));
return result;
} else {
Object[] exArgs = { "The URI " + URI + " is not configured for offline work" };
throw new ResourceResolverException("generic.EmptyMessage", exArgs, context.uriToResolve, context.baseUri);
}
} catch (IOException ex) {
throw new ResourceResolverException(ex, context.uriToResolve, context.baseUri, "generic.EmptyMessage");
}
}
use of org.apache.xml.security.utils.resolver.ResourceResolverException in project santuario-java by apache.
the class ResolverDirectHTTPTest method testBug40783.
@Test
public void testBug40783() throws Exception {
Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
Attr uri = doc.createAttribute("id");
uri.setNodeValue("urn:ddd:uuu");
doc.createElement("test").setAttributeNode(uri);
try {
ResourceResolver resolver = ResourceResolver.getInstance(uri, null, true);
fail("No exception thrown, but resolver found: " + resolver);
} catch (ResourceResolverException e) {
//
}
}
use of org.apache.xml.security.utils.resolver.ResourceResolverException in project santuario-java by apache.
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(ex);
} catch (CanonicalizationException ex) {
throw new XMLSignatureException(ex);
} catch (InvalidCanonicalizerException ex) {
throw new XMLSignatureException(ex);
} catch (TransformationException ex) {
throw new XMLSignatureException(ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException(ex);
}
}
Aggregations