Example usage for javax.xml.crypto.dsig XMLSignatureFactory unmarshalXMLSignature

List of usage examples for javax.xml.crypto.dsig XMLSignatureFactory unmarshalXMLSignature

Introduction

In this page you can find the example usage for javax.xml.crypto.dsig XMLSignatureFactory unmarshalXMLSignature.

Prototype

public abstract XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure) throws MarshalException;

Source Link

Document

Unmarshals a new XMLSignature instance from a mechanism-specific XMLStructure instance.

Usage

From source file:test.unit.be.fedict.eid.dss.spi.utils.XAdESValidationTest.java

private XMLSignature getXmlSignature(Node signatureNode) throws Exception {

    DOMValidateContext domValidateContext = new DOMValidateContext(
            KeySelector.singletonKeySelector(keyPair.getPublic()), signatureNode);
    XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
    XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
    boolean validity = xmlSignature.validate(domValidateContext);
    assertTrue(validity);/*  ww w.  j a v  a  2s  .co  m*/
    return xmlSignature;
}

From source file:test.unit.be.fedict.eid.idp.protocol.ws_federation.WSFederationMetadataHttpServletTest.java

public void testSignatureVerification() throws Exception {
    // setup//w  w  w.ja  v a2 s .c  o m
    InputStream documentInputStream = WSFederationProtocolServiceTest.class
            .getResourceAsStream("/FederationMetadata.xml");
    assertNotNull(documentInputStream);

    Document document = loadDocument(documentInputStream);

    NodeList signatureNodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    assertEquals(1, signatureNodeList.getLength());
    Node signatureNode = signatureNodeList.item(0);

    KeyInfoKeySelector keySelector = new KeyInfoKeySelector();
    DOMValidateContext domValidateContext = new DOMValidateContext(keySelector, signatureNode);

    XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
    XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);

    // operate
    boolean validity = xmlSignature.validate(domValidateContext);

    // verify
    assertTrue(validity);
}

From source file:test.unit.be.fedict.eid.idp.protocol.ws_federation.WSFederationProtocolServiceTest.java

public void testSignatureVerification() throws Exception {
    // setup/*from ww w  .ja  v a 2s . co m*/
    InputStream documentInputStream = WSFederationProtocolServiceTest.class
            .getResourceAsStream("/sts-response-message.xml");
    assertNotNull(documentInputStream);

    Document document = loadDocument(documentInputStream);

    NodeList signatureNodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
    assertEquals(1, signatureNodeList.getLength());
    Node signatureNode = signatureNodeList.item(0);

    KeyInfoKeySelector keySelector = new KeyInfoKeySelector();
    DOMValidateContext domValidateContext = new DOMValidateContext(keySelector, signatureNode);
    SAMLURIDereferencer dereferencer = new SAMLURIDereferencer(document);
    domValidateContext.setURIDereferencer(dereferencer);

    XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
    XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);

    // operate
    boolean validity = xmlSignature.validate(domValidateContext);

    // verify
    assertTrue(validity);
}