/**
  * Validate the SAML2 Document
  *
  * @param signedDocument
  * @param publicKey
  * @return
  * @throws ProcessingException
  */
 public boolean validate(Document signedDocument, PublicKey publicKey) throws ProcessingException {
   try {
     configureIdAttribute(signedDocument);
     return XMLSignatureUtil.validate(signedDocument, publicKey);
   } catch (MarshalException me) {
     throw new ProcessingException(logger.signatureError(me));
   } catch (XMLSignatureException xse) {
     throw new ProcessingException(logger.signatureError(xse));
   }
 }
  /**
   * Sign an Document at the root
   *
   * @param response
   * @param keyPair Key Pair
   * @param digestMethod (Example: DigestMethod.SHA1)
   * @param signatureMethod (Example: SignatureMethod.DSA_SHA1)
   * @return
   * @throws ParserConfigurationException
   * @throws XMLSignatureException
   * @throws MarshalException
   * @throws GeneralSecurityException
   */
  public Document sign(Document doc, String referenceID, KeyPair keyPair)
      throws ParserConfigurationException, GeneralSecurityException, MarshalException,
          XMLSignatureException {
    String referenceURI = "#" + referenceID;

    configureIdAttribute(doc);

    if (sibling != null) {
      SignatureUtilTransferObject dto = new SignatureUtilTransferObject();
      dto.setDocumentToBeSigned(doc);
      dto.setKeyPair(keyPair);
      dto.setDigestMethod(digestMethod);
      dto.setSignatureMethod(signatureMethod);
      dto.setReferenceURI(referenceURI);
      dto.setNextSibling(sibling);

      if (x509Certificate != null) {
        dto.setX509Certificate(x509Certificate);
      }

      return XMLSignatureUtil.sign(dto);
    }
    return XMLSignatureUtil.sign(doc, keyPair, digestMethod, signatureMethod, referenceURI);
  }