use of org.apache.xml.security.signature.reference.ReferenceOctetStreamData in project santuario-java by apache.
the class InteropTestBase method checkReferences.
private void checkReferences(XMLSignature xmlSignature) throws Exception {
SignedInfo signedInfo = xmlSignature.getSignedInfo();
assertTrue(signedInfo.getLength() > 0);
for (int i = 0; i < signedInfo.getLength(); i++) {
Reference reference = signedInfo.item(i);
assertNotNull(reference);
ReferenceData referenceData = reference.getReferenceData();
assertNotNull(referenceData);
if (referenceData instanceof ReferenceNodeSetData) {
Iterator<Node> iter = ((ReferenceNodeSetData) referenceData).iterator();
assertTrue(iter.hasNext());
boolean found = false;
while (iter.hasNext()) {
Node n = iter.next();
if (n instanceof Element) {
found = true;
break;
}
}
assertTrue(found);
} else if (referenceData instanceof ReferenceOctetStreamData) {
assertNotNull(((ReferenceOctetStreamData) referenceData).getOctetStream());
}
}
}
use of org.apache.xml.security.signature.reference.ReferenceOctetStreamData in project santuario-java by apache.
the class Reference method cacheDereferencedElement.
/**
* Store the dereferenced Element(s) so that it/they can be retrieved later.
*/
private void cacheDereferencedElement(XMLSignatureInput input) {
if (input.isNodeSet()) {
try {
final Set<Node> s = input.getNodeSet();
referenceData = new ReferenceNodeSetData() {
public Iterator<Node> iterator() {
return new Iterator<Node>() {
Iterator<Node> sIterator = s.iterator();
@Override
public boolean hasNext() {
return sIterator.hasNext();
}
@Override
public Node next() {
return sIterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
} catch (Exception e) {
// LOG a warning
LOG.warn("cannot cache dereferenced data: " + e);
}
} else if (input.isElement()) {
referenceData = new ReferenceSubTreeData(input.getSubNode(), input.isExcludeComments());
} else if (input.isOctetStream() || input.isByteArray()) {
try {
referenceData = new ReferenceOctetStreamData(input.getOctetStream(), input.getSourceURI(), input.getMIMEType());
} catch (IOException ioe) {
// LOG a warning
LOG.warn("cannot cache dereferenced data: " + ioe);
}
}
}
Aggregations