外部ロール マッピング

Edge for Private Cloud バージョン 4.17.05

外部のロール マッピングを使用すると、独自のグループまたはロールを、Apigee Edge で作成されたロールベースのアクセス制御(RBAC)のロールとグループにマッピングできます。

前提条件

  • この構成を行うには、グローバル システム管理者認証情報を持つ Apigee Private Cloud システム管理者である必要があります。
  • Apigee Edge Private Cloud インストール環境のルート ディレクトリを把握している必要があります。デフォルトのルート ディレクトリは /opt です。Apigee Edge Private Cloud のインストール時に別のルート ディレクトリを選択した場合は、以下の手順に従い、/opt の代わりにそのルート ディレクトリを使用してください。
  • 必要な JAR ファイルを Apigee から取得します。

ユーザーが Edge とディレクトリ サービスに登録されていることを確認する

ロール マッピングを使用する場合、Edge にアクセスするすべてのユーザーが、外部ディレクトリ サービスと Edge ユーザー リポジトリの両方に存在する必要があります。つまり、外部ディレクトリ サービスにユーザーを追加するときには、同じユーザーを Apigee ユーザー リポジトリにも追加する必要があります。

たとえば、ユーザー a01@company.com が外部ディレクトリ グループ apiadmin に存在するとします。次に、ユーザー a01@company.com を Edge の orgadmin ロールにマッピングするとします。このため、最初にユーザー a01@company.com を Edge の orgadmin グループに追加する必要があります。

Edge ユーザーを作成してロールに割り当てる方法については、グローバル ユーザーの作成をご覧ください。

デフォルト構成

外部のロール マッピングはデフォルトで無効になっています。

外部ロール マッピングの有効化

  1. 次の構成を行う前に、ExternalRoleMapperService インターフェースを実装する Java クラスを作成する必要があります。この実装の詳細については、次の実装例をご覧ください。
  2. Apigee Edge Management Server にログインして、Management Server を停止します。
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-serverstop
  3. サーバーのステータスを確認します。Management Server が停止しているか、実行されていないことを確認します。
    > /opt/apigee/apigee-service/bin/apigee-all status
  4. テキスト エディタで /opt/apigee/customer/application/management-server.properties を開きます。
  5. management-server.properties ファイルを編集して、以下の設定を行います。
    conf_security_authentication.user.store=externalized.authentication
    conf_security_externalized.authentication.role.mapper.enabled=true
    conf_security_externalized.authentication.role.mapper.implementation.class=com.customer.authorization.impl.ExternalRoleMapperImpl
    クラスは、上記のパッケージのみです。このパッケージの名前は、--

    このクラスの実装の詳細については、以下の実装例をご覧ください。
  6. management-server.properties ファイルを保存します。
  7. Management Server を起動します。
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-server start
  8. サーバーが実行中であることを確認します。
    > /opt/apigee/apigee-service/bin/apigee-all status

外部承認の無効化

外部認証を無効にするには:

  1. テキスト エディタで /opt/apigee/customer/application/management-server.properties を開きます。
  2. 認証ユーザーストアを ldap に変更します。
    conf_security_authentication.user.store=ldap
  3. 次のプロパティを false に設定します。
    conf_security_externalized.authentication.role.mapper.enabled=false
  4. Management Server を再起動します。
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-server restart

ExternalRoleMapperImpl サンプル実装について

上記の management-server.properties 構成ファイルにある次の行に注目してください。

conf_security_externalized.authentication.role.mapper.implementation.class=com.customer.authorization.impl.ExternalRoleMapperImpl

このクラスは ExternalRoleMapperService インターフェースを実装しており、必須です。それぞれのグループを反映した、このクラスの独自の実装を作成する必要があります。完了したら、コンパイルしたクラスを JAR に配置し、その JAR を /<install_dir>/apigee/edge-gateway/lib/infra/libraries に配置します。

ExternalRoleMapperService が実装され、クラスパスでアクセスでき、management-server.properties 構成ファイルで正しく参照されているクラスであれば、自由にクラス名とパッケージを設定できます。

以下は、適切にコメントされた ExternalRoleMapperImpl クラスのサンプル実装です。このクラスをコンパイルするには、Edge に含まれる次の JAR ファイルを参照する必要があります。

/<install_dir>/apigee/edge-gateway/lib/infra/libraries/authentication-1.0.0.jar 
package com.apigee.authenticate;

import com.apigee.authentication.ConfigBean;
import com.apigee.authentication.ConnectionException;
import com.apigee.authentication.ExternalRoleMapperService;
import com.apigee.authentication.NameSpace;
import com.apigee.authentication.NameSpacedRole;
import com.apigee.authorization.namespace.OrganizationNamespace;
import com.apigee.authorization.namespace.SystemNamespace;
import java.util.Collection;
import java.util.HashSet;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

