Search in sources :

Example 36 with DelAdminMgr

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

the class CreatePermOrgHierarchySample method testCreateHierPermOrgs.

/**
 * Add a simple OrgUnit hierarchy to ldap.  The OrgUnits will named to include a name,'sampleHierPermOrg', appended with the
 * sequence of 1 - 6.  'sampleHierPermOrg1' is the root or highest level OrgUnit in the structure while sampleHierPermOrg6 is the lowest
 * most child.  Fortress OrgUnits may have multiple parents which is demonstrated in testCreateAscendantPermOrgs sample.
 * <p>
 * <img src="./doc-files/HierPermOrgSimple.png" alt="">
 */
public static void testCreateHierPermOrgs() {
    String szLocation = ".testCreateHierPermOrgs";
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // Instantiate the root OrgUnit entity.  OrgUnit requires name and type before addition.
        OrgUnit baseOrgUnit = new OrgUnit(TEST_HIER_BASE_PERMORG, OrgUnit.Type.PERM);
        // Add the root OrgUnit entity to the directory.
        delAdminMgr.add(baseOrgUnit);
        // Create Perm OrgUnits, 'sampleHierPermOrg2' - 'sampleHierPermOrg6'.
        for (int i = 2; i < TEST_NUMBER + 1; i++) {
            // Instantiate the OrgUnit entity.
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_PERMORG_PREFIX + i, OrgUnit.Type.PERM);
            // Add the OrgUnit entity to the directory.
            delAdminMgr.add(childOrgUnit);
            // Instantiate the parent OrgUnit.  The key is the name and type.
            OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_PERMORG_PREFIX + (i - 1), OrgUnit.Type.PERM);
            // Add a relationship between the parent and child OrgUnits:
            delAdminMgr.addInheritance(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 37 with DelAdminMgr

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

the class CreatePermOrgHierarchySample method testCreateAscendantPermOrgs.

/**
 * Demonstrate a child to parent OrgUnit structure of one-to-many.  To use this API, the child OrgUnit must be created before
 * the call to addAscendant which will Add a new OrgUnit node and set a OrgUnit relationship with child node.
 * <p>
 * <img src="./doc-files/HierPermOrgAscendants.png" alt="">
 */
public static void testCreateAscendantPermOrgs() {
    String szLocation = ".testCreateAscendantPermOrgs";
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // Instantiate the child OrgUnit.  This needs a name and type.
        OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
        // This child will have many parents:
        delAdminMgr.add(childOrgUnit);
        // Create OrgUnits, 'sampleHierPermOrgA2' - 'sampleHierPermOrgA6'.
        for (int i = 1; i < TEST_NUMBER; i++) {
            // Instantiate the parent OrgUnit.  This needs a name and type before it can be added to ldap.
            OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + (i + 1), OrgUnit.Type.PERM);
            // Now add parent OrgUnit entity to directory and add relationship with existing child OrgUnit.
            delAdminMgr.addAscendant(childOrgUnit, parentOrgUnit);
        }
    } 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 38 with DelAdminMgr

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

the class CreatePermOrgHierarchySample method testDeleteDescendantPermOrgs.

/**
 * Demonstrate teardown of a parent to child relationship of one-to-many.  Each child must first remove the inheritance
 * relationship with parent before being removed from ldap.  The parent OrgUnit will be removed from ldap last.
 * Perm OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to PermObjs in ldap.
 * <p>
 * <img src="./doc-files/HierPermOrgDescendants.png" alt="">
 */
public static void testDeleteDescendantPermOrgs() {
    String szLocation = ".testDeleteDescendantPermOrgs";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // This parent has many children.  They must be deleted before parent itself can.
        OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_DESC_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
        // There are N Perm OrgUnits to process:
        for (int i = 2; i < TEST_NUMBER + 1; i++) {
            // Instantiate the child OrgUnit entity.  The key is the name and type.
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_DESC_PERMORG_PREFIX + i, OrgUnit.Type.PERM);
            // Remove the relationship from the parent and child OrgUnit:
            delAdminMgr.deleteInheritance(parentOrgUnit, childOrgUnit);
            // Remove the child OrgUnit from directory:
            delAdminMgr.delete(childOrgUnit);
        }
        // Remove the parent OrgUnit from directory:
        delAdminMgr.delete(parentOrgUnit);
        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 39 with DelAdminMgr

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

the class CreatePermOrgSample method testCreatePermOrg2.

/**
 */
public static void testCreatePermOrg2() {
    String szLocation = ".testCreatePermOrg2";
    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_NM2, 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)

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