建立邀請外部使用者處理常式 create-invite-external-users-handler
本檔案中的範例和範例僅適用於JEE環境上的AEM Forms 。
您可以為Rights Management服務建立「邀請外部使用者」處理常式。 邀請外部使用者處理常式可讓Rights Management服務邀請外部使用者成為Rights Management使用者。 當使用者成為Rights Management使用者後,該使用者便能執行工作,例如開啟受原則保護的PDF檔案。 將邀請外部使用者處理常式部署至AEM Forms後,您可以使用管理主控台與其互動。
步驟摘要
若要開發「邀請外部使用者」處理常式,您必須執行下列步驟:
- 設定您的開發環境。
- 定義「邀請外部使用者」處理常式實作。
- 定義元件XML檔案。
- 部署邀請外部使用者處理常式。
- 測試邀請外部使用者處理常式。
設定您的開發環境 setting-up-development-environment
若要設定開發環境,您必須建立Java專案,例如Eclipse專案。 支援的Eclipse版本為 3.2.1
或更新版本。
Rights ManagementSPI需要 edc-server-spi.jar
要在專案的類別路徑中設定的檔案。 如果您未參考此JAR檔案,則無法在Java專案中使用Rights ManagementSPI。 此JAR檔案會與AEM Forms SDK安裝在中 [install directory]\Adobe\Adobe_Experience_Manager_forms\sdk\spi
資料夾。
除了新增 edc-server-spi.jar
檔案到專案的類別路徑,您還必須新增使用Rights Management服務API所需的JAR檔案。 若要在邀請外部使用者處理常式中使用Rights Management服務API,則需要這些檔案。
定義邀請外部使用者處理常式實作 define-invite-external-users-handler
若要開發Invite外部使用者處理常式,您必須建立實作 com.adobe.edc.server.spi.ersp.InvitedUserProvider
介面。 此類別包含方法: invitedUser
,當使用提交電子郵件地址時,Rights Management服務會叫用它 新增受邀使用者 可透過管理控制檯存取的頁面。
此 invitedUser
方法接受 java.util.List
執行個體,其中包含從提交的字串型別電子郵件地址 新增受邀使用者 頁面。 此 invitedUser
方法傳回陣列 InvitedUserProviderResult
物件,通常是電子郵件地址到使用者物件的對應(不傳回null)。
邀請外部使用者處理常式的實作包含名為的使用者定義方法 createLocalPrincipalAccount
. 此方法接受將電子郵件地址指定為引數值的字串值。 此 createLocalPrincipalAccount
方法假設預先存在名為的本機網域 EDC_EXTERNAL_REGISTERED
. 您可以將此網域名稱設定為您想要的任何名稱;但是,對於生產應用程式,您可能想要與企業網域整合。
此 createUsers
方法逐一檢視每個電子郵件地址,並建立對應的使用者物件(位於中的本機使用者) EDC_EXTERNAL_REGISTERED
網域)。 最後, doEmails
方法稱為。 在範例中,此方法會刻意保留為虛設常式。 在生產環境實作中,它會包含應用程式邏輯,以將邀請電子郵件訊息傳送給新建立的使用者。 範例中會保留此功能,以示範實際應用程式的應用程式邏輯流程。
定義邀請外部使用者處理常式實作 user-handler-implementation
下列邀請外部使用者處理常式實作會接受從「新增受邀使用者」頁面(可透過管理控制檯存取)提交的電子郵件地址。
package com.adobe.livecycle.samples.inviteexternalusers.provider;
import com.adobe.edc.server.spi.ersp.*;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.um.api.*;
import com.adobe.idp.um.api.infomodel.*;
import com.adobe.idp.um.api.impl.UMBaseLibrary;
import com.adobe.livecycle.usermanager.client.DirectoryManagerServiceClient;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class InviteExternalUsersSample implements InvitedUserProvider
{
private ServiceClientFactory _factory = null;
private User createLocalPrincipalAccount(String email_address) throws Exception
{
String ret = null;
// Assume the local domain already exists!
String domain = "EDC_EXTERNAL_REGISTERED";
List aliases = new ArrayList();
aliases.add( email_address );
User local_user = UMBaseLibrary.createUser( email_address, domain, email_address );
local_user.setCommonName( email_address );
local_user.setEmail( email_address );
local_user.setEmailAliases( aliases );
// You may wish to disable the local user until, for example, his registration is processed by a confirmation link
//local_user.setDisabled( true );
DirectoryManager directory_manager = new DirectoryManagerServiceClient( _factory );
String ret_oid = directory_manager.createLocalUser( local_user, null );
if( ret_oid == null )
{
throw new Exception( "FAILED TO CREATE PRINCIPAL FOR EMAIL ADDRESS: " + email_address );
}
return local_user;
}
protected User[] createUsers( List emails ) throws Exception
{
ArrayList ret_users = new ArrayList();
_factory = ServiceClientFactory.createInstance();
Iterator iter = emails.iterator();
while( iter.hasNext() )
{
String current_email = (String)iter.next();
ret_users.add( createLocalPrincipalAccount( current_email ) );
}
return (User[])ret_users.toArray( new User[0] );
}
protected void doInvitations(List emails)
{
// Here you may choose to send the users who were created an invitation email
// This step is completely optional, depending on your requirements.
}
public InvitedUserProviderResult[] invitedUser(List emails)
{
// This sample demonstrates the workflow for inviting a user via email
try
{
User[] principals = createUsers(emails);
InvitedUserProviderResult[] result = new InvitedUserProviderResult[principals.length];
for( int i = 0; i < principals.length; i++ )
{
result[i] = new InvitedUserProviderResult();
result[i].setEmail( (String)emails.get( i ) );
result[i].setUser( principals[i] );
}
doInvitations(emails);
System.out.println( "SUCCESSFULLY INVITED " + result.length + " USERS" );
return result;
}
catch( Exception e )
{
System.out.println( "FAILED TO INVITE USERS FOR INVITE USERS SAMPLE" );
e.printStackTrace();
return new InvitedUserProviderResult[0];
}
}
}
定義授權處理常式的元件XML檔案 define-component-xml-authorization-handler
尋找元件XML檔案,以部署Invite外部使用者處理常式元件。 每個元件都有元件XML檔案,並提供有關元件的中繼資料。
下列專案 component.xml
檔案用於「邀請外部使用者」處理常式。 請注意,服務名稱為 InviteExternalUsersSample
而此服務公開的作業已命名 invitedUser
. 輸入引數為 java.util.List
例項,而輸出值為陣列 com.adobe.edc.server.spi.esrp.InvitedUserProviderResult
執行個體。
定義邀請外部使用者處理常式的元件XML檔案 component-xml-invite-external-users-handler
<component xmlns="https://adobe.com/idp/dsc/component/document">
<component-id>com.adobe.livecycle.samples.inviteexternalusers</component-id>
<version>1.0</version>
<bootstrap-class>com.adobe.livecycle.samples.inviteexternalusers.provider.BootstrapImpl</bootstrap-class>
<descriptor-class>com.adobe.idp.dsc.component.impl.DefaultPOJODescriptorImpl</descriptor-class>
<services>
<service name="InviteExternalUsersSample">
<specifications>
<specification spec-id="com.adobe.edc.server.spi.ersp.InvitedUserProvider"/>
</specifications>
<specification-version>1.0</specification-version>
<implementation-class>com.adobe.livecycle.samples.inviteexternalusers.provider.InviteExternalUsersSample</implementation-class>
<auto-deploy category-id="Samples" service-id="InviteExternalUsersSample" major-version="1" minor-version="0"/>
<operations>
<operation name="invitedUser">
<input-parameter name="input" type="java.util.List" required="true"/>
<output-parameter name="result" type="com.adobe.edc.server.spi.esrp.InvitedUserProviderResult[]"/>
</operation>
</operations>
</service>
</services>
</component>
正在封裝邀請外部使用者處理常式 packaging-invite-external-users-handler
若要將邀請外部使用者處理常式部署到AEM Forms,您必須將Java專案封裝到JAR檔案中。 請確定邀請外部使用者處理常式的商業邏輯所相依的外部JAR檔案,例如 edc-server-spi.jar
和 adobe-rightsmanagement-client.jar
檔案也包含在JAR檔案中。 此外,元件XML檔案也必須存在。 此 component.xml
檔案和外部JAR檔案必須位於JAR檔案的根目錄下。
BootstrapImpl
類別即會顯示。 本節未討論如何建立 BootstrapImpl
類別。下圖顯示封裝至邀請外部使用者處理常式的JAR檔案中的Java專案內容。
A.元件所需的外部JAR檔案B. JAVA檔案
將邀請外部使用者處理常式封裝到JAR檔案中。 在上圖中,請注意已列出.JAVA檔案。 封裝成JAR檔案後,也必須指定對應的.CLASS檔案。 如果沒有.CLASS檔案,授權處理常式將無法運作。
測試邀請外部使用者處理常式 testing-invite-external-users-handler
若要測試邀請外部使用者處理常式,您可以使用管理控制檯來新增要邀請的外部使用者。
若要使用管理主控台新增要邀請的外部使用者:
-
使用Workbench部署邀請外部使用者處理常式的JAR檔案。
-
重新啟動應用程式伺服器。
note note NOTE 建議您使用'Ctrl + C'命令重新啟動SDK。 使用替代方法重新啟動AEM SDK (例如停止Java程式)可能會導致AEM開發環境不一致。 -
登入管理主控台。
-
按一下 服務 > Rights Management > 設定 >已邀請 使用者註冊.
-
啟用受邀使用者註冊,方法是核取 啟用受邀使用者註冊 方塊。 在 使用內建註冊系統,按一下 否. 儲存您的設定。
-
在管理控制檯首頁上,按一下 設定 > User Management > 網域管理.
-
按一下 新增本機網域. 在下列頁面中,使用名稱和識別碼值建立網域
EDC_EXTERNAL_REGISTERED
. 儲存您的變更。 -
在管理控制檯首頁上,按一下 服務 > Rights Management > 受邀和本機使用者. 此 新增受邀使用者 頁面便會顯示。
-
輸入電子郵件地址(由於目前的邀請外部使用者處理常式並不會實際傳送電子郵件訊息,因此電子郵件地址不一定有效)。 按一下 確定. 使用者受邀加入系統。
-
在管理控制檯首頁上,按一下 設定 > User Management > 使用者和群組.
-
在 尋找 欄位,輸入您指定的電子郵件地址。 按一下 尋找. 您邀請的使用者會顯示為本機
EDC_EXTERNAL_REGISTERED
網域。