/** * 
 * Sample Implementation constructed with dummy roles with required namespaces.
 * 
 * Created by GopiAlagar on 6/12/15.
 */

public class ExternalRoleMapperImpl implements ExternalRoleMapperService {

    InitialDirContext dirContext = null;

    @Override
    public void stop() throws Exception {
    }

    /**
    * 
    * This method would be implemented by the customer, Below is the basic
    * example. 
    * 
    * If User has sysadmin role then it's expected to set SystemNameSpace 
    * along with the
    * res\quested NameSpace. Otherwise role's requestedNameSpace to be set 
    * for the NameSpacedRole.
    * 
    * Collection<NameSpacedRole> results = new HashSet<NameSpacedRole>();
    * 
    * NameSpacedRole sysNameSpace = new NameSpacedRole("sysadmin",
    * SystemNamespace.get());
    * 
    * String orgName =
    * ((OrganizationNamespace)requestedNameSpace).getOrganization();
    * 
    * NameSpacedRole orgNameSpace = new NameSpacedRole ("orgadmin",
    * requestedNameSpace);
    * 
    * results.add(sysNameSpace);
    * 
    * results.add(orgNameSpace);
    */

public Collection<NameSpacedRole> getUserRoles(String userName,
    String password, NameSpace requestedNameSpace) {

    /*
    * There are 3 actions performed in the below implementation
    * 1. Authenticate Given User against ADS
    * 2. Fetch the internal groups from the ADS
    * 3. Map the internal group into the apigee-edge roles
    */

    /*************************************************************/
    /******************* Authenticate Given User *******************/
    /*************************************************************/

    // Customer Specific Implementation will override this method
    // implementation.

    // Obtain dnName for given username or email address.
    String dnName = ImplementDnameLookupLogic();

    if (dnName == null) {
        System.out.println("Error ");
    }

    DirContext dirContext = null;

    Collection<NameSpacedRole> results = new HashSet<NameSpacedRole>();

    try {

        // Verify the credentials for a given username or dnName 
        // and password in order to create a directory context.
        dirContext = ImplementDirectoryContextCreationLogic();

        /****************************************************/
        /********** Fetch internal groups *******************/
        /****************************************************/

        String groupDN = "OU=Groups,DC=corp,DC=wacapps,DC=net";
        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        NamingEnumeration<SearchResult> groups = dirContext.search(groupDN,"(objectClass=*)", new Object[] { "", "" }, controls);

        if (groups.hasMoreElements()) {
            while (groups.hasMoreElements()) {
                SearchResult searchResult = groups.nextElement();
                Attributes attributes = searchResult.getAttributes();
                String groupName = attributes.get("name").get().toString();

                 /**************************************/
                 /** Map the internal group into the ***/
                 /** apigee-edge roles               ***/
                 /**************************************/

                if (groupName.equals("BusDev")) {
                    results.add(new NameSpacedRole("businessAdmin",SystemNamespace.get()));

                } else if (groupName.equals("DevSupport")) {
                    results.add(new NameSpacedRole("devOpsAdmin",SystemNamespace.get()));

                } else if (groupName.equals("Engineering")) {
                    if (requestedNameSpace instanceof OrganizationNamespace) {
                        String orgName = ((OrganizationNamespace) requestedNameSpace).getOrganization();
                        results.add(new NameSpacedRole("orgadmin", new OrganizationNamespace(orgName)));
                    }

                } else if (groupName.equals("Operations") || groupName.equals("IT")) {
                    results.add(new NameSpacedRole("sysadmin",SystemNamespace.get()));

                } else if (groupName.equals("Marketing")) {
                    results.add(new NameSpacedRole("marketAdmin",SystemNamespace.get()));

                } else {
                    results.add(new NameSpacedRole("readOnly",SystemNamespace.get()));
                }
            }

        } else {

            /** 
            * In case of no group found or exception found we throw empty
            * roles.
            */
            System.out.println(" !!!!! NO  GROUPS FOUND !!!!!");
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        System.out.println("Error in authenticating User: {}" + new Object[] { userName });

    } finally {
        // Customer implementation to close 
        // ActiveDirectory/LDAP context.
    }

    return results;

}

@Override
public void start(ConfigBean arg0) throws ConnectionException {

    try {
        // Create InitialDirContext.
        // Create a directory context based on the 
        // system admin user credentials.
        dirContext = ImplementDirContextCreationLogicForSysAdmin();

        } catch (NamingException e) {
            // TODO Auto-generated catch block

            throw new ConnectionException(e);

        }

    }

}