Edge for 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 และการมอบหมายบทบาทให้ผู้ใช้ได้ที่หัวข้อการสร้างผู้ใช้ส่วนกลาง
การกำหนดค่าเริ่มต้น
ระบบจะปิดใช้การจับคู่บทบาทภายนอกไว้โดยค่าเริ่มต้น
การเปิดใช้การจับคู่บทบาทภายนอก
- คุณต้องสร้างคลาส Java ที่ใช้เฟสอินเทอร์เฟส ExternalRoleMapperService ก่อนจึงจะกำหนดค่าต่อไปนี้ให้เสร็จสมบูรณ์ได้ ดูรายละเอียดเกี่ยวกับการติดตั้งใช้งานนี้ได้ในตัวอย่างการติดตั้งใช้งานด้านล่าง
- เข้าสู่ระบบเซิร์ฟเวอร์การจัดการ Apigee Edge แล้วหยุดเซิร์ฟเวอร์การจัดการ
> /opt/apigee/apigee-service/bin/apigee-service edge-management-server stop - ตรวจสอบสถานะของเซิร์ฟเวอร์ ตรวจสอบว่าเซิร์ฟเวอร์การจัดการหยุดทำงาน/ไม่ได้ทำงาน:
> /opt/apigee/apigee-service/bin/apigee-all status - เปิด /opt/apigee/customer/application/management-server.properties ในเครื่องมือแก้ไขข้อความ
- แก้ไขไฟล์ 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
สำคัญ: คลาสการติดตั้งใช้งานและชื่อแพ็กเกจที่อ้างอิงด้านบน ExternalRoleMapperImpl เป็นเพียงตัวอย่างเท่านั้น ซึ่งเป็นคลาสที่คุณต้องติดตั้งใช้งานและตั้งชื่อคลาสและแพ็กเกจตามต้องการ ดูรายละเอียดเกี่ยวกับการใช้คลาสนี้ได้ที่ตัวอย่างการใช้งานด้านล่าง - บันทึกไฟล์ management-server.properties
- เริ่มเซิร์ฟเวอร์การจัดการ:
> /opt/apigee/apigee-service/bin/apigee-service edge-management-server start - ตรวจสอบว่าเซิร์ฟเวอร์ทำงานอยู่:
> /opt/apigee/apigee-service/bin/apigee-all status
กำลังปิดใช้การให้สิทธิ์ภายนอก
วิธีปิดใช้การให้สิทธิ์ภายนอก
- เปิด /opt/apigee/customer/application/management-server.properties ในเครื่องมือแก้ไขข้อความ
- เปลี่ยนที่เก็บข้อมูลผู้ใช้สำหรับการตรวจสอบสิทธิ์เป็น ldap:
conf_security_authentication.user.store=ldap - ตั้งค่าพร็อพเพอร์ตี้ต่อไปนี้เป็นเท็จ
conf_security_externalized.authentication.role.mapper.enabled=false - รีสตาร์ทเซิร์ฟเวอร์การจัดการ:
> /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, เข้าถึงได้ใน classpath และมีการอ้างอิงอย่างถูกต้องในไฟล์การกำหนดค่า 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); } } }