Ánh xạ vai trò bên ngoài

Edge for Private Cloud phiên bản 4.17.05

Liên kết vai trò bên ngoài cho phép bạn liên kết nhóm hoặc vai trò của riêng bạn với các vai trò và nhóm kiểm soát quyền truy cập dựa trên vai trò (RBAC) được tạo trên Apigee Edge. 

Điều kiện tiên quyết

  • Bạn phải là quản trị viên hệ thống Đám mây riêng tư Apigee và có thông tin đăng nhập của quản trị viên hệ thống toàn cầu thì mới có thể định cấu hình này. 
  • Bạn cần biết thư mục gốc của quá trình cài đặt đám mây riêng tư Apigee Edge. Thư mục gốc mặc định là /opt. Nếu bạn chọn một thư mục gốc khác trong quá trình cài đặt Đám mây riêng tư Apigee Edge, hãy sử dụng thư mục đó thay vì /opt khi bạn làm theo hướng dẫn này.
  • Lấy các tệp JAR cần thiết từ Apigee.

Đảm bảo rằng người dùng được đăng ký trên Edge và trong dịch vụ thư mục của bạn

Khi sử dụng tính năng ánh xạ vai trò, tất cả người dùng truy cập vào Edge phải có trong cả dịch vụ thư mục bên ngoài và kho lưu trữ người dùng của Edge. Tức là khi thêm một người dùng vào dịch vụ thư mục bên ngoài, bạn cũng phải thêm người dùng đó vào kho lưu trữ người dùng Apigee.

Ví dụ: người dùng a01@company.com tồn tại trong nhóm thư mục bên ngoài 'apiadmin'. Sau đó, bạn nên liên kết người dùng a01@company.com với vai trò orgadmin trong Edge. Do đó, trước tiên, bạn phải thêm người dùng a01@company.com vào nhóm orgadmin trên Edge. 

Hãy xem bài viết Tạo người dùng toàn cầu để biết thêm thông tin về cách tạo người dùng Edge và chỉ định người dùng vào vai trò.

Cấu hình mặc định

Tính năng ánh xạ vai trò bên ngoài bị tắt theo mặc định.

Bật liên kết vai trò bên ngoài

  1. Trước khi có thể hoàn tất cấu hình sau, bạn phải tạo một lớp Java triển khai giao diện ExternalRoleMapperService. Để biết chi tiết về cách triển khai này, hãy xem cách triển khai mẫu bên dưới.
  2. Đăng nhập vào Máy chủ quản lý Apigee Edge rồi dừng Máy chủ quản lý:
    > /opt/apigee/apigee-service/bin/apigee-service Edge-management-server dừng
  3. Kiểm tra trạng thái của máy chủ. Đảm bảo Máy chủ quản lý đã dừng/không chạy:
    > /opt/apigee/apigee-service/bin/apigee-all status
  4. Mở /opt/apigee/customer/application/management-server.properties trong trình chỉnh sửa văn bản.
  5. Chỉnh sửa tệp management-server.properties bằng các chế độ cài đặt sau:
    conf_security_Transaction.user.store=externalized.auth.
    conf_security_externalized. dắt.



    Để biết thông tin chi tiết về cách triển khai lớp này, hãy xem quy trình triển khai mẫu bên dưới. 
  6. Lưu tệp management-server.properties.
  7. Khởi động Máy chủ quản lý:
    > /opt/apigee/apigee-service/bin/apigee-service Edge-management-server start
  8. Xác minh rằng máy chủ đang chạy:
    > /opt/apigee/apigee-service/bin/apigee-all status

Tắt tính năng uỷ quyền bên ngoài

Cách tắt tính năng uỷ quyền bên ngoài:

  1. Mở /opt/apigee/customer/application/management-server.properties trong trình chỉnh sửa văn bản.
  2. Thay đổi kho lưu trữ người dùng xác thực thành ldap:
    conf_security_ dắt.user.store=ldap
  3. Đặt thuộc tính sau thành false:
    conf_security_externalized.authentication.role.mapper.enabled=false
  4. Khởi động lại Máy chủ quản lý:
    > /opt/apigee/apigee-service/bin/apigee-service Edge-management-server khởi động lại

Giới thiệu về việc triển khai mẫu ExternalRoleMapperImpl

Trong tệp cấu hình management-server.properties mô tả ở trên, hãy lưu ý dòng sau:

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

Lớp này bắt buộc triển khai giao diện ExternalRoleMapperService. Bạn cần tạo cách triển khai lớp này của riêng mình sao cho phù hợp với các nhóm tương ứng của bạn. Khi hoàn tất, hãy đặt lớp đã biên dịch vào tệp JAR rồi đặt tệp JAR đó vào /<install_dir>/apigee/edge-gateway/lib/infra/libraries

Bạn có thể đặt tên cho lớp và đóng gói theo bất cứ cách nào bạn muốn, miễn là lớp này triển khai ExternalRoleMapperService, có thể truy cập được trong classpath và được tham chiếu chính xác trong tệp cấu hình management-server.properties

Dưới đây là cách triển khai mẫu của một lớp ExternalRoleMapperImpl được nhận xét chi tiết. Để biên dịch lớp này, bạn phải tham chiếu tệp JAR sau đây đi kèm với Edge:

/<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);

        }

    }

}