Search in sources :

Example 1 with KeyInfoReference

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;
}
Also used : KeyInfo(org.apache.xml.security.keys.KeyInfo) Element(org.w3c.dom.Element) KeyInfoReference(org.apache.xml.security.keys.content.KeyInfoReference) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Attr(org.w3c.dom.Attr) IOException(java.io.IOException) KeyResolverException(org.apache.xml.security.keys.keyresolver.KeyResolverException) CanonicalizationException(org.apache.xml.security.c14n.CanonicalizationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException) SAXException(org.xml.sax.SAXException)

Example 2 with KeyInfoReference

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());
}
Also used : Element(org.w3c.dom.Element) KeyInfoReference(org.apache.xml.security.keys.content.KeyInfoReference)

Example 3 with KeyInfoReference

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());
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) KeyInfoReference(org.apache.xml.security.keys.content.KeyInfoReference) Document(org.w3c.dom.Document)

Example 4 with KeyInfoReference

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));
}
Also used : KeyInfoReference(org.apache.xml.security.keys.content.KeyInfoReference)

Example 5 with KeyInfoReference

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());
}
Also used : KeyInfoReference(org.apache.xml.security.keys.content.KeyInfoReference)

Aggregations

KeyInfoReference (org.apache.xml.security.keys.content.KeyInfoReference)5 Element (org.w3c.dom.Element)3 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 CanonicalizationException (org.apache.xml.security.c14n.CanonicalizationException)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 KeyInfo (org.apache.xml.security.keys.KeyInfo)1 KeyResolverException (org.apache.xml.security.keys.keyresolver.KeyResolverException)1 XMLSignatureInput (org.apache.xml.security.signature.XMLSignatureInput)1 Attr (org.w3c.dom.Attr)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1