Search in sources :

Example 36 with FinderException

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

the class RoleDAO method findAssignedRoles.

/**
 * @param userDn
 * @param contextId
 * @return
 * @throws FinderException
 */
List<String> findAssignedRoles(String userDn, String contextId) throws FinderException {
    List<String> roleNameList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(contextId, GlobalIds.ROLE_ROOT);
    try {
        String filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")";
        filter += "(" + SchemaConstants.ROLE_OCCUPANT_AT + "=" + userDn + "))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            roleNameList.add(getAttribute(searchResults.getEntry(), ROLE_NM));
        }
    } catch (LdapException e) {
        String error = "findAssignedRoles userDn [" + userDn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_OCCUPANT_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findAssignedRoles userDn [" + userDn + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_OCCUPANT_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleNameList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 37 with FinderException

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

the class RoleDAO method findRoles.

/**
 * @param role
 * @param limit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<String> findRoles(Role role, int limit) throws FinderException {
    List<String> roleList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(role.getContextId(), GlobalIds.ROLE_ROOT);
    String filter = null;
    try {
        String searchVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, limit);
        while (searchResults.next()) {
            Entry entry = searchResults.getEntry();
            roleList.add(getAttribute(entry, ROLE_NM));
        }
    } catch (LdapException e) {
        String error = "findRoles filter [" + filter + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : 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) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 38 with FinderException

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

the class RoleP method removeOccupant.

/**
 * Remove the User dn occupant attribute from the OrganizationalRole entity in ldap.  This method is called by AdminMgrImpl
 * when the User is being deleted.
 *
 * @param userDn contains the userId targeted for attribute removal.
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
 * @throws SecurityException in the event of DAO search error.
 */
void removeOccupant(String userDn, String contextId) throws SecurityException {
    List<String> list;
    try {
        list = rDao.findAssignedRoles(userDn, contextId);
        for (String roleNm : list) {
            Role role = new Role(roleNm);
            role.setContextId(contextId);
            deassign(role, userDn);
        }
    } catch (FinderException fe) {
        String error = "removeOccupant userDn [" + userDn + "] caught FinderException=" + fe;
        throw new SecurityException(GlobalErrIds.ROLE_REMOVE_OCCUPANT_FAILED, error, fe);
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) FinderException(org.apache.directory.fortress.core.FinderException) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 39 with FinderException

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

the class ExampleDAO method findExamples.

/**
 * @param searchVal
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
public List<Example> findExamples(String searchVal) throws FinderException {
    List<Example> exampleList = new ArrayList<>();
    LdapConnection ld = null;
    String exampleRoot = Config.getInstance().getProperty(EIds.EXAMPLE_ROOT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("findExamples: " + EIds.EXAMPLE_ROOT + " [" + exampleRoot + "]");
    }
    try {
        searchVal = encodeSafeText(searchVal, GlobalIds.ROLE_LEN);
        ld = getAdminConnection();
        String filter = GlobalIds.FILTER_PREFIX + Arrays.toString(EIds.EXAMPLE_OBJ_CLASS) + ")(" + EIds.EXAMPLE_NM + "=" + searchVal + "*))";
        SearchCursor searchResults = search(ld, exampleRoot, SearchScope.SUBTREE, filter, EXAMPLE_ATRS, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            exampleList.add(getEntityFromLdapEntry(searchResults.getEntry()));
        }
    } catch (LdapException e) {
        String error = "findExamples caught LDAPException=" + e;
        LOG.warn(error);
        throw new FinderException(EErrIds.EXAMPLE_SEARCH_FAILED, error);
    } catch (CursorException e) {
        String error = "findExamples caught CursorException=" + e;
        throw new FinderException(EErrIds.EXAMPLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return exampleList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 40 with FinderException

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

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