public abstract class StandardSecurityHandler extends AbstractSecurityHandler implements IAccessPermissionsSupport
Be aware that there is no internal check for permissions. The reason is simply that on the API level there's nothing that really keeps you from manipulating a PDF document.
On one hand, changing simply the security relevant parameters won't work as the crypt key is cached. It is necessary to create and associate a new security handler. Here we could check and abandon the request if no owner permissions are set. But this is no real problem, as you could read the complete document with user permissions and as such simply copy the root.
So we didn't even care as this would pollute the implementation while providing only superficial benefits.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_ACCESS_PERMISSIONS
The default value for the access permission flags.
|
static COSName |
DK_EncryptMetadata |
static COSName |
DK_O |
static COSName |
DK_P |
static COSName |
DK_R |
static COSName |
DK_U |
| Constructor and Description |
|---|
StandardSecurityHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
apply() |
void |
attach(STDocument doc)
Associate this
ISecurityHandler with a STDocument. |
void |
authenticate()
Perform an authentication.
|
abstract boolean |
authenticateOwner(byte[] owner) |
abstract boolean |
authenticateUser(byte[] user) |
int |
basicGetPermissionFlags() |
void |
basicSetPermissionFlags(int newValue) |
byte[] |
decrypt(COSObjectKey key,
byte[] bytes)
Decrypt any bytes in the context of COSObject referenced by the provided
key.
|
void |
detach(STDocument doc)
Disassociate this
ISecurityHandler from STDocument. |
byte[] |
encrypt(COSObjectKey key,
byte[] bytes)
Encrypt any bytes in the context of COSObject referenced by the provided
key.
|
IAccessPermissions |
getAccessPermissions()
The access permissions active for the document.
|
IAuthenticationHandler |
getAuthenticationHandler() |
byte[] |
getCryptKey()
The crypt key created by this
ISecurityHandler. |
PermissionFlags |
getPermissionFlags() |
abstract int |
getRevision() |
void |
initialize(STDocument doc)
Initialize this
ISecurityHandler with a STDocument. |
boolean |
isEncryptMetadata() |
void |
setAuthenticationHandler(IAuthenticationHandler authenticationHandler) |
void |
setEncryptMetadata(boolean value) |
void |
setOwnerPassword(byte[] pOwner)
Set new owner password for the
ISecurityHandler. |
void |
setUserPassword(byte[] pUser)
Set new user password for the
ISecurityHandler. |
cosGetEncryption, getEncryption, stGetDocpublic static final int DEFAULT_ACCESS_PERMISSIONS
Everything is allowed, only the reserved flags are zero.
public static final COSName DK_EncryptMetadata
public static final COSName DK_O
public static final COSName DK_P
public static final COSName DK_R
public static final COSName DK_U
public void apply()
throws COSSecurityException
COSSecurityExceptionpublic void attach(STDocument doc)
ISecurityHandlerISecurityHandler with a STDocument.
The ISecurityHandler should add all its private information to
the document structure, in particular to the /Encrypt dictionary.
attach in interface ISecurityHandlerattach in class AbstractSecurityHandlerpublic final void authenticate()
throws COSSecurityException
ISecurityHandlerauthenticate in interface ISecurityHandlerCOSSecurityExceptionpublic abstract boolean authenticateOwner(byte[] owner)
throws COSSecurityException
COSSecurityExceptionpublic abstract boolean authenticateUser(byte[] user)
throws COSSecurityException
COSSecurityExceptionpublic int basicGetPermissionFlags()
public void basicSetPermissionFlags(int newValue)
throws COSSecurityException
COSSecurityExceptionpublic byte[] decrypt(COSObjectKey key, byte[] bytes) throws COSSecurityException
ICryptHandlerdecrypt in interface ICryptHandlerkey - of the object which provides the contextbytes - to decryptCOSSecurityExceptionpublic void detach(STDocument doc) throws COSSecurityException
ISecurityHandlerISecurityHandler from STDocument.
The ISecurityHandler should remove all its private information
from the document structure, in particular from the /Encrypt dictionary.
detach in interface ISecurityHandlerdetach in class AbstractSecurityHandlerCOSSecurityExceptionpublic byte[] encrypt(COSObjectKey key, byte[] bytes) throws COSSecurityException
ICryptHandlerencrypt in interface ICryptHandlerkey - of the object which provides the contextbytes - to decryptCOSSecurityExceptionpublic final IAccessPermissions getAccessPermissions()
IAccessPermissionsSupport
The return value of this method not only depends on the permissions
encoded by the ISecurityHandler, but also on the outcome of the
authentication.
A negative authentication should result in no permissions, a positive authentication should result either in the encoded permissions for a user authentication or in all permissions for a successful owner authentication.
getAccessPermissions in interface IAccessPermissionsSupportpublic IAuthenticationHandler getAuthenticationHandler()
public byte[] getCryptKey()
ISecurityHandlerISecurityHandler. The crypt key is
used by the ISystemSecurityHandler (or the ICryptHandler
to initialize its cryptographic functions.
The crypt key is valid after the authentication.
getCryptKey in interface ISecurityHandlerISecurityHandler.public PermissionFlags getPermissionFlags()
public abstract int getRevision()
public void initialize(STDocument doc)
ISecurityHandlerISecurityHandler with a STDocument.
The ISecurityHandler should initialize its state from the
information in the document structure, in particular from the /Encrypt
dictionary.
initialize in interface ISecurityHandlerinitialize in class AbstractSecurityHandlerpublic boolean isEncryptMetadata()
public void setAuthenticationHandler(IAuthenticationHandler authenticationHandler)
public void setEncryptMetadata(boolean value)
public void setOwnerPassword(byte[] pOwner)
throws COSSecurityException
ISecurityHandler.pOwner - The new owner password.COSSecurityExceptionpublic void setUserPassword(byte[] pUser)
throws COSSecurityException
ISecurityHandler.pUser - The new user passwordCOSSecurityExceptionCopyright © 2013 intarsys consulting GmbH. All Rights Reserved.