Quick Start (SwaRef): Verifying a digital signature using the web service API

The following Java code example verifies a digital signature that is located in a signed PDF document that is based on a PDF file named LoanSigned.pdf. (See Verifying Digital Signatures.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Signature services  WSDL. You can use JAX-WS to create 
    * the proxy Java files.   
    *  
    * If you are supplying a set of associated files, add the file name to the BLOB attribute. 
    * The create3DPDF service uses those file names to resolve references from the main assembly file. 
    *    
    * For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle 
    */ 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class VerifySignatureSWAref{ 
 
    public static void main(String[] args) { 
         
    try 
    { 
     //Set LiveCycle connection values 
     String url = "http://hiro-xp:8080/soap/services/signatureservice?blob=swaRef"; 
     String username = "administrator"; 
     String password = "password"; 
             
     // Create the service Client objects needed 
     SignatureServiceService signatureService = new SignatureServiceService(); 
     SignatureService signatureClient =  signatureService.getSignatureservice(); 
 
     // Retrieve the Web services from the LiveCycle server. 
     ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
     ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
     ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
     
     //Specify a PDF document that contains a digital signature 
     String path1 = "C:\\Adobe\LoanSigned.pdf"; 
     FileDataSource ds1 = new FileDataSource(path1);  
     DataHandler handler1 = new DataHandler(ds1); 
     BLOB inDoc = new BLOB(); 
     inDoc.setSwaRef(handler1); 
         
      //Specify the name of the signature field 
      String fieldName = "SignatureField1"; 
     
      //Create a PKIOptions object that contains PKI run-time options 
      PKIOptions pkiOptions = new PKIOptions();  
      pkiOptions.setVerificationTime(VerificationTime.CURRENT_TIME); 
      pkiOptions.setRevocationCheckStyle(RevocationCheckStyle.BEST_EFFORT); 
     
      //Verify the digital signature 
      PDFSignatureVerificationInfo  signInfo = signatureClient.verify2( 
         inDoc, 
         fieldName, 
         pkiOptions, 
         null); 
 
      //Get the Signature Status 
      SignatureStatus sigStatus = signInfo.getStatus(); 
      String myStatus="";  
     
      //Determine the status of the signature 
      if (sigStatus == SignatureStatus.DYNAMIC_FORM_SIGNATURE_UNKNOWN) 
             myStatus = "The signatures located in the dynamic PDF form are unknown"; 
         else if (sigStatus == SignatureStatus.DOCUMENT_SIGNATURE_UNKNOWN) 
             myStatus = "The signatures located in the PDF document are unknown"; 
         else if (sigStatus == SignatureStatus.CERTIFIED_DYNAMIC_FORM_SIGNATURE_TAMPER) 
             myStatus = "The signatures located in a certified PDF form are valid"; 
         else if (sigStatus == SignatureStatus.SIGNED_DYNAMIC_FORM_SIGNATURE_TAMPER) 
             myStatus = "The signatures located in a signed dynamic PDF form are valid"; 
         else if (sigStatus == SignatureStatus.CERTIFIED_DOCUMENT_SIGNATURE_TAMPER) 
             myStatus = "The signatures located in a certified PDF document are valid"; 
         else if (sigStatus == SignatureStatus.SIGNED_DOCUMENT_SIGNATURE_TAMPER) 
             myStatus = "The signatures located in a signed PDF document are valid"; 
         else if (sigStatus == SignatureStatus.SIGNATURE_FORMAT_ERROR) 
             myStatus = "The format of a signature in a signed document is invalid"; 
         else if (sigStatus == SignatureStatus.DYNAMIC_FORM_SIG_NO_CHANGES) 
             myStatus = "No changes were made to the signed dynamic PDF form"; 
         else if (sigStatus == SignatureStatus.DOCUMENT_SIG_NO_CHANGES) 
             myStatus = "No changes were made to the signed PDF document"; 
         else if (sigStatus == SignatureStatus.DYNAMIC_FORM_CERTIFICATION_SIG_NO_CHANGES) 
             myStatus = "No changes were made to the certified dynamic PDF form"; 
         else if (sigStatus == SignatureStatus.DOCUMENT_CERTIFICATION_SIG_NO_CHANGES) 
             myStatus = "No changes were made to the certified PDF document"; 
         else if (sigStatus == SignatureStatus.DOC_SIG_WITH_CHANGES) 
             myStatus = "There were changes to a signed PDF document"; 
        else if (sigStatus == SignatureStatus.CERTIFIED_DOC_SIG_WITH_CHANGES) 
             myStatus = "There were changes made to the PDF document."; 
               
      //Get the signature type 
      SignatureType sigType = signInfo.getSignatureType(); 
      String myType = ""; 
         
      if (sigType.getType() == PDFSignatureType.AUTHORSIG) 
             myType="Certification"; 
      else if(sigType.getType() == PDFSignatureType.RECIPIENTSIG) 
             myType="Recipient"; 
     
      //Get the identity of the signer 
      IdentityInformation signerId = signInfo.getSigner(); 
      String signerMsg = ""; 
     
     if (signerId.getStatus() == IdentityStatus.UNKNOWN) 
         signerMsg = "Identity Unknown"; 
     else if (signerId.getStatus() == IdentityStatus.TRUSTED) 
         signerMsg = "Identity Trusted"; 
     else if (signerId.getStatus() == IdentityStatus.NOTTRUSTED) 
         signerMsg = "Identity Not Trusted"; 
              
     //Get the Signature properties returned by the Signature service 
     SignatureProperties sigProps = signInfo.getSignatureProps(); 
     String signerName =  sigProps.getSignerName(); 
     
    System.out.println("The status of the signature is: "+myStatus +". The signer identity is "+signerMsg +". The signature type is "+myType +". The name of the signer is "+signerName+"."); 
    } 
    catch (Exception ee) 
    { 
        ee.printStackTrace(); 
    } 
     } 
} 

// Ethnio survey code removed