מיפוי תפקידים חיצוני

Edge for Private Cloud גרסה 4.17.05

מיפוי תפקידים חיצוני מאפשר לכם למפות את הקבוצות או התפקידים שלכם לתפקידים ולקבוצות של בקרת גישה מבוססת-תפקיד (RBAC) שנוצרו ב-Apigee Edge. 

דרישות מוקדמות

  • כדי לבצע את ההגדרה הזו, אתם צריכים להיות אדמינים של ענן פרטי של Apigee עם פרטי כניסה של אדמין גלובלי. 
  • צריך לדעת מהי ספריית הבסיס של התקנת הענן הפרטי של Apigee Edge. ספריית הבסיס שמוגדרת כברירת מחדל היא /opt. אם בחרת ספריית בסיס אחרת במהלך התקנת הענן הפרטי של Apigee Edge, יש להשתמש בה במקום /opt ולפעול לפי ההוראות האלה.
  • מורידים את קובצי ה-JAR הנדרשים מ-Apigee.

בדיקה שהמשתמשים רשומים ב-Edge ובשירות הספריות שלך

כשמשתמשים במיפוי תפקידים, כל המשתמשים שיש להם גישה ל-Edge חייבים להימצא בשירות הספריות החיצוני ובמאגר המשתמשים של Edge. כלומר, כשמוסיפים משתמש לשירות הספריות החיצוני, צריך להוסיף את אותו המשתמש גם למאגר המשתמשים ב-Apigee.

לדוגמה, המשתמש a01@company.com קיים בקבוצת הספריות החיצוניות 'apiadmin'. אז כדאי למפות את המשתמש a01@company.com לתפקיד orgadmin ב-Edge. לכן, צריך קודם להוסיף את המשתמש a01@company.com לקבוצה orgadmin ב-Edge. 

למידע נוסף על יצירת משתמשי 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.distribution.class=com.customer.authorization.impl.ExternalRoleMapperImpl
    ל-{namename}{!ExternalRoleMapperImpl

    לפרטים על הטמעת הכיתה הזו, ניתן לעיין בהטמעה לדוגמה שבהמשך. 
  6. שומרים את הקובץ management-server.properties.
  7. מפעילים את Management Server:
    > /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 הפעלה מחדש

מידע על ההטמעה לדוגמה של 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, עם תגובות טובות. כדי להדר את המחלקה הזו, צריך להפנות לקובץ ה-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);

        }

    }

}