12
Security
Adding Security to PDF Documents
In order to obtain certificates from a directory, you must first connect to it using the
directory
object’s
connect
method, which returns a
DirConnection
object. An
example is given below:
// Obtain the security handler:
var sh = security.getHandler("Adobe.PPKMS");
var dc = sh.directories[0].connect();
It is then possible to use the
DirConnection
object to search for certificates. You can
specify the list of attributes to be used for the search by invoking the
DirConnection
object’s
setOutputFields
method, which accepts two parameters:
oFields
: an array of attributes to be used in the search
●
bCustom
: whether the attributes are standard output attribute names
For example, the following code specifies standard output attributes (
certificates
and
email
):
●
dc.setOutputAttributes({oFields: ["certificates", "email"]});
To perform the search, invoke the
DirConnection
object’s
search
method, which
accepts the following parameters:
●
oParams
: an array of key-value pairs consisting of search attribute names and their
corresponding strings
●
●
●
cGroupName
: the name of the group to which to restrict the search
bCustom
: whether
oParams
contains standard attribute names
bUI
: whether a user interface is used to collect the search parameters
In the following example, the directory is searched for certificates for the user whose last
name is "Smith", and displays the user’s email address:
var retval = dc.search({oParams: {lastName: "Smith"}});
if (retval.length > 0)
console.println(retval[0].email);
212
Acrobat JavaScript Scripting Guide