外部ユーザー招待ハンドラー実装の定義

次の外部ユーザー招待ハンドラーの実装は、管理コンソールからアクセスできる招待ユーザーの追加ページから送信されるメールアドレスを受け付けます。

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 ファイルを定義します。コンポーネントの 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>