बाहरी भूमिका की मैपिंग

Edge for Private Cloud v. 4.17.05

एक्सटर्नल रोल मैपिंग की मदद से, अपने ग्रुप या भूमिकाओं को भूमिका के हिसाब से ऐक्सेस कंट्रोल (RBAC) रोल और Apigee Edge पर बनाए गए ग्रुप के साथ मैप किया जा सकता है. 

ज़रूरी शर्तें

  • इस कॉन्फ़िगरेशन को करने के लिए, आपको Apigee Private Cloud सिस्टम एडमिन होना चाहिए. साथ ही, आपके पास ग्लोबल सिस्टम एडमिन क्रेडेंशियल भी होने चाहिए.
  • आपको अपने Apigee Edge Private Cloud को इंस्टॉल करने की रूट डायरेक्ट्री के बारे में पता होना चाहिए. डिफ़ॉल्ट रूट डायरेक्ट्री /opt है. अगर आपने Apigee Edge Private Cloud को इंस्टॉल करने के दौरान, कोई दूसरी रूट डायरेक्ट्री चुनी है, तो इन निर्देशों का पालन करते समय /opt के बजाय उसका इस्तेमाल करें.
  • Apigee से ज़रूरी JAR फ़ाइलें पाएं.

पक्का करें कि उपयोगकर्ता Edge पर और आपकी डायरेक्ट्री सेवा में रजिस्टर हैं

रोल मैपिंग का इस्तेमाल करते समय, Edge को ऐक्सेस करने वाले सभी उपयोगकर्ता, आपकी बाहरी डायरेक्ट्री सेवा और Edge उपयोगकर्ता के रिपॉज़िटरी, दोनों में मौजूद होने चाहिए. इसका मतलब है कि जब किसी उपयोगकर्ता को बाहरी डायरेक्ट्री सेवा में जोड़ा जाता है, तो आपको उसी उपयोगकर्ता को Apigee यूज़र रिपॉज़िटरी में भी जोड़ना होगा.

उदाहरण के लिए, उपयोगकर्ता a01@company.com, आपके बाहरी डायरेक्ट्री ग्रुप 'apiadmin' में मौजूद है. इसके बाद, आपको उपयोगकर्ता a01@company.com को Edge में orgadmin की भूमिका से मैप करना है. इसलिए, उपयोगकर्ता a01@company.com को सबसे पहले, Edge पर orgadmin ग्रुप में जोड़ना ज़रूरी है. 

Edge उपयोगकर्ता बनाने और उन्हें भूमिकाएं असाइन करने के बारे में अधिक जानकारी के लिए वैश्विक उपयोगकर्ता बनाना देखें.

डिफ़ॉल्ट कॉन्फ़िगरेशन

बाहरी भूमिका की मैपिंग डिफ़ॉल्ट रूप से बंद होती है.

बाहरी भूमिका की मैपिंग चालू करना

  1. नीचे दिए गए कॉन्फ़िगरेशन को पूरा करने से पहले, आपको एक Java क्लास बनानी होगी, जो externalRoleMapperService इंटरफ़ेस को लागू करती है. इस प्रोसेस को लागू करने के बारे में जानने के लिए, नीचे दिया गया उदाहरण देखें.
  2. अपने Apigee Edge मैनेजमेंट सर्वर में लॉग इन करें और मैनेजमेंट सर्वर को बंद करें:
    > /opt/apigee/apigee-service/bin/apigee-serviceedge-management-server बंद
  3. सर्वर की स्थिति देखें. पक्का करें कि मैनेजमेंट सर्वर बंद हो या काम न कर रहा हो:
    > /opt/apigee/apigee-service/bin/apigee-all स्थिति
  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. स्ट्रीमानेशन.class=com.customer. Customer.Authorize.श्


    इस क्लास को लागू करने के बारे में जानकारी के लिए, नीचे दिया गया सैंपल देखें. 
  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 start

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);

        }

    }

}