Class SignatureProvider
- java.lang.Object
-
- org.faceless.pdf2.viewer2.ViewerFeature
-
- org.faceless.pdf2.viewer2.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 signorcan verifythe 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.name The name of the entity signing the document - the default value of getDefaultName()reason The reason for the signature - the default value of getDefaultReason().location The location the signature is being applied - the default value of getDefaultLocation().certification The type of certification to use for the first signature applied to a PDF (the default value of getDefaultCertificationType()). Valid values arenone,nochanges,formsorcomments. If the signature being applied is not the initial signature this is ignored- Since:
- 2.11
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSignatureProvider.SignatureStateA SignatureState contains information about aFormSignatureonce it's been verified.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSignatureProvider(String name)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancanSign(FormSignature field)Return true if this SignatureProvider can sign the specified fieldabstract booleancanVerify(FormSignature field)Return true if this SignatureProvider can verify the specified fieldSignatureProvider.SignatureStatecreateSignatureState(FormSignature signature)Create a newSignatureProvider.SignatureStatethat is appropriate for use with this SignatureProvider.intgetDefaultCertificationType()Return the default type of certification for any new signatures using theshowSignDialog()method, or -1 to not specify a default.StringgetDefaultLocation()Return the location of the new signature being applied using theshowSignDialog()method, ornullto not specify a default.StringgetDefaultName()Return the name of the entity signing the document using theshowSignDialog()method, ornullto not specify a default.StringgetDefaultReason()Return the reason that the new signature is being applied using theshowSignDialog()method, ornullto not specify a default.abstract StringgetDisplayName()Return the "user friendly" name of this SignatureProvider, to use in dialogs and menus.static ImageIcongetIcon(DocumentPanel docpanel, FormSignature field)Get an Icon that can be used to describe the specified signature.static SignatureProvider.SignatureStategetSignatureState(DocumentPanel docpanel, FormSignature field)Get a previously determinedSignatureProvider.SignatureStatefor the specified signature field, as set bysetSignatureState().List<Map.Entry<String,String>>getSummaryText(FormSignature field, DocumentPanel docpanel)PDFViewergetViewer()Return thePDFViewerset ininitialize(org.faceless.pdf2.viewer2.PDFViewer)voidinitialize(PDFViewer viewer)Called when the feature is first added to a viewerstatic voidselectSignProvider(DocumentPanel docpanel, FormSignature field, JComponent comp, Point point, ActionListener listener)Select a SignatureProvider that can be used to sign the specified signature field.static voidselectVerifyProvider(DocumentPanel docpanel, FormSignature field, JComponent comp, Point point, ActionListener listener)Select a SignatureProvider that can be used to verify the specified signature field.static voidsetSignatureState(DocumentPanel docpanel, FormSignature field, SignatureProvider.SignatureState state)Set theSignatureProvider.SignatureStateof this field - should be called by theshowVerifyDialog()method after the field has been verified, to save the details of the verification.abstract voidshowSignDialog(JComponent root, FormSignature field)Display the signing dialog for the specified field, and assuming all goes well sign the field at the end.abstract voidshowVerifyDialog(JComponent root, FormSignature field)Show a dialog displaying information about the specified (signed) digital signature field.SignatureProvider.SignatureStateverify(JComponent root, FormSignature field)Verify the field.-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, isEnabledByDefault, setFeatureName, teardown, toString
-
-
-
-
Constructor Detail
-
SignatureProvider
protected SignatureProvider(String name)
-
-
Method Detail
-
initialize
public void initialize(PDFViewer viewer)
Description copied from class:ViewerFeatureCalled when the feature is first added to a viewer- Overrides:
initializein classViewerFeature
-
getViewer
public final PDFViewer getViewer()
Return thePDFViewerset ininitialize(org.faceless.pdf2.viewer2.PDFViewer)
-
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 theshowSignDialog()method, ornullto not specify a default.
-
getDefaultReason
public String getDefaultReason()
Return the reason that the new signature is being applied using theshowSignDialog()method, ornullto not specify a default.
-
getDefaultLocation
public String getDefaultLocation()
Return the location of the new signature being applied using theshowSignDialog()method, ornullto not specify a default.
-
getDefaultCertificationType
public int getDefaultCertificationType()
Return the default type of certification for any new signatures using theshowSignDialog()method, or -1 to not specify a default.- Returns:
- one of
FormSignature.CERTIFICATION_UNCERTIFIED,FormSignature.CERTIFICATION_NOCHANGES,FormSignature.CERTIFICATION_ALLOWFORMS,FormSignature.CERTIFICATION_ALLOWCOMMENTS, or the value -1 to prompt the user (the 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
-
showSignDialog
public abstract void showSignDialog(JComponent root, FormSignature field) throws IOException, GeneralSecurityException
Display the signing dialog for the specified field, and assuming all goes well sign the field at the end.- Parameters:
root- the JCompoment the dialog should be relative to - typically this is theDocumentPanelfield- the field to be signed- Throws:
IOExceptionGeneralSecurityException
-
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 theDocumentPanelfield- 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 fromcanVerify(). 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 forfield- the signed field- Returns:
- the SignatureState, or null if verification was cancelled and the state is unknown
- Since:
- 2.11.7
-
getIcon
public static final ImageIcon getIcon(DocumentPanel docpanel, FormSignature field)
Get an Icon that can be used to describe the specified signature.
-
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
listenerparameter specifies anActionListenerwhich will be called with the chosen provider - theActionEventit 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
listenerwill be called without a dialog being displayed.- Parameters:
docpanel- the DocumentPanel containing the PDFfield- the field the user is requesting to signcomp- the Component the user has clicked on or selected to request the signingpoint- the position relative tocompthat any dialog should be based around. If null, no dialog will be displayed, and hte first match will be usedlistener- 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
listenerparameter specifies anActionListenerwhich will be called with the chosen provider - theActionEventit 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
listenerwill be called without a dialog being displayed.- Parameters:
docpanel- the DocumentPanel containing the PDFfield- the field the user is requesting to verifycomp- the Component the user has clicked on or selected to request the verificationpoint- the position relative tocompthat any dialog should be based around. If null, no dialog will be displayed, and hte first match will be usedlistener- the ActionListener that should be called when the SignatureProvider is chosen
-
getSummaryText
public List<Map.Entry<String,String>> getSummaryText(FormSignature field, DocumentPanel docpanel)
-
createSignatureState
public SignatureProvider.SignatureState createSignatureState(FormSignature signature)
Create a newSignatureProvider.SignatureStatethat is appropriate for use with this SignatureProvider. This method is expected to be overridden by subclasses- Parameters:
signature- the signature (required)- Returns:
- a new
SignatureProvider.SignatureStateto be initialized - Since:
- 2.28.7
-
getSignatureState
public static final SignatureProvider.SignatureState getSignatureState(DocumentPanel docpanel, FormSignature field)
Get a previously determinedSignatureProvider.SignatureStatefor the specified signature field, as set bysetSignatureState(). If this method returnsnullthen the signature has not been verified yet.- Parameters:
docpanel- the DocumentPanel containing the signaturefield- the FormSignature whose state is being checked- Since:
- 2.11.7
-
setSignatureState
public static final void setSignatureState(DocumentPanel docpanel, FormSignature field, SignatureProvider.SignatureState state)
Set the
SignatureProvider.SignatureStateof this field - should be called by theshowVerifyDialog()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"DocumentPanelEventon 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 signaturefield- 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
-
-