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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations