Search in sources :

Example 16 with DelAdminMgr

use of org.apache.directory.fortress.core.DelAdminMgr in project directory-fortress-core by apache.

the class CreatePermOrgHierarchySample method testCreateDescendantPermOrgs.

/**
 * Demonstrate a parent to child OrgUnit structure of one-to-many.  The parent OrgUnit must be created before
 * the call to addDescendant which will Add a new OrgUnit node and set a OrgUnit relationship with parent node.
 * <p>
 * <img src="./doc-files/HierPermOrgDescendants.png" alt="">
 */
public static void testCreateDescendantPermOrgs() {
    String szLocation = ".testCreateDescendantPermOrgs";
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // Instantiate the parent Perm OrgUnit entity.  This needs a name and type before it can be added to ldap.
        OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_DESC_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
        // This parent will have many children:
        delAdminMgr.add(parentOrgUnit);
        // Create Perm OrgUnits, 'sampleHierPermD2' - 'sampleHierPermOrgD6'.
        for (int i = 1; i < TEST_NUMBER; i++) {
            // Now add relationship to the directory between parent and child Perm OrgUnits.
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_DESC_PERMORG_PREFIX + (i + 1), OrgUnit.Type.PERM);
            // Now add child OrgUnit entity to directory and add relationship with existing parent OrgUnit.
            delAdminMgr.addDescendant(parentOrgUnit, childOrgUnit);
        }
        LOG.info(szLocation + " success");
    } catch (SecurityException ex) {
        LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 17 with DelAdminMgr

use of org.apache.directory.fortress.core.DelAdminMgr in project directory-fortress-core by apache.

the class CreatePermOrgSample method testCreatePermOrg.

/**
 * Create a new Permission OrgUnit entity in LDAP.  The Permission OrgUnit entity must have the
 * OrgUnit name and the OrgUnit type set before being added.
 */
public static void testCreatePermOrg() {
    String szLocation = ".testCreatePermOrg";
    try {
        DelReviewMgr dRevAdminMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
        // The OrgUnit requires name and type to be set before use.
        OrgUnit inOU = new OrgUnit(TEST_PERM_OU_NM, OrgUnit.Type.PERM);
        try {
            dRevAdminMgr.read(inOU);
            // if org is found, return.
            return;
        } catch (FinderException fe) {
            assertTrue(szLocation + " excep id check", fe.getErrorId() == GlobalErrIds.ORG_NOT_FOUND_PERM);
        // pass
        }
        // Instantiate the Delegated AdminMgr implementation object which provisions OrgUnits and AdminRoles to the system.
        DelAdminMgr dAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // Add the OrgUnit to the directory.
        dAdminMgr.add(inOU);
        // Instantiate the Delegated RevewMgr implementation which interrogates the OrgUnit and AdminRole data.
        DelReviewMgr dReviewMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
        // Now read the OrgUnit back to make sure it got added OK.
        OrgUnit outOU = dReviewMgr.read(inOU);
        assertTrue(szLocation + " failed read", inOU.equals(outOU));
        LOG.info(szLocation + " [" + outOU.getName() + "] success");
    } catch (SecurityException ex) {
        LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) FinderException(org.apache.directory.fortress.core.FinderException) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) DelReviewMgr(org.apache.directory.fortress.core.DelReviewMgr)

Example 18 with DelAdminMgr

use of org.apache.directory.fortress.core.DelAdminMgr in project directory-fortress-core by apache.

the class DelegatedMgrImplTest method updateAdminRoles.

/**
 * @param msg
 * @param rArray
 */
public static void updateAdminRoles(String msg, String[][] rArray, boolean isAdmin) {
    LogUtil.logIt(msg);
    try {
        DelAdminMgr dAdminMgr;
        if (isAdmin) {
            dAdminMgr = getManagedDelegatedMgr();
        } else {
            dAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        }
        for (String[] rle : rArray) {
            AdminRole role = AdminRoleTestData.getRole(rle);
            AdminRole entity = dAdminMgr.updateRole(role);
            LOG.debug("updateAdminRoles role [" + entity.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("updateAdminRoles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminRole(org.apache.directory.fortress.core.model.AdminRole) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole)

Example 19 with DelAdminMgr

use of org.apache.directory.fortress.core.DelAdminMgr in project directory-fortress-core by apache.

the class DelegatedMgrImplTest method deleteOrgUnit.

/**
 * @param msg
 * @param org
 */
private void deleteOrgUnit(String msg, String[] org) {
    LogUtil.logIt(msg);
    try {
        DelAdminMgr dAdminMgr = getManagedDelegatedMgr();
        OrgUnit ou = OrgUnitTestData.getOrgUnit(org);
        dAdminMgr.delete(ou);
        LOG.debug("deleteOrgUnit ou [" + ou.getName() + "] successful");
    } catch (SecurityException ex) {
        LOG.error("deleteOrgUnit caught SecurityException=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 20 with DelAdminMgr

use of org.apache.directory.fortress.core.DelAdminMgr in project directory-fortress-core by apache.

the class DelegatedMgrImplTest method deassignAdminUserRole.

void deassignAdminUserRole(String msg, String[][] uArray, String[][] rArray, boolean isAdmin) {
    LogUtil.logIt(msg);
    try {
        DelAdminMgr dAdminMgr;
        if (isAdmin) {
            dAdminMgr = getManagedDelegatedMgr();
        } else {
            dAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        }
        int i = 0;
        for (String[] usr : uArray) {
            UserAdminRole uAdminRole = new UserAdminRole(UserTestData.getUserId(usr), AdminRoleTestData.getRole(rArray[i]).getName());
            dAdminMgr.deassignUser(uAdminRole);
            i++;
        }
    } catch (SecurityException ex) {
        LOG.error("deassignAdminUserRole caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Aggregations

DelAdminMgr (org.apache.directory.fortress.core.DelAdminMgr)39 SecurityException (org.apache.directory.fortress.core.SecurityException)39 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)26 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)13 DelReviewMgr (org.apache.directory.fortress.core.DelReviewMgr)9 AdminRole (org.apache.directory.fortress.core.model.AdminRole)9 HashSet (java.util.HashSet)4 FinderException (org.apache.directory.fortress.core.FinderException)3 ArrayList (java.util.ArrayList)2 User (org.apache.directory.fortress.core.model.User)2 Role (org.apache.directory.fortress.core.model.Role)1