Search in sources :

Example 41 with FinderException

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

Example 42 with FinderException

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

the class ExampleDAO method findByKey.

/**
 * @param name
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
public Example findByKey(String name) throws FinderException {
    Example entity = null;
    LdapConnection ld = null;
    String dn = SchemaConstants.CN_AT + "=" + name + "," + Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("findByKey dn [" + dn + "]");
    }
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, EXAMPLE_ATRS);
        entity = getEntityFromLdapEntry(findEntry);
        if (entity == null) {
            String error = "findByKey could not find entry for example name [" + name + "]";
            LOG.error(error);
            throw new FinderException(EErrIds.EXAMPLE_NOT_FOUND, error);
        }
    } catch (LdapNoSuchObjectException e) {
        String error = "findByKey COULD NOT FIND ENTRY for example name [" + name + "]";
        throw new FinderException(GlobalErrIds.SSD_NOT_FOUND, error);
    } catch (LdapException e) {
        String error = "findByKey name [" + name + "] caught LDAPException=" + e;
        LOG.warn(error);
        throw new FinderException(EErrIds.EXAMPLE_READ_FAILED, error);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 43 with FinderException

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

the class CreateRoleSample method testDeleteRoles.

/**
 * Remove the Role from the directory.  Role removal will trigger automatic deassignment from all Users or revocation of Permission as well.
 */
public static void testDeleteRoles() {
    String szLocation = ".testDeleteRoles";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the AdminMgr implementation which is used to provision RBAC policies.
        AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        for (int i = 1; i < 11; i++) {
            // The key that must be set to locate any Role is simply the name.
            Role inRole = new Role(TEST_ROLE_PREFIX + i);
            // Remove the Role from directory along with associated assignments:
            adminMgr.deleteRole(inRole);
            // Instantiate the ReviewMgr implementation which is used to interrogate RBAC policy information.
            ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
            try {
                // this should fail because the Role was deleted above:
                reviewMgr.readRole(inRole);
                fail(szLocation + " role [" + inRole.getName() + "] delete failed");
            } catch (FinderException se) {
                assertTrue(szLocation + " excep id check", se.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND);
            // pass
            }
            LOG.info(szLocation + " role [" + inRole.getName() + "] success");
        }
    } catch (SecurityException ex) {
        LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) FinderException(org.apache.directory.fortress.core.FinderException) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 44 with FinderException

use of org.apache.directory.fortress.core.FinderException 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 45 with FinderException

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

the class SdDAO method search.

/**
 * @param roles
 * @param sdSet
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Set<SDSet> search(Set<String> roles, SDSet sdSet) throws FinderException {
    Set<SDSet> sdList = new HashSet<>();
    LdapConnection ld = null;
    String ssdRoot = getSdRoot(sdSet.getContextId());
    String objectClass = SSD_OBJECT_CLASS_NM;
    if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
        objectClass = DSD_OBJECT_CLASS_NM;
    }
    try {
        if (CollectionUtils.isNotEmpty(roles)) {
            StringBuilder filterbuf = new StringBuilder();
            filterbuf.append(GlobalIds.FILTER_PREFIX);
            filterbuf.append(objectClass);
            filterbuf.append(")(|");
            for (String rle : roles) {
                filterbuf.append("(");
                filterbuf.append(ROLES);
                filterbuf.append("=");
                filterbuf.append(rle);
                filterbuf.append(")");
            }
            filterbuf.append("))");
            ld = getAdminConnection();
            SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filterbuf.toString(), SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
            long sequence = 0;
            while (searchResults.next()) {
                sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
            }
        }
    } catch (LdapException e) {
        String error = "search type [" + sdSet.getType() + "] caught LdapException=" + e.getMessage();
        int errCode;
        if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "search type [" + sdSet.getType() + "] caught CursorException=" + e.getMessage();
        int errCode;
        if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
            errCode = GlobalErrIds.DSD_SEARCH_FAILED;
        } else {
            errCode = GlobalErrIds.SSD_SEARCH_FAILED;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return sdList;
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

FinderException (org.apache.directory.fortress.core.FinderException)80 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)72 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)72 ArrayList (java.util.ArrayList)49 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)48 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)48 Entry (org.apache.directory.api.ldap.model.entry.Entry)22 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)21 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)17 Permission (org.apache.directory.fortress.core.model.Permission)10 User (org.apache.directory.fortress.core.model.User)8 SecurityException (org.apache.directory.fortress.core.SecurityException)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)6 Modification (org.apache.directory.api.ldap.model.entry.Modification)6 UpdateException (org.apache.directory.fortress.core.UpdateException)6 Role (org.apache.directory.fortress.core.model.Role)6 UserRole (org.apache.directory.fortress.core.model.UserRole)6 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)5 AdminRole (org.apache.directory.fortress.core.model.AdminRole)4 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)4