Search in sources :

Example 41 with OrgUnit

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());
    }
}
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 42 with OrgUnit

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());
    }
}
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 43 with OrgUnit

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());
    }
}
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 44 with OrgUnit

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;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 45 with OrgUnit

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;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

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