Edge for Private Cloud 4.17.05 版
外部角色對應可讓您將自己的群組或角色,對應至在 Apigee Edge 建立的角色式存取控管 (RBAC) 角色和群組。
必要條件
- 您必須是 Apigee 私有雲系統管理員,並具備全域系統管理員憑證,才能執行這項設定。
- 您必須知道 Apigee Edge 私有雲安裝作業的根目錄。預設根目錄為 /opt。如果您在安裝 Apigee Edge 私有雲時選擇其他根目錄,請在按照這些操作說明操作時,使用該目錄而非 /opt。
- 從 Apigee 取得必要的 JAR 檔案。
確認使用者已在 Edge 和目錄服務中註冊
使用角色對應時,所有存取 Edge 的使用者都必須同時存在於外部目錄服務和 Edge 使用者存放區中。也就是說,當您將使用者新增至外部目錄服務時,也必須將該使用者新增至 Apigee 使用者存放區。
舉例來說,使用者 a01@company.com 位於外部目錄群組 apiadmin 中。接著,您想將使用者 a01@company.com 對應至 Edge 中的 orgadmin 角色。因此,使用者 a01@company.com 必須先加入 Edge 的 orgadmin 群組。
如要進一步瞭解如何建立 Edge 使用者並指派角色,請參閱「建立全域使用者」。
預設設定
外部角色對應功能預設為停用。
啟用外部角色對應
- 您必須先建立實作 ExternalRoleMapperService 介面的 Java 類別,才能完成下列設定。如要進一步瞭解這項實作,請參閱下方的實作範例。
- 登入 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 - 將下列屬性設為 false:
conf_security_externalized.authentication.role.mapper.enabled=false - 重新啟動 Management Server:
> /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、可在類別路徑中存取,且在 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); } } }