Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.encryption » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.pdfbox.pdmodel.encryption;
   18   
   19   /**
   20    * This class represents the protection policy to add to a document
   21    * for password-based protection.
   22    *
   23    * The following example shows how to protect a PDF document with password.
   24    * In this example, the document will be protected so that someone opening
   25    * the document with the user password <code>user_pwd</code> will not be
   26    * able to modify the document.
   27    *
   28    * <pre>
   29    * AccessPermission ap = new AccessPermission();
   30    * ap.setCanModify(false);
   31    * StandardProtectionPolicy policy = new StandardProtectionPolicy(owner_pwd, user_pwd, ap);
   32    * doc.protect(policy);
   33    * </pre>
   34    *
   35    * @author Benoit Guillon (benoit.guillon@snv.jussieu.fr)
   36    * @version $Revision: 1.3 $
   37    */
   38   public class StandardProtectionPolicy extends ProtectionPolicy
   39   {
   40   
   41       private AccessPermission permissions;
   42   
   43       private String ownerPassword = "";
   44   
   45       private String userPassword = "";
   46   
   47   
   48       /**
   49        * Creates an new instance of the standard protection policy
   50        * in order to protect a PDF document with passwords.
   51        *
   52        * @param ownerPass The owner's password.
   53        * @param userPass The users's password.
   54        * @param perms The access permissions given to the user.
   55        */
   56       public StandardProtectionPolicy(String ownerPass, String userPass, AccessPermission perms)
   57       {
   58           this.permissions = perms;
   59           this.userPassword = userPass;
   60           this.ownerPassword = ownerPass;
   61       }
   62   
   63       /**
   64        * Getter of the property <tt>permissions</tt>.
   65        *
   66        * @return Returns the permissions.
   67        */
   68       public AccessPermission getPermissions()
   69       {
   70           return permissions;
   71       }
   72   
   73       /**
   74        * Setter of the property <tt>permissions</tt>.
   75        *
   76        * @param perms The permissions to set.
   77        */
   78       public void setPermissions(AccessPermission perms)
   79       {
   80           this.permissions = perms;
   81       }
   82   
   83       /**
   84        * Getter of the property <tt>ownerPassword</tt>.
   85        *
   86        * @return Returns the ownerPassword.
   87        */
   88       public String getOwnerPassword()
   89       {
   90           return ownerPassword;
   91       }
   92   
   93       /**
   94        * Setter of the property <tt>ownerPassword</tt>.
   95        *
   96        * @param ownerPass The ownerPassword to set.
   97        */
   98       public void setOwnerPassword(String ownerPass)
   99       {
  100           this.ownerPassword = ownerPass;
  101       }
  102   
  103       /**
  104        * Getter of the property <tt>userPassword</tt>.
  105        *
  106        * @return Returns the userPassword.
  107        */
  108       public String getUserPassword()
  109       {
  110           return userPassword;
  111       }
  112   
  113       /**
  114        * Setter of the property <tt>userPassword</tt>.
  115        *
  116        * @param userPass The userPassword to set.
  117        */
  118       public void setUserPassword(String userPass)
  119       {
  120           this.userPassword = userPass;
  121       }
  122   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.encryption » [javadoc | source]