Search in sources :

Example 36 with OrgUnit

use of org.apache.directory.fortress.core.model.OrgUnit 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 37 with OrgUnit

use of org.apache.directory.fortress.core.model.OrgUnit 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 38 with OrgUnit

use of org.apache.directory.fortress.core.model.OrgUnit 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 39 with OrgUnit

use of org.apache.directory.fortress.core.model.OrgUnit 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)

Example 40 with OrgUnit

use of org.apache.directory.fortress.core.model.OrgUnit 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)

Aggregations

OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)60 SecurityException (org.apache.directory.fortress.core.SecurityException)36 DelAdminMgr (org.apache.directory.fortress.core.DelAdminMgr)26 DelReviewMgr (org.apache.directory.fortress.core.DelReviewMgr)7 Relationship (org.apache.directory.fortress.core.model.Relationship)6 FinderException (org.apache.directory.fortress.core.FinderException)5 FortRequest (org.apache.directory.fortress.core.model.FortRequest)5 FortResponse (org.apache.directory.fortress.core.model.FortResponse)5 HashSet (java.util.HashSet)4 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)4 ArrayList (java.util.ArrayList)3 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)3 UserRole (org.apache.directory.fortress.core.model.UserRole)3 TreeSet (java.util.TreeSet)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 ValidationException (org.apache.directory.fortress.core.ValidationException)2 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 Graphable (org.apache.directory.fortress.core.model.Graphable)2 Hier (org.apache.directory.fortress.core.model.Hier)2 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)2