Quick Start (SwaRef): Verifying multiple digital signatures using the web service API

The following Java code example verifies multiple digital signatures that are located in a signed PDF document that is based on a PDF file named LoanAllSigs.pdf. The verification time is set to current time and the revocation checking option is set to best effort. (See Verifying Multiple 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 java.util.*; 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
import com.adobe.idp.services.*; 
 
 
public class VerifyAllSignaturesSWAref{ 
 
    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 multiple digital signatures 
          String path1 = "C:\\Adobe\LoanAllSigs.pdf"; 
          FileDataSource ds1 = new FileDataSource(path1);  
          DataHandler handler1 = new DataHandler(ds1); 
          BLOB inDoc = new BLOB(); 
          inDoc.setSwaRef(handler1); 
     
          //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 all digital signatures that are located in a PDF document 
          PDFDocumentVerificationInfo  allSig = signatureClient.verifyPDFDocument( 
                  inDoc, 
                  pkiOptions, 
                  null); 
 
          //Get a list of all signatures that are located in the PDF document 
          MyArrayOfXsdAnyType allSignatures = allSig.getVerificationInfos(); 
     
          //Create an Iterator object and iterate through  
          //the List object 
          List<Object> allSignaturesList =  allSignatures.getItem(); 
          Iterator<Object> iter = allSignaturesList.iterator();  
     
          while (iter.hasNext()) {  
              PDFSignatureVerificationInfo signInfo = (PDFSignatureVerificationInfo)iter.next();  
             
              //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 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 signature type is "+myType +". The name of the signer is "+signerName+"."); 
        } 
    } 
    catch (Exception ee) 
    { 
        ee.printStackTrace(); 
    } 
     } 
}