use of org.apache.directory.fortress.core.model.OrgUnit in project directory-fortress-core by apache.
the class CreatePermOrgHierarchySample method testCreateAscendantPermOrgs.
/**
* Demonstrate a child to parent OrgUnit structure of one-to-many. To use this API, the child OrgUnit must be created before
* the call to addAscendant which will Add a new OrgUnit node and set a OrgUnit relationship with child node.
* <p>
* <img src="./doc-files/HierPermOrgAscendants.png" alt="">
*/
public static void testCreateAscendantPermOrgs() {
String szLocation = ".testCreateAscendantPermOrgs";
try {
// Instantiate the DelAdminMgr implementation which is used to provision ARBAC policies.
DelAdminMgr delAdminMgr = DelAdminMgrFactory.createInstance(TestUtils.getContext());
// Instantiate the child OrgUnit. This needs a name and type.
OrgUnit childOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
// This child will have many parents:
delAdminMgr.add(childOrgUnit);
// Create OrgUnits, 'sampleHierPermOrgA2' - 'sampleHierPermOrgA6'.
for (int i = 1; i < TEST_NUMBER; i++) {
// Instantiate the parent OrgUnit. This needs a name and type before it can be added to ldap.
OrgUnit parentOrgUnit = new OrgUnit(TEST_HIER_ASC_PERMORG_PREFIX + (i + 1), OrgUnit.Type.PERM);
// Now add parent OrgUnit entity to directory and add relationship with existing child OrgUnit.
delAdminMgr.addAscendant(childOrgUnit, parentOrgUnit);
}
} 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 testDeleteDescendantPermOrgs.
/**
* 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.
* Perm OrgUnit removal is not allowed (SecurityException will be thrown) if ou is assigned to PermObjs in ldap.
* <p>
* <img src="./doc-files/HierPermOrgDescendants.png" alt="">
*/
public static void testDeleteDescendantPermOrgs() {
String szLocation = ".testDeleteDescendantPermOrgs";
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_PERMORG_PREFIX + 1, OrgUnit.Type.PERM);
// There are N Perm 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_PERMORG_PREFIX + i, OrgUnit.Type.PERM);
// 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());
}
}
use of org.apache.directory.fortress.core.model.OrgUnit in project directory-fortress-core by apache.
the class CreatePermOrgSample method testCreatePermOrg2.
/**
*/
public static void testCreatePermOrg2() {
String szLocation = ".testCreatePermOrg2";
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_NM2, 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());
}
}
use of org.apache.directory.fortress.core.model.OrgUnit in project directory-fortress-core by apache.
the class DelAdminMgrRestImpl method update.
/**
* {@inheritDoc}
*/
@Override
public OrgUnit update(OrgUnit entity) throws SecurityException {
VUtil.assertNotNull(entity, GlobalErrIds.ORG_NULL, CLS_NM + ".updateOU");
OrgUnit retOrg;
FortRequest request = new FortRequest();
request.setContextId(this.contextId);
request.setEntity(entity);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.ORG_UPDATE);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retOrg = (OrgUnit) response.getEntity();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retOrg;
}
use of org.apache.directory.fortress.core.model.OrgUnit in project directory-fortress-core by apache.
the class DelAdminMgrRestImpl method delete.
/**
* {@inheritDoc}
*/
@Override
public OrgUnit delete(OrgUnit entity) throws SecurityException {
VUtil.assertNotNull(entity, GlobalErrIds.ORG_NULL, CLS_NM + ".deleteOU");
OrgUnit retOrg;
FortRequest request = new FortRequest();
request.setContextId(this.contextId);
request.setEntity(entity);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.ORG_DELETE);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retOrg = (OrgUnit) response.getEntity();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retOrg;
}
Aggregations