定義邀請外部使用者處理常式實作

下列邀請外部使用者處理常式實作會接受從「新增受邀使用者」頁面(可透過管理控制檯存取)提交的電子郵件地址。

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];
    }
       }
}

注意
此Java類別會儲存為名為InviteExternalUsersSample.java的JAVA檔案。

定義授權處理常式的元件XML檔案

尋找元件XML檔案,以部署Invite外部使用者處理常式元件。 每個元件都有元件XML檔案,並提供有關元件的中繼資料。

下列component.xml檔案用於邀請外部使用者處理常式。 請注意,服務名稱為InviteExternalUsersSample,此服務公開的操作名稱為invitedUser。 輸入引數是java.util.List執行個體,而輸出值是com.adobe.edc.server.spi.esrp.InvitedUserProviderResult執行個體的陣列。

定義邀請外部使用者處理常式的元件XML檔案

<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>

正在封裝邀請外部使用者處理常式

若要將邀請外部使用者處理常式部署到AEM Forms,您必須將Java專案封裝到JAR檔案中。 請確定JAR檔案中也包含Invite外部使用者處理常式商業邏輯所依賴的外部JAR檔案,例如edc-server-spi.jar和adobe-rightsmanagement-client.jar檔案。 此外,元件XML檔案也必須存在。 component.xml檔案和外部JAR檔案必須位於JAR檔案的根目錄。

注意
在下圖中,顯示BootstrapImpl類別。 本節未討論如何建立BootstrapImpl類別。

下圖顯示封裝至邀請外部使用者處理常式的JAR檔案中的Java專案內容。

邀請使用者

A.元件B所需的外部JAR檔案。 JAVA檔案

將邀請外部使用者處理常式封裝到JAR檔案中。 在上圖中,請注意已列出.JAVA檔案。 封裝成JAR檔案後,也必須指定對應的.CLASS檔案。 如果沒有.CLASS檔案,授權處理常式將無法運作。

注意
將外部授權處理常式封裝成JAR檔案後,您就可以將元件部署到AEM Forms。 一次只能部署一個邀請外部使用者處理常式。
注意
您也可以以程式設計方式部署元件。

測試邀請外部使用者處理常式

若要測試邀請外部使用者處理常式,您可以使用管理控制檯來新增要邀請的外部使用者。

若要使用管理主控台新增要邀請的外部使用者:

  1. 使用Workbench部署邀請外部使用者處理常式的JAR檔案。

  2. 重新啟動應用程式伺服器。

    注意
    建議您使用'Ctrl + C'命令重新啟動SDK。 使用替代方法重新啟動AEM SDK (例如停止Java程式),可能會導致AEM開發環境不一致。
  3. 登入管理主控台。

  4. 按一下​服務 > Rights Management > 組態 >已邀請​使用者註冊。

  5. 勾選​ 啟用受邀使用者註冊 ​方塊,以啟用受邀使用者註冊。 在​ 使用內建註冊系統 ​下,按一下​否。 儲存您的設定。

  6. 從管理主控台首頁,按一下​設定 > 使用者管理 > 網域管理。

  7. 按一下​新增本機網域。 在下列頁面中,建立名稱與識別碼值為EDC_EXTERNAL_REGISTERED的網域。 儲存您的變更。

  8. 從管理主控台首頁,按一下​服務 > Rights Management > 受邀和本機使用者。 出現「新增受邀使用者」頁面。

  9. 輸入電子郵件地址(由於目前的邀請外部使用者處理常式並不會實際傳送電子郵件訊息,因此電子郵件地址不一定有效)。 按一下​「確定」。 使用者受邀加入系統。

  10. 從管理主控台首頁,按一下​設定 > 使用者管理 > 使用者和群組。

  11. 在​ 尋找 ​欄位中,輸入您指定的電子郵件地址。 按一下​尋找。 您邀請的使用者會顯示為本機EDC_EXTERNAL_REGISTERED網域中的使用者。

注意
如果停止或解除安裝元件,邀請外部使用者處理常式會失敗。
自動翻譯
使用「語言選取器」檢視此頁面的英文版。
翻譯是否有幫助?

Ask AI

Not sure where to start?
Ask me anything about Adobe products.

Type your question or pick a suggestion below.

Use of this AI chatbot is subject to Adobe's Privacy Policy. Don't share sensitive data. AI responses are not your Content, may be inaccurate, and any offers provided are non-binding. Generative AI Terms.