Search in sources :

Example 21 with OrgUnit

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

the class CreateUserOrgHierarchySample method testCreateDescendantUserOrgs.

/**
 * 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/HierUserOrgDescendants.png" alt="">
 */
public static void testCreateDescendantUserOrgs() {
    String szLocation = ".testCreateDescendantUserOrgs";
    try {
        // Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
        DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
        // Instantiate the parent User OrgUnit entity.  This needs a name and type before it can be added to ldap.
        OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_DESC_USERORG_PREFIX + 1, OrgUnit.Type.USER);
        // This parent will have many children:
        delAdminMgr.add(parentOrgUnit);
        // Create User OrgUnits, 'sampleHierUserOrgD2' - 'sampleHierUserOrgD6'.
        for (int i = 1; i < TEST_NUMBER; i++) {
            // Now add relationship to the directory between parent and child User OrgUnits.
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_DESC_USERORG_PREFIX + (i + 1), OrgUnit.Type.USER);
            // 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 22 with OrgUnit

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

the class CreateUserOrgSample method testCreateUserOrg.

/**
 * Before a User can be added to ldap directory an OrgUnit must be created.  The User OrgUnit entity
 * supports general hierarchies meaning an OrgUnit can have zero or more parents.  The User OrgUnit
 * organizational structure is represented logically as a simple directional graph though that
 * functionality is not demonstrated here.
 */
public static void testCreateUserOrg() {
    String szLocation = ".testCreateUserOrg";
    try {
        DelReviewMgr dRevAdminMgr = DelReviewMgrFactory.createInstance(TestUtils.getContext());
        // The OrgUnit requires name and type to be set before use.
        OrgUnit inOU = new OrgUnit(TEST_USER_OU_NM, OrgUnit.Type.USER);
        try {
            dRevAdminMgr.read(inOU);
            // if org is found, return.
            return;
        } catch (FinderException fe) {
            assertTrue(szLocation + " excep id check", fe.getErrorId() == GlobalErrIds.ORG_NOT_FOUND_USER);
        // 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 23 with OrgUnit

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

the class CreatePermOrgHierarchySample method testDeleteHierPermOrgs.

/**
 * 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.
 * Perm OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to PermObjs in ldap.
 * <p>
 * <img src="./doc-files/HierPermOrgSimple.png" alt="">
 */
public static void testDeleteHierPermOrgs() {
    String szLocation = ".testDeleteHierPermOrgs";
    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_PERMORG_PREFIX + i, OrgUnit.Type.PERM);
            OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_PERMORG_PREFIX + (i + 1), OrgUnit.Type.PERM);
            // 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_PERMORG_PREFIX + TEST_NUMBER, OrgUnit.Type.PERM));
        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 24 with OrgUnit

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

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

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