use of org.apache.xml.security.keys.content.KeyInfoReference in project santuario-java by apache.
the class KeyInfoReferenceResolver method resolveReferentKeyInfo.
/**
* Resolve the KeyInfoReference Element's URI attribute into a KeyInfo instance.
*
* @param element
* @param baseURI
* @param storage
* @return the KeyInfo which is referred to by this KeyInfoReference, or null if can not be resolved
* @throws XMLSecurityException
*/
private KeyInfo resolveReferentKeyInfo(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
KeyInfoReference reference = new KeyInfoReference(element, baseURI);
Attr uriAttr = reference.getURIAttr();
XMLSignatureInput resource = resolveInput(uriAttr, baseURI, secureValidation);
Element referentElement = null;
try {
referentElement = obtainReferenceElement(resource);
} catch (Exception e) {
LOG.debug("XMLSecurityException", e);
return null;
}
if (referentElement == null) {
LOG.debug("De-reference of KeyInfoReference URI returned null: {}", uriAttr.getValue());
return null;
}
validateReference(referentElement);
KeyInfo referent = new KeyInfo(referentElement, baseURI);
referent.addStorageResolver(storage);
return referent;
}
use of org.apache.xml.security.keys.content.KeyInfoReference in project santuario-java by apache.
the class KeyInfoReferenceTest method testSchema.
@org.junit.Test
public void testSchema() throws Exception {
KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
Element element = keyInfoReference.getElement();
assertEquals("http://www.w3.org/2009/xmldsig11#", element.getNamespaceURI());
assertEquals("KeyInfoReference", element.getLocalName());
}
use of org.apache.xml.security.keys.content.KeyInfoReference in project santuario-java by apache.
the class KeyInfoReferenceTest method testURIFromElement.
@org.junit.Test
public void testURIFromElement() throws Exception {
Document doc = loadXML("KeyInfoReference.xml");
NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpec11NS, Constants._TAG_KEYINFOREFERENCE);
Element element = (Element) nl.item(0);
KeyInfoReference keyInfoReference = new KeyInfoReference(element, "");
assertEquals(uriControl, keyInfoReference.getURI());
assertEquals(idControl, keyInfoReference.getId());
}
use of org.apache.xml.security.keys.content.KeyInfoReference in project santuario-java by apache.
the class KeyInfoReferenceTest method testId.
@org.junit.Test
public void testId() throws Exception {
KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
assertEquals("", keyInfoReference.getId());
assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
keyInfoReference.setId(idControl);
assertEquals(idControl, keyInfoReference.getId());
assertTrue(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID).isId());
keyInfoReference.setId(null);
assertEquals("", keyInfoReference.getId());
assertNull(keyInfoReference.getElement().getAttributeNodeNS(null, Constants._ATT_ID));
}
use of org.apache.xml.security.keys.content.KeyInfoReference in project santuario-java by apache.
the class KeyInfoReferenceTest method testURIOnConstruction.
@org.junit.Test
public void testURIOnConstruction() throws Exception {
KeyInfoReference keyInfoReference = new KeyInfoReference(documentBuilder.newDocument(), uriControl);
assertEquals(uriControl, keyInfoReference.getURI());
}
Aggregations