Class SignatureProvider

  • Direct Known Subclasses:
    KeyStoreSignatureProvider

    public abstract class SignatureProvider
    extends ViewerFeature

    A ViewerFeature that acts as a service provider for applying Digital Signatures. When a digital signature field is encounted by the PDF viewer, it will search its list of features for an instance of this class that can sign or can verify the field as appropriate. A dialog will then be presented.

    Although each type of subclass will be different, there are several properties that apply to any digital signature and so they can be specified here. Subclasses implementing the showSignDialog() method are expected to use these values if specified, or prompt the user otherwise.

    The following initialization parameters can be specified to configure subclasses of this feature.
    nameThe name of the entity signing the document - the default value of getDefaultName()
    reasonThe reason for the signature - the default value of getDefaultReason().
    locationThe location the signature is being applied - the default value of getDefaultLocation().
    certificationThe type of certification to use for the first signature applied to a PDF (the default value of getDefaultCertificationType()). Valid values are none, nochanges, forms or comments. If the signature being applied is not the initial signature this is ignored
    Since:
    2.11
    • Constructor Detail

      • SignatureProvider

        protected SignatureProvider​(String name)
    • Method Detail

      • getDisplayName

        public abstract String getDisplayName()
        Return the "user friendly" name of this SignatureProvider, to use in dialogs and menus.
      • getDefaultName

        public String getDefaultName()
        Return the name of the entity signing the document using the showSignDialog() method, or null to not specify a default.
      • getDefaultReason

        public String getDefaultReason()
        Return the reason that the new signature is being applied using the showSignDialog() method, or null to not specify a default.
      • getDefaultLocation

        public String getDefaultLocation()
        Return the location of the new signature being applied using the showSignDialog() method, or null to not specify a default.
      • canSign

        public abstract boolean canSign​(FormSignature field)
        Return true if this SignatureProvider can sign the specified field
      • canVerify

        public abstract boolean canVerify​(FormSignature field)
        Return true if this SignatureProvider can verify the specified field
      • showVerifyDialog

        public abstract void showVerifyDialog​(JComponent root,
                                              FormSignature field)
        Show a dialog displaying information about the specified (signed) digital signature field. The dialog should display the signatures verification state, which may be determined by this method or retrieved from a previous verification
        Parameters:
        root - the JCompoment the dialog should be relative to - typically this is the DocumentPanel
        field - the field to be verified
      • verify

        public SignatureProvider.SignatureState verify​(JComponent root,
                                                       FormSignature field)
        Verify the field. Must be overridden by any SignatureProvider that returns true from canVerify(). This method may provide visual feedback to the user, but it's primary purpose is to verify the field and return its state so it should not block user progress unless it's unavoidable.
        Parameters:
        root - the component that should be used as a root for
        field - the signed field
        Returns:
        the SignatureState, or null if verification was cancelled and the state is unknown
        Since:
        2.11.7
      • selectSignProvider

        public static final void selectSignProvider​(DocumentPanel docpanel,
                                                    FormSignature field,
                                                    JComponent comp,
                                                    Point point,
                                                    ActionListener listener)

        Select a SignatureProvider that can be used to sign the specified signature field. The listener parameter specifies an ActionListener which will be called with the chosen provider - the ActionEvent it will be given will have the source set to the chosen provider and the action type set to "sign".

        If more than one SignatureProvider is available this method will show a dialog allowing the user to choose, otherwise the the listener will be called without a dialog being displayed.

        Parameters:
        docpanel - the DocumentPanel containing the PDF
        field - the field the user is requesting to sign
        comp - the Component the user has clicked on or selected to request the signing
        point - the position relative to comp that any dialog should be based around. If null, no dialog will be displayed, and hte first match will be used
        listener - the ActionListener that should be called when the SignatureProvider is chosen
      • selectVerifyProvider

        public static final void selectVerifyProvider​(DocumentPanel docpanel,
                                                      FormSignature field,
                                                      JComponent comp,
                                                      Point point,
                                                      ActionListener listener)

        Select a SignatureProvider that can be used to verify the specified signature field. The listener parameter specifies an ActionListener which will be called with the chosen provider - the ActionEvent it will be given will have the source set to the chosen provider and the action type set to "verify".

        If more than one SignatureProvider is available this method will show a dialog allowing the user to choose, otherwise the the listener will be called without a dialog being displayed.

        Parameters:
        docpanel - the DocumentPanel containing the PDF
        field - the field the user is requesting to verify
        comp - the Component the user has clicked on or selected to request the verification
        point - the position relative to comp that any dialog should be based around. If null, no dialog will be displayed, and hte first match will be used
        listener - the ActionListener that should be called when the SignatureProvider is chosen
      • setSignatureState

        public static final void setSignatureState​(DocumentPanel docpanel,
                                                   FormSignature field,
                                                   SignatureProvider.SignatureState state)

        Set the SignatureProvider.SignatureState of this field - should be called by the showVerifyDialog() method after the field has been verified, to save the details of the verification. This method may be called in any thread, but it will fire the "stateChanged" DocumentPanelEvent on the Swing Event Dispatch Thread.

        If "field" and "state" are both null, this is a special action that removes the state for any existing fields. This can be used to reset the state of all signatures in the document to unknown

        Parameters:
        docpanel - the DocumentPanel containing the signature
        field - the FormSignature that was verified, or if state==null, this can be null to indicate "all fields"
        state - the state of the signature, or null