外部角色映射

Edge for Private Cloud v. 4.17.05

借助外部角色映射,您可以将自己的群组或角色映射到在 Apigee Edge 上创建的基于角色的访问权限控制 (RBAC) 角色和群组。

前提条件

  • 您必须是拥有全局系统管理员凭据的 Apigee Private Cloud 系统管理员才能执行此配置。
  • 您需要知道 Apigee Edge Private Cloud 安装的根目录。默认根目录为 /opt。如果您在 Apigee Edge Private Cloud 安装期间选择了其他根目录,请在按照这些说明操作时使用该目录,而不是 /opt。
  • 从 Apigee 获取所需的 JAR 文件。

确保在 Edge 和目录服务中注册用户

使用角色映射时,所有访问 Edge 的用户都必须同时存在于您的外部目录服务和 Edge 用户代码库中。这意味着,当您向外部目录服务添加用户时,您还必须将该用户添加到 Apigee 用户存储库中。

例如,外部目录群组 'apiadmin' 中存在用户 a01@company.com。然后,您希望将用户 a01@company.com 映射到 Edge 中的组织管理员角色。因此,必须先将用户 a01@company.com 添加到 Edge 上的 orgadmin 群组。

如需详细了解如何创建 Edge 用户并为其分配角色,请参阅创建全局用户

默认配置

外部角色映射默认处于停用状态。

启用外部角色映射

  1. 您必须先创建一个实现 ExternalRoleMapperService 接口的 Java 类,然后才能完成以下配置。如需详细了解此实现,请参阅以下示例实现。
  2. 登录您的 Apigee Edge Management Server,然后停止管理服务器:
    > /opt/apigee/apigee-service/bin/apigee-serviceedge-management-server stop
  3. 检查服务器的状态。请确保管理服务器已停止/未运行:
    > /opt/apigee/apigee-service/bin/apigee-all 状态
  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. 启动管理服务器:
    > /opt/apigee/apigee-service/bin/apigee-serviceedge-management-server start
  8. 验证服务器是否正在运行:
    > /opt/apigee/apigee-service/bin/apigee-all 状态

停用外部授权

如需停用外部授权,请执行以下操作:

  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. 重启管理服务器:
    > /opt/apigee/apigee-service/bin/apigee-serviceedge-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);

        }

    }

}