Search in sources :

Example 31 with DelAdminMgr

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

the class CreateUserOrgHierarchySample method testCreateHierUserOrgs.

/**
 * Add a simple OrgUnit hierarchy to ldap.  The OrgUnits will named to include a name,'sampleHierUserOrg', appended with the
 * sequence of 1 - 6.  'sampleHierUserOrg1' is the root or highest level OrgUnit in the structure while sampleHierUserOrg6 is the lowest
 * most child.  Fortress OrgUnits may have multiple parents which is demonstrated in testCreateAscendantUserOrgs sample.
 * <p>
 * <img src="./doc-files/HierUserOrgSimple.png" alt="">
 */
public static void testCreateHierUserOrgs() {
    String szLocation = ".testCreateHierUserOrgs";
    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_USERORG, OrgUnit.Type.USER);
        // Add the root OrgUnit entity to the directory.
        delAdminMgr.add(baseOrgUnit);
        // Create User OrgUnits, 'sampleHierUserOrg2' - 'sampleHierUserOrg6'.
        for (int i = 2; i < TEST_NUMBER + 1; i++) {
            // Instantiate the OrgUnit entity.
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_USERORG_PREFIX + i, OrgUnit.Type.USER);
            // 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_USERORG_PREFIX + (i - 1), OrgUnit.Type.USER);
            // 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 32 with DelAdminMgr

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

the class CreateUserOrgHierarchySample method testDeleteDescendantUserOrgs.

/**
 * 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.
 * User OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to Users in ldap.
 * <p>
 * <img src="./doc-files/HierUserOrgDescendants.png" alt="">
 */
public static void testDeleteDescendantUserOrgs() {
    String szLocation = ".testDeleteDescendantUserOrgs";
    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_USERORG_PREFIX + 1, OrgUnit.Type.USER);
        // There are N User 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_USERORG_PREFIX + i, OrgUnit.Type.USER);
            // 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 33 with DelAdminMgr

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

the class CreateUserOrgHierarchySample method testDeleteHierUserOrgs.

/**
 * Remove the simple hierarchical OrgUnits from the directory.  Before removal call the API to move the relationship
 * between the parent and child OrgUnits.  Once the relationship is removed the parent OrgUnit can be removed.
 * User OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to Users in ldap.
 * <p>
 * <img src="./doc-files/HierUserOrgSimple.png" alt="">
 */
public static void testDeleteHierUserOrgs() {
    String szLocation = ".testDeleteHierUserOrgs";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        for (int i = 1; i < TEST_NUMBER; i++) {
            // The key that must be set to locate any OrgUnit is simply the name and type.
            OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_USERORG_PREFIX + i, OrgUnit.Type.USER);
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_USERORG_PREFIX + (i + 1), OrgUnit.Type.USER);
            // Remove the relationship from the parent and child OrgUnit:
            delAdminMgr.deleteInheritance(parentOrgUnit, childOrgUnit);
            // Remove the parent OrgUnit from directory:
            delAdminMgr.delete(parentOrgUnit);
        }
        // Remove the child OrgUnit from directory:
        delAdminMgr.delete(new OrgUnit(TEST_HIER_USERORG_PREFIX + TEST_NUMBER, OrgUnit.Type.USER));
        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 34 with DelAdminMgr

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

the class CreateUserOrgHierarchySample method testDeleteAscendantUserOrgs.

/**
 * This example demonstrates tear down of a child to parent represented as one-to-many.  The parents must all
 * be removed from the child before the child can be removed.
 * User OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to Users in ldap.
 * <p>
 * <img src="./doc-files/HierUserOrgAscendants.png" alt="">
 */
public static void testDeleteAscendantUserOrgs() {
    String szLocation = ".testDeleteAscendantUserOrgs";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // This child OrgUnit has many parents:
        OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_ASC_USERORG_PREFIX + 1, OrgUnit.Type.USER);
        for (int i = 2; i < TEST_NUMBER + 1; i++) {
            // Instantiate the parent.  This needs a name and type before it can be used in operation.
            OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_ASC_USERORG_PREFIX + i, OrgUnit.Type.USER);
            // Remove the relationship between parent and child OrgUnits:
            delAdminMgr.deleteInheritance(parentOrgUnit, childOrgUnit);
            // Remove the parent OrgUnit from directory:
            delAdminMgr.delete(parentOrgUnit);
        }
        // Remove the child OrgUnit from directory:
        delAdminMgr.delete(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 35 with DelAdminMgr

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

the class CreatePermOrgHierarchySample method testDeleteAscendantPermOrgs.

/**
 * This example demonstrates tear down of a child to parent represented as one-to-many.  The parents must all
 * be removed from the child before the child can be removed.
 * Perm OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to PermObjs in ldap.
 * <p>
 * <img src="./doc-files/HierPermOrgAscendants.png" alt="">
 */
public static void testDeleteAscendantPermOrgs() {
    String szLocation = ".testDeleteAscendantPermOrgs";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // This child OrgUnit has many parents:
        OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
        for (int i = 2; i < TEST_NUMBER + 1; i++) {
            // Instantiate the parent.  This needs a name and type before it can be used in operation.
            OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + i, OrgUnit.Type.PERM);
            // Remove the relationship between parent and child OrgUnits:
            delAdminMgr.deleteInheritance(parentOrgUnit, childOrgUnit);
            // Remove the parent OrgUnit from directory:
            delAdminMgr.delete(parentOrgUnit);
        }
        // Remove the child OrgUnit from directory:
        delAdminMgr.delete(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)

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