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

Edge for Private Cloud v. 4.17.05

External Role Mapping की मदद से, अपने ग्रुप या भूमिकाओं को 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' में मौजूद है. इसके बाद, आपको Edge में उपयोगकर्ता a01@company.com को orgadmin भूमिका के लिए मैप करना है. इसलिए, उपयोगकर्ता a01@company.com को सबसे पहले Edge पर orgadmin ग्रुप में जोड़ना होगा. 

Edge उपयोगकर्ताओं को बनाने और उन्हें भूमिकाएं असाइन करने के बारे में ज़्यादा जानने के लिए, ग्लोबल उपयोगकर्ता बनाना लेख पढ़ें.

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

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

एक्सटर्नल रोल मैपिंग की सुविधा चालू करना

  1. यहां दिया गया कॉन्फ़िगरेशन पूरा करने से पहले, आपको एक Java क्लास बनानी होगी, जो ExternalRoleMapperService इंटरफ़ेस को लागू करती हो. इस सुविधा को लागू करने के बारे में ज़्यादा जानने के लिए, यहां दिया गया सैंपल देखें.
  2. अपने Apigee Edge मैनेजमेंट सर्वर में लॉग इन करें. इसके बाद, मैनेजमेंट सर्वर को बंद करें:
    > /opt/apigee/apigee-service/bin/apigee-service edge-management-server stop
  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.ExternalRoleMapperImpl


    अहम जानकारी: ऊपर रेफ़रंस के तौर पर दी गई क्लास और पैकेज का नाम, ExternalRoleMapperImpl, सिर्फ़ एक उदाहरण है -- यह एक ऐसी क्लास है जिसे आपको लागू करना होगा. साथ ही, क्लास और पैकेज को अपनी पसंद के मुताबिक नाम दिया जा सकता है. इस क्लास को लागू करने के बारे में ज़्यादा जानने के लिए, नीचे दिया गया सैंपल देखें. 
  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. इस प्रॉपर्टी को false पर सेट करें:
    conf_security_externalized.authentication.role.mapper.enabled=false
  4. मैनेजमेंट सर्वर को रीस्टार्ट करें:
    > /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);

        }

    }

}