Search in sources :

Example 71 with FinderException

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

the class GroupDAO method find.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> find(User user) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(user.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.MEMBER_AT + "=" + user.getDn() + "))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 72 with FinderException

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

the class GroupDAO method roleGroups.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> roleGroups(Role role) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(role.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.MEMBER_AT + "=" + role.getDn() + "))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 73 with FinderException

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

the class GroupDAO method get.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Group get(Group group) throws FinderException {
    Group entity = null;
    LdapConnection ld = null;
    String dn = getDn(group.getName(), group.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, GROUP_ATRS);
        if (findEntry == null) {
            String warning = "No Group entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.GROUP_NOT_FOUND, warning);
        }
        entity = unloadLdapEntry(findEntry, 0);
    } catch (LdapNoSuchObjectException e) {
        String warning = "read Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.GROUP_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "read dn [" + dn + "] LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_READ_FAILED, error, e);
    } 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 74 with FinderException

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

the class GroupDAO method find.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> find(Group group) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(group.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        String searchVal = encodeSafeText(group.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.CN_AT + "=" + searchVal + "*))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 75 with FinderException

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

the class OrgUnitDAO method getOrgs.

/**
 * @param orgUnit
 * @return
 * @throws FinderException
 */
Set<String> getOrgs(OrgUnit orgUnit) throws FinderException {
    Set<String> ouSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    LdapConnection ld = null;
    String orgUnitRoot = getOrgRoot(orgUnit);
    try {
        String filter = "(objectclass=" + ORGUNIT_OBJECT_CLASS_NM + ")";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, ORGUNIT_ATR, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            ouSet.add(getAttribute(searchResults.getEntry(), SchemaConstants.OU_AT));
        }
        searchResults.close();
    } catch (LdapException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught LdapException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught CursorException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (IOException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught IOException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return ouSet;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) TreeSet(java.util.TreeSet) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) 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