AEM Forms Document Security Java SDK提供API,讓使用者帳戶能代表其他使用者保護檔案,而無須取得編輯檔案的權限。 您可以在工作流程程式中使用API,或以程式設計方式將API用作檔案服務。 新API包括:
protectDocumentUse 代表將策略應用到文檔的ProtectDocument API
另一個使用者帳戶。 用於應用策略的用戶帳戶的權限仍僅限於保護文檔。 它沒有獲得開啟和查看檔案的權利。 RMSecureDocumentResult protectDocument(Document inDoc, String documentName, String policySetName, String policyName, RMLocale區域設定,布林值bExactMatchForNames)
createLicenseUse 建立許可證API,以代表其他用戶帳戶為策略建立許可證。 PublishLicenseDTO createLicense(String policyId, String documentName, boolean logSecureDocEvent)
protectDocumentWithCoverPageUse 用於應用策略並代表另一用戶向文檔添加封面的ProtectDocumentWithCoverPage API。 用於應用策略的用戶帳戶的權限仍僅限於保護文檔。 它沒有獲得開啟和查看檔案的權利。 RMSecureDocumentResultprotectDocumentWithCoverPage(Document inDoc, String documentName, String policySetName, String policyName, Document coverDoc, boolean bExactMatchForNames)
執行以下步驟以代表其他用戶保護文檔,而不獲得編輯文檔的權限:
建立策略集。 例如,PolicySet1。
在新建立的策略集中建立策略。 例如,PolicySet1中的Policy1。
建立具有角色Rights Management最終用戶的用戶。 例如User1。 為新建立的用戶提供查看使用Policy1保護的文檔的權限。
建立新角色。 例如,Role1。 為新建立的角色提供服務調用權限。 使用新建立的角色建立用戶。 例如, User2。您可以使用User2或管理員建立SDK連接並調用protectDocument服務。
現在,您可以運行以下示例代碼以保護文檔,而不向保護文檔的用戶提供編輯文檔的權限:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.adobe.edc.common.dto.PublishLicenseDTO;
import com.adobe.edc.sdk.SDKException;
import com.adobe.idp.Document;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
import com.adobe.livecycle.rightsmanagement.RMSecureDocumentResult;
import com.adobe.livecycle.rightsmanagement.client.DocumentManager;
import com.adobe.livecycle.rightsmanagement.client.RightsManagementClient;
import com.adobe.livecycle.rightsmanagement.client.RightsManagementClient2;
public class PublishAsProtectAPI {
private static final String unprotectedFileName = "C:\\unprotected.pdf";
private static final String protectedFileName = "C:\\protect.pdf";
private static final String coverFileName = "C:\\CoverPage.pdf";
private static final String POLICY_ID = "2EF66008-5E2D-1034-9B06-00000A292C18";
public static void main(String[] args) {
try {
Properties connectionProps = new Properties();
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT,"http://localhost:8080");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME,"administrator");
connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD,"password");
// Create a ServiceClientFactory instance
ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps);
testProtectDocument(factory);
testProtectDocumentWithCoverPage(factory);
testProtectDocumentJavaPPL(factory);
}
catch (Exception ex) {
ex.printStackTrace(); }
}
private static void testProtectDocument(ServiceClientFactory factory) throws FileNotFoundException, SDKException {
// Create a RightsManagementClient object
RightsManagementClient rmClient = new RightsManagementClient(factory);
// Create a Document Manager object
DocumentManager documentManager = rmClient.getDocumentManager();
//Reference a policy-protected PDF document from which to remove a policy
FileInputStream is = new FileInputStream(unprotectedFileName);
Document inPDF = new Document(is);
long startTime = System.currentTimeMillis();
//Remove a policy from the policy-protected PDF document
RMSecureDocumentResult securePDF = documentManager.protectDocument(inPDF, "test", "newPolicySet", "latest", "DefaultDom", "administrator", null, true);
System.out.println("Total Time taken for protectDocument = " + (System.currentTimeMillis() - startTime));
//Save the unsecured PDF document
File myFile = new File(protectedFileName);
securePDF.getProtectedDoc().copyToFile(myFile);
}
private static void testProtectDocumentWithCoverPage(ServiceClientFactory factory) throws FileNotFoundException, SDKException {
// Create a RightsManagementClient object
RightsManagementClient rmClient = new RightsManagementClient(factory);
// Create a Document Manager object
DocumentManager documentManager = rmClient.getDocumentManager();
//Reference a policy-protected PDF document from which to remove a policy
FileInputStream is = new FileInputStream(unprotectedFileName);
Document inPDF = new Document(is);
FileInputStream coverIS = new FileInputStream(coverFileName);
Document inCoverPDF = new Document(coverIS);
long startTime = System.currentTimeMillis();
//Remove a policy from the policy-protected PDF document
RMSecureDocumentResult securePDF = documentManager.protectDocumentWithCoverPage(inPDF, "test", "newPolicySet", "latestPolicy", inCoverPDF, true);
System.out.println("Total Time taken for Page0ProtectDocument = " + (System.currentTimeMillis() - startTime));
//Save the unsecured PDF document
File myFile = new File(protectedFileName);
securePDF.getProtectedDoc().copyToFile(myFile);
}
private static PublishLicenseDTO testProtectDocumentJavaPPL (ServiceClientFactory factory) throws SDKException, FileNotFoundException, IOException {
// Create a RightsManagementClient object
RightsManagementClient2 rmClient2 = new RightsManagementClient2(factory);
// Create a Document Manager object
DocumentManager documentManager = rmClient2.getDocumentManager();
long startTime = System.currentTimeMillis();
PublishLicenseDTO license = documentManager.createLicense(POLICY_ID, "Out.pdf", true);
System.out.println("Create License totalTime = " + (System.currentTimeMillis() - startTime));
startTime = System.currentTimeMillis();
// Reference a PDF document to which a policy is applied
InputStream inputFileStream = new FileInputStream(unprotectedFileName);
// Apply a policy to the PDF document
InputStream protectPDF = rmClient2.getRightsManagementEncryptionService().protectDocument(inputFileStream, license);
// Save the policy-protected PDF document
File myFile = new File(protectedFileName);
// write the inputStream to a FileOutputStream
FileOutputStream outputStream = new FileOutputStream(myFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = protectPDF.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
System.out.println("protectPDFDocument totalTime = " + (System.currentTimeMillis() - startTime));
outputStream.close();
inputFileStream.close();
System.out.println("Document Protected Successfully");
return license;
}
}