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

Edge for Private Cloud phiên bản 4.17.05

Tính năng Ánh xạ vai trò bên ngoài cho phép bạn ánh xạ các nhóm hoặc vai trò của riêng mình với các vai trò và nhóm điều khiể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 Apigee Private Cloud có thông tin đăng nhập của quản trị viên hệ thống chung để thực hiện cấu hình này. 
  • Bạn cần biết thư mục gốc của bản cài đặt Apigee Edge Private Cloud. 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 Apigee Edge Private Cloud, hãy sử dụng thư mục đó thay vì /opt khi làm theo các hướng dẫn này.
  • Lấy các tệp JAR bắt buộc từ Apigee.

Đảm bảo người dùng đã đă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 liên kết vai trò, tất cả người dùng truy cập vào Edge phải tồn tại trong cả dịch vụ thư mục bên ngoài và trong kho lưu trữ người dùng Edge. Điều đó có nghĩa là khi thêm 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 muố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 chung để biết thêm thông tin về cách tạo người dùng Edge và chỉ định vai trò cho họ.

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

Tính năng liên kết vai trò bên ngoài bị tắt theo mặc định.

Bật tính năng 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 thông tin chi tiết về cách triển khai này, hãy xem ví dụ về cách triển khai 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 stop
  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_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


    Quan trọng: Lớp triển khai và tên gói được tham chiếu ở trên, ExternalRoleMapperImpl, chỉ là một ví dụ – đây là một lớp mà bạn phải triển khai và bạn có thể đặt tên cho lớp và gói theo ý muốn. Để biết thông tin chi tiết về cách triển khai lớp này, hãy xem ví dụ về cách triển khai 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_authentication.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 restart

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

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

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

Lớp này triển khai giao diện ExternalRoleMapperService và là lớp bắt buộc. Bạn cần tạo phương thức triển khai lớp này của riêng mình để phản ánh các nhóm tương ứng. Khi hoàn tất, hãy đặt lớp đã biên dịch vào một tệp JAR và đặ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à gói theo ý muốn, miễn là lớp và gói đó 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à ví dụ về cách triển khai lớp ExternalRoleMapperImpl có chú thích rõ ràng. Để biên dịch lớp này, bạn phải tham chiếu tệp JAR sau đây có trong 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);

        }

    }

}