public class DocumentSecurity
Example:
// Create a blank document, which has no security of any kind by default
Document doc = new Document();
// The "Security" property serves as a description of the security level of a document
Assert.assertEquals(doc.getBuiltInDocumentProperties().getSecurity(), DocumentSecurity.NONE);
// Upon saving a document after setting its security level, Aspose automatically updates this property to the appropriate value
doc.getWriteProtection().setReadOnlyRecommended(true);
doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyRecommended.docx");
// We can open a document and glance at its security level like this
Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyRecommended.docx").getBuiltInDocumentProperties().getSecurity(),
DocumentSecurity.READ_ONLY_RECOMMENDED);
// Create a new document and set it to Write-Protected
doc = new Document();
Assert.assertFalse(doc.getWriteProtection().isWriteProtected());
doc.getWriteProtection().setPassword("MyPassword");
Assert.assertTrue(doc.getWriteProtection().validatePassword("MyPassword"));
Assert.assertTrue(doc.getWriteProtection().isWriteProtected());
doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyEnforced.docx");
// This document's security level counts as "ReadOnlyEnforced"
Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyEnforced.docx").getBuiltInDocumentProperties().getSecurity(),
DocumentSecurity.READ_ONLY_ENFORCED);
// Since this is still a descriptive property, we can protect a document and pick a suitable value ourselves
doc = new Document();
doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS, "MyPassword");
doc.getBuiltInDocumentProperties().setSecurity(DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
doc.save(getArtifactsDir() + "Properties.Security.ReadOnlyExceptAnnotations.docx");
Assert.assertEquals(new Document(getArtifactsDir() + "Properties.Security.ReadOnlyExceptAnnotations.docx").getBuiltInDocumentProperties().getSecurity(),
DocumentSecurity.READ_ONLY_EXCEPT_ANNOTATIONS);
Field Summary | ||
---|---|---|
static final int | NONE | |
There are no security states specified by the property.
|
||
static final int | PASSWORD_PROTECTED | |
The document is password protected. (Note has never been seen in a document so far).
|
||
static final int | READ_ONLY_RECOMMENDED | |
The document to be opened read-only if possible, but the setting can be overridden.
|
||
static final int | READ_ONLY_ENFORCED | |
The document to always be opened read-only.
|
||
static final int | READ_ONLY_EXCEPT_ANNOTATIONS | |
The document to always be opened read-only except for annotations.
|
public static final int NONE
public static final int PASSWORD_PROTECTED
public static final int READ_ONLY_RECOMMENDED
public static final int READ_ONLY_ENFORCED
public static final int READ_ONLY_EXCEPT_ANNOTATIONS