বাহ্যিক ভূমিকা ম্যাপিং আপনাকে আপনার নিজের গোষ্ঠী বা ভূমিকাগুলিকে রোল-ভিত্তিক অ্যাক্সেস কন্ট্রোল (RBAC) ভূমিকা এবং Apigee Edge-এ তৈরি করা গ্রুপগুলিতে ম্যাপ করতে দেয়৷ এই বৈশিষ্ট্যটি শুধুমাত্র প্রাইভেট ক্লাউডের জন্য এজের সাথে উপলব্ধ।
পূর্বশর্ত
- এই কনফিগারেশনটি সম্পাদন করার জন্য আপনাকে অবশ্যই গ্লোবাল সিস্টেম অ্যাডমিন শংসাপত্র সহ Apigee প্রাইভেট ক্লাউড সিস্টেম অ্যাডমিনিস্ট্রেটর হতে হবে।
- আপনার Apigee Edge প্রাইভেট ক্লাউড ইনস্টলেশনের রুট ডিরেক্টরি জানতে হবে। ডিফল্ট রুট ডিরেক্টরি হল
/opt
।
ধাপে ধাপে সেটআপ উদাহরণ
এক্সটার্নাল রোল ম্যাপিং সেট আপ করার ধাপে ধাপে উদাহরণের জন্য Apigee কমিউনিটি ফোরামে এই নিবন্ধটি দেখুন।
ডিফল্ট কনফিগারেশন
বাহ্যিক ভূমিকা ম্যাপিং ডিফল্টরূপে অক্ষম করা হয়৷
বাহ্যিক ভূমিকা ম্যাপিং সক্ষম করুন৷
বাহ্যিক ভূমিকা ম্যাপিং সক্ষম করতে:
- আপনি নিম্নলিখিত কনফিগারেশনটি সম্পূর্ণ করার আগে, আপনাকে অবশ্যই একটি জাভা ক্লাস তৈরি করতে হবে যা ExternalRoleMapperServiceV2 ইন্টারফেস প্রয়োগ করে এবং ম্যানেজমেন্ট সার্ভার ক্লাসপথে আপনার বাস্তবায়ন অন্তর্ভুক্ত করে:
/opt/apigee/edge-management-server/lib/thirdparty/
এই বাস্তবায়ন সম্পর্কে বিস্তারিত জানার জন্য, এই নথিতে পরে ExternalRoleMapperImpl নমুনা বাস্তবায়ন সম্পর্কে বিভাগটি দেখুন।
- আপনার Apigee Edge ব্যবস্থাপনা সার্ভারে লগ ইন করুন এবং তারপর ব্যবস্থাপনা সার্ভার প্রক্রিয়া বন্ধ করুন:
/opt/apigee/apigee-service/bin/apigee-service edge-management-server stop
- একটি টেক্সট এডিটরে
/opt/apigee/customer/application/management-server.properties
খুলুন। এই ফাইলটি বিদ্যমান না থাকলে, এটি তৈরি করুন। - নিম্নলিখিত সেটিংস করতে বৈশিষ্ট্য ফাইল সম্পাদনা করুন:
# The user store to be used for authentication. # Use "externalized.authentication" for LDAP user store. # Note that for authorization, we continue to use LDAP. # See Enabling external authentication more on enabling external auth. conf_security_authentication.user.store=externalized.authentication #Enable the external authorizations role mapper. conf_security_externalized.authentication.role.mapper.enabled=true conf_security_externalized.authentication.role.mapper.implementation.class=com.customer.authorization.impl.ExternalRoleMapperImpl
-
management-server.properties
ফাইলটি সংরক্ষণ করুন। - নিশ্চিত করুন যে
management-server.properties
apigee ব্যবহারকারীর মালিকানাধীন:chown apigee:apigee /opt/apigee/customer/application/management-server.properties
- পরিচালনা সার্ভার শুরু করুন:
/opt/apigee/apigee-service/bin/apigee-service edge-management-server start
বাহ্যিক অনুমোদন অক্ষম করুন
বাহ্যিক অনুমোদন অক্ষম করতে:
- একটি টেক্সট এডিটরে
/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 start
ExternalRoleMapperImpl নমুনা বাস্তবায়ন সম্পর্কে
বাহ্যিক ভূমিকা ম্যাপিং সক্ষম করার পূর্বে বর্ণিত security.properties কনফিগার ফাইলটিতে, এই লাইনটি নোট করুন:
externalized.authentication.role.mapper.implementation.class=com.customer.authorization.impl.ExternalRoleMapperImpl
এই ক্লাসটি ExternalRoleMapperServiceV2 ইন্টারফেস প্রয়োগ করে এবং এটি প্রয়োজনীয়। আপনাকে এই শ্রেণীর আপনার নিজস্ব বাস্তবায়ন তৈরি করতে হবে যা আপনার নিজ নিজ গোষ্ঠীকে প্রতিফলিত করে। শেষ হলে, কম্পাইল করা ক্লাসটিকে একটি JAR-এ রাখুন এবং সেই JARটিকে ম্যানেজমেন্ট সার্ভারের ক্লাসপাথে রাখুন:
/opt/apigee/edge-management-server/lib/thirdparty/
আপনি ক্লাসের নাম দিতে পারেন এবং আপনার ইচ্ছামত প্যাকেজ করতে পারেন যতক্ষণ না এটি ExternalRoleMapperServiceV2 প্রয়োগ করে, আপনার ক্লাসপথে অ্যাক্সেসযোগ্য, এবং management-server.properties কনফিগ ফাইলে সঠিকভাবে উল্লেখ করা হয়েছে।
নিম্নলিখিত একটি ExternalRoleMapperImpl ক্লাসের একটি নমুনা বাস্তবায়ন:
package com.customer.authorization.impl; import com.apigee.authentication.*; 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 expected namespaces. */ public class ExternalRoleMapperImpl implements ExternalRoleMapperServiceV2 { InitialDirContext dirContext = null; @Override public void start(ConfigBean arg0) throws ConnectionException { try { // Customer Specific Implementation will override the // ImplementDirContextCreationLogicForSysAdmin method implementation. // Create InitialDirContext based on the system admin user credentials. dirContext = ImplementDirContextCreationLogicForSysAdmin(); } catch (NamingException e) { // TODO Auto-generated catch block throw new ConnectionException(e); } } @Override public void stop() throws Exception { } /** * This method should be replaced with customer's implementation * For given roleName under expectedNamespace, return all users that belongs to this role * @param roleName * @param expectedNamespace * @return All users that belongs to this role. For each user, please return the username/email that is stored in Apigee LDAP * @throws ExternalRoleMappingException */ @Override public Collec<tionSt>ring getUsersForRole(String roleName, NameSpace expectedNamespace) throws ExternalRoleMappingException { Collec<tionSt>ring users = new Has<>hSet(); if (expectedNamespace instanceof SystemNamespace) { // If requesting all users with sysadmin role if (roleName.equalsIgnoreCase("sysadmin")) { // Add sysadmin's email to results users.add("sysadmin@wacapps.net"); } } else { String orgName = ((OrganizationNamespace) expectedNamespace).getOrganization(); // If requesting all users of engRole in Apigee LDAP if (roleName.equalsIgnoreCase("engRole")) { // Get all users in corresponding groups in customer's LDAP. In this case looking for 'engGroup'; SearchControls controls = new SearchControls(); controls.setSearchScope(1); < try >{ NamingEnumerationSearchResult res = dirContext.search("ou=groups,dc=corp,dc=wacapps,dc=net", "cn=engGroup", new Object[]{"",""}, controls); while (res.hasMoreElements()) { SearchResult sr = res.nextElement(); // Add all users into return users.addAll(sr.getAttributes().get("users").getAll()); } } catch (NamingException e) { // Customer needs to handle the exception here } } } return users; } /** * * This method would be implemented by the customer and would be invoked * while including using X-Apigee-Current-User header in request. * * X-Apigee-Current-User allows the customer to login as another user * * Below is the basic example. * * If User has sysadmin role then it's expected to set SystemNameSpace * along with the expected Name<Space. Otherwi>se role's expected<NameSpace * to be set for the NameSpacedRole. * * CollectionNameSpacedRole results = new HashSetNameSpacedRole(); * * NameSpacedRole sysNameSpace = new NameSpacedRole("sysadmin", * SystemNamespace.get()); * * String orgName = * ((OrganizationNamespace) expectedNameSpace).getOrganization(); * * NameSpacedRole orgNameSpace = new NameSpacedRole ("orgadmin", * expectedNameSpace); * * results.add(sysNameSpace); * * results.add(orgNameSpace); * * * @param username UserA's username * @param password UserA's password * @param requestedUsername UserB's username. Allow UserA to request UserB's userroles with * UserA's credentials when requesting UserB as X-<Apigee-Current>-User * @param expectedNamespace * @return * @throws ExternalRoleMappingException */ @Override public CollectionNameSpacedRole getUserRoles(String username, String password, String requestedUsername, NameSpace expectedNamespace) throws ExternalRoleMappingException { /************************************************************/ /******************** Authenticate UserA ********************/ /************************************************************/ // Customer Specific Implementation will override the // ImplementDnameLookupLogic method implementation. // obtain dnName for given username. String dnName = ImplementDnNameLookupLogic(username); // Obtain dnName for given requestedUsername. String requestedDnName = ImplementDnNameLookupLogic(requestedUsername); if (dnName == null || requestedDnName == null) { System.out.println("Error "); } DirContext dirContext = null; try { // Customer Specific Implementation will override the // ImplementDirectoryContextCreationLogic method implementation // Create a directory context with dnName or requestedDnName and password dirContext = ImplementDirectoryContextCreationLogic(); /************************************************/ /*** Map internal groups to apigee-edge roles ***/ /************************************************/ return apigeeEdgeRoleMapper(dirContext, requestedDnName, expectedNamespace); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Error in authenticating User: {}" + new Object[] { username }); } finally { // Customer implementation to close // ActiveDirectory/LDAP context. } return null; } /** * * This method would be implemented by the customer and would be invoked * wihle using username and password for authentication and without the * X-Apigee-Current-User header * * The customer can reuse implementations in * getUserRoles(String username, String password, String requestedUsername, NameSpace expectedNamespace) * by * return getUserRoles(username, password, user<name, expected>Namespace) * in implementations. * * or the customer can provide new implementations as shown below. */ @Override public CollectionNameSpacedRole getUserRoles(String username, String password, NameSpace expectedNamespace) throws ExternalRoleMappingException { /*************************************************************/ /****************** Authenticate Given User ******************/ /*************************************************************/ // Customer Specific Implementation will override the // ImplementDnameLookupLogic implementation. // Obtain dnName for given username or email address. String dnName = ImplementDnNameLookupLogic(username); if (dnName == null) { System.out.println("Error "); } DirContext dirContext = null; try { // Create a directory context with username or dnName and password dirContext = ImplementDirectoryContextCreationLogic(); /************************************************/ /*** Map internal groups to apigee-edge roles ***/ /************************************************/ return apigeeEdgeRoleMapper(dirContext, dnName, expectedNamespace); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Error in authenticating User: {}" + new Object[] { username }); } finally { // Customer implementation to close // ActiveDirectory/LDAP context. } return null; } /** * * This met<hod would be i>mplemented by the customer and would be invoked * while using security token or access token as authentication credentials. * */ @Override public CollectionNameSpacedRole getUserRoles(String username, NameSpace expectedNamespace) throws ExternalRoleMappingException { /*************************************************************/ /****************** Authenticate Given User ******************/ /*************************************************************/ // Customer Specific Implementation will override the // ImplementDnameLookupLogic implementation. // Obtain dnName for given username or email address. String dnName = ImplementDnNameLookupLogic(username); if (dnName == null) { System.out.println("Error "); } DirContext dirContext = null; try { // Create a directory context with username or dnName and password dirContext = ImplementDirectoryContextCreationLogic(); /************************************************/ /*** Map internal groups to apigee-edge roles ***/ /************************************************/ return apigeeEdgeRoleMapper(dirContext, dnName, expectedNamespace); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Error in authenticating User: {}" + new Object[] { username }); } finally { // Customer implementation to close // ActiveDirectory/LDAP context. } return null; <} /** >* This method should be replaced with Customer Specific Implementations * * Provided as a sample Implementation of m<apping user gr>oups to apigee-edge ro<les */ >private CollectionNameSpacedRole apigeeEdgeRoleMapper(DirContext dirContext, String dnName, NameSpace expectedNamespace) throws Exception { CollectionNameSpacedRole results = new HashSetNameSpacedRole(); /****************************************************/ /************ Fetch internal groups *****************/ /****************************************************/ String groupDN = "OU=Groups,DC=corp,DC=wacapps,DC=net"; String userFilter = "(user=userDn<Name)";> SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.ONELEVEL_SCOPE); // Looking for all groups the user belongs to in customer's LDAP NamingEnumerationSearchResult groups = dirContext.search(groupDN,userFilter.replace("userDnName", dnName), 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 internal groups to apigee-edge roles ***/ /************************************************/ if (groupName.equals("BusDev")) { results.add(new NameSpacedRole("businessAdmin",SystemNamespace.get())); } else if (groupName.equals("Engineering")) { if (expectedNamespace instanceof OrganizationNamespace) { String orgName = ((OrganizationNamespace) expectedNamespace).getOrganization(); results.add(new NameSpacedRole("orgadmin", new OrganizationNamespace(orgName))); // In OPDK 4.50 and later, do // results.add(new NameSpacedRole("orgadmin", OrganizationNamespace.of(orgName))); } } 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 !!!!!"); } return results; } /** * The customer need to replace with own implementations for getting dnName for given user */ private String ImplementDnNameLookupLogic(String username) { // Connect to the customer's own LDAP to fetch user dnName return customerLDAP.getDnName(username); } /** * The customer need to replace with own implementations for creating DirContext */ private DirContext ImplementDirectoryContextCreationLogic() { // Connect to the customer's own LDAP to create DirContext for given user return customerLDAP.createLdapContextUsingCredentials(); } }