Implementing a SecurityCallback

compared with
Current by Mark Collette
on Jan 27, 2010 18:01.


 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 5 changes. View first change.

 \\
 When the Document class encounters a PDF document that is encrypted with Acrobat standard security, it first tries to open the PDF file with an empty password string. If the Document class fails to validate the empty password, the application must have a mechanism to request the password. You can use the *{{org.icepdf.core.SecurityCallback}}* interface to do this.
  \\
 When the Document class encounters a PDF document that is encrypted with Acrobat standard security, it first tries to open the PDF file with an empty password string. If the Document class fails to validate the empty password, the application must have a mechanism to request the password. You can use the {{{*}org.icepdf.core.SecurityCallback{*}}} interface to do this.
  
The interface has one method, which is called by the Document class to retrieve a document's password. You can implement the SecurityCallback interface in numerous ways to meet the needs of your application. For example, the package *{{org.icepdf.core.ri.common}}* contains reference code for the SecurityCallback in the class *{{MyGUISecurityCallback}}*.
  The interface has one method, which is called by the Document class to retrieve a document's password. You can implement the SecurityCallback interface in numerous ways to meet the needs of your application. For example, the package {{{*}org.icepdf.core.ri.common{*}}} contains reference code for the SecurityCallback in the class {{{*}MyGUISecurityCallback{*}}}.
  
Consider the following code which would allow a user to type in the documents password if needed.
  Consider the following code which would allow a user to type in the documents password if needed.
  
 {code}
 // new document instance
 Document document = new Document();
 // setup a security callback before opening an encrypted document.
 document.setSecurityCallback(new SecurityCallback(){
  public String requestPassword(Document document) {
  System.out.println(
  "This document is Encrypted please type the document password:");
  String input = "";
  // get users password
  try {
  BufferedReader stdin =
  new BufferedReader(new InputStreamReader(System.in));
  input = stdin.readLine();
  } catch (IOException e) {}
  return input;
  }
 });
// finally open the document.
  // finally open the document.
 document.setFile(filePath);
 {code}
  
  
 The anonymous inner class allows a developer to handle how they want to ask a user for the password, in this case the command line is used but alternatively could have used a dialog or some other input form.
  
  \\
  \\
  The anonymous inner class allows a developer to handle how they want to ask a user for the password. In this case the command line is used, but alternatively a dialog or some other input form could have been use.

© Copyright 2017 ICEsoft Technologies Canada Corp.