Search in sources :

Example 31 with OrgUnit

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

the class DelegatedMgrImplTest method addOrgUnitDescendant.

/**
 * @param msg
 * @param oArray
 */
public static void addOrgUnitDescendant(String msg, String[][] oArray, OrgUnit.Type type) {
    LogUtil.logIt(msg);
    try {
        DelAdminMgr dAdminMgr = getManagedDelegatedMgr();
        int ctr = 0;
        for (String[] ole : oArray) {
            OrgUnit orgUnit = OrgUnitTestData.getOrgUnit(ole);
            if (ctr++ == 0 || OrgUnitTestData.isTree(ole)) {
                dAdminMgr.add(orgUnit);
                LOG.debug("addOrgUnitDescendant add orgUnit [" + orgUnit.getName() + "] successful");
            }
            // use list because order is important for test structure:
            List<String> descs = new ArrayList<String>();
            OrgUnitTestData.getRelationship(descs, ole);
            if (OrgUnitTestData.isTree(ole)) {
                OrgUnit parent = orgUnit;
                for (String desc : descs) {
                    OrgUnit child = new OrgUnit(desc, type);
                    dAdminMgr.addDescendant(parent, new OrgUnit(desc, type));
                    LOG.debug("addOrgUnitDescendant asc orgUnit [" + orgUnit.getName() + "] desc orgUnit [" + desc + "] successful");
                    parent = child;
                }
            } else {
                for (String desc : descs) {
                    dAdminMgr.addDescendant(orgUnit, new OrgUnit(desc, type));
                    LOG.debug("addOrgUnitDescendant asc orgUnit [" + orgUnit.getName() + "] desc orgUnit [" + desc + "] successful");
                }
            }
            Set<String> inheritances = OrgUnitTestData.getInheritances(ole);
            if (inheritances != null) {
                for (String desc : inheritances) {
                    dAdminMgr.addInheritance(orgUnit, new OrgUnit(desc, type));
                    LOG.debug("addOrgUnitDescendant asc orgUnit [" + orgUnit.getName() + "] desc orgUnit [" + desc + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("addOrgUnitDescendant caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) ArrayList(java.util.ArrayList) DelAdminMgr(org.apache.directory.fortress.core.DelAdminMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 32 with OrgUnit

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

the class DelegatedMgrImplTest method readOrgUnits.

/**
 * @param msg
 * @param oArray
 */
public static void readOrgUnits(String msg, String[][] oArray) {
    LogUtil.logIt(msg);
    try {
        DelReviewMgr dReviewMgr = getManagedDelegatedReviewMgr();
        for (String[] ole : oArray) {
            OrgUnit ou = OrgUnitTestData.getOrgUnit(ole);
            OrgUnit entity = dReviewMgr.read(ou);
            OrgUnitTestData.assertEquals(entity, ole);
            LOG.debug("readOrgUnits [" + entity.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("readOrgUnits caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) SecurityException(org.apache.directory.fortress.core.SecurityException) DelReviewMgr(org.apache.directory.fortress.core.DelReviewMgr)

Example 33 with OrgUnit

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

the class DelegatedMgrImplTest method searchOrgUnits.

/**
 * @param msg
 * @param srchValue
 * @param oArray
 */
public static void searchOrgUnits(String msg, String srchValue, String[][] oArray) {
    LogUtil.logIt(msg);
    try {
        DelReviewMgr dReviewMgr = getManagedDelegatedReviewMgr();
        // grab the type from the first entry in the test org list:
        OrgUnit.Type type = OrgUnitTestData.getType(oArray[0]);
        List<OrgUnit> ous = dReviewMgr.search(type, srchValue);
        assertNotNull(ous);
        assertTrue("searchOrgUnits list size check", oArray.length == ous.size());
        for (String[] ole : oArray) {
            int indx = ous.indexOf(new OrgUnit(OrgUnitTestData.getName(ole)));
            if (indx != -1) {
                OrgUnit entity = ous.get(indx);
                assertNotNull(entity);
                OrgUnitTestData.assertEquals(entity, ole);
                LOG.debug("searchOrgUnits [" + entity.getName() + "] successful");
            } else {
                msg = "searchOrgUnits srchValue [" + srchValue + "] failed list search";
                LogUtil.logIt(msg);
                fail(msg);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("searchOrgUnits srchValue [" + srchValue + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) SecurityException(org.apache.directory.fortress.core.SecurityException) DelReviewMgr(org.apache.directory.fortress.core.DelReviewMgr)

Example 34 with OrgUnit

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

the class OrgUnitTestData method getOrgUnit.

public static OrgUnit getOrgUnit(String[] ole) {
    OrgUnit ou = new OrgUnit();
    ou.setName(getName(ole));
    ou.setDescription(getDescription(ole));
    ou.setType(getType(ole));
    return ou;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit)

Example 35 with OrgUnit

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

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