การแมปบทบาทภายนอก

Edge สำหรับ Private Cloud เวอร์ชัน 4.17.05

การแมปบทบาทภายนอกช่วยให้คุณแมปกลุ่มหรือบทบาทของคุณเองกับบทบาทและการควบคุมการเข้าถึงตามบทบาท (RBAC) และกลุ่มที่สร้างใน Apigee Edge ได้

ข้อกำหนดเบื้องต้น

  • คุณต้องเป็นผู้ดูแลระบบ 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 กับบทบาท orgadmin ใน Edge ดังนั้นจึงต้องเพิ่มผู้ใช้ a01@company.com ลงในกลุ่ม orgadmin ใน Edge ก่อน

โปรดดูข้อมูลเพิ่มเติมเกี่ยวกับการสร้างผู้ใช้ Edge และการมอบหมายบทบาทได้ที่หัวข้อการสร้างผู้ใช้ส่วนกลาง

การกำหนดค่าเริ่มต้น

การแมปบทบาทภายนอกจะปิดใช้อยู่โดยค่าเริ่มต้น

การเปิดใช้การจับคู่บทบาทภายนอก

  1. ก่อนที่คุณจะกำหนดค่าต่อไปนี้ให้เสร็จสมบูรณ์ คุณต้องสร้างคลาส Java ที่ใช้งานอินเทอร์เฟซ ExternalRoleMapperService ดูรายละเอียดเกี่ยวกับการติดตั้งใช้งานนี้ได้โดยดูตัวอย่างการติดตั้งใช้งานด้านล่าง
  2. เข้าสู่ระบบ Apigee Edge Management Server แล้วหยุดเซิร์ฟเวอร์การจัดการโดยทำดังนี้
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-server start
  3. ตรวจสอบสถานะของเซิร์ฟเวอร์ โปรดตรวจสอบว่าเซิร์ฟเวอร์การจัดการหยุดทำงาน/ไม่ทํางาน ดังนี้
    > /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.ExternalRoleMapper that โปรดดูและชื่อแพ็กเกจ.


    โปรดดูรายละเอียดเกี่ยวกับการติดตั้งใช้งานคลาสนี้โดยดูตัวอย่างการใช้งานด้านล่าง
  6. บันทึกไฟล์ management-server.properties
  7. เริ่มต้นเซิร์ฟเวอร์การจัดการ:
    > /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. ตั้งค่าพร็อพเพอร์ตี้ต่อไปนี้เป็น "เท็จ"
    conf_security_externalized.authentication.role.mapper.enabled=false
  4. รีสตาร์ทเซิร์ฟเวอร์การจัดการโดยทำดังนี้
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-serverและวิธีรีสตาร์ท

เกี่ยวกับการติดตั้งใช้งานตัวอย่าง 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 ที่มีการแสดงความคิดเห็น ในการคอมไพล์คลาสนี้ คุณต้องอ้างอิงไฟล์ JAR ต่อไปนี้ที่รวมอยู่ใน 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);

        }

    }

}