use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class AdminRoleDAO method findRoles.
/**
* @param adminRole
* @return
* @throws FinderException
*/
List<AdminRole> findRoles(AdminRole adminRole) throws FinderException {
List<AdminRole> roleList = new ArrayList<AdminRole>();
LdapConnection ld = null;
String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
String filter;
try {
String searchVal = encodeSafeText(adminRole.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_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, adminRole.getContextId()));
}
} catch (LdapException e) {
String error = "findRoles name [" + adminRole.getName() + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findRoles name [" + adminRole.getName() + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class AdminRoleDAO method findRoles.
/**
* @param adminRole
* @param limit
* @return
* @throws FinderException
*/
List<String> findRoles(AdminRole adminRole, int limit) throws FinderException {
List<String> roleList = new ArrayList<String>();
LdapConnection ld = null;
String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
String filter;
String searchVal = null;
try {
searchVal = encodeSafeText(adminRole.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 name [" + searchVal + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "findRoles name [" + searchVal + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class RoleDAO method getAllDescendants.
/**
* @param contextId
* @return
* @throws FinderException
*/
List<Graphable> getAllDescendants(String contextId) throws FinderException {
String[] DESC_ATRS = { ROLE_NM, GlobalIds.PARENT_NODES };
List<Graphable> descendants = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(contextId, GlobalIds.ROLE_ROOT);
String filter = null;
try {
filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + GlobalIds.PARENT_NODES + "=*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, DESC_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
descendants.add(unloadDescendants(searchResults.getEntry(), sequence++, contextId));
}
} catch (LdapException e) {
String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return descendants;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class RoleDAO method groupRoles.
/**
* Pull back all roles that are assigned to a particular group.
* @param group
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Role> groupRoles(Group group) throws FinderException {
List<Role> roleList = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(group.getContextId(), GlobalIds.ROLE_ROOT);
StringBuilder filterbuf = new StringBuilder();
try {
// loop for each group member....
// add role name to search filter
//
List<String> members = group.getMembers();
if (CollectionUtils.isNotEmpty(members)) {
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(GlobalIds.ROLE_OBJECT_CLASS_NM);
filterbuf.append(")(");
filterbuf.append("|");
for (String memberdn : members) {
filterbuf.append("(");
filterbuf.append(SchemaConstants.ENTRY_DN_AT);
filterbuf.append("=");
filterbuf.append(memberdn);
filterbuf.append(")");
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filterbuf.toString(), ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, group.getContextId()));
}
} else {
String error = "groupRoles passed empty member list";
throw new FinderException(GlobalErrIds.GROUP_MEMBER_NULL, error);
}
} catch (LdapException e) {
String error = "groupRoles filter [" + filterbuf.toString() + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "groupRoles filter [" + filterbuf.toString() + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return roleList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class RoleDAO method findRoles.
/**
* @param role
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<Role> findRoles(Role role) throws FinderException {
List<Role> 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_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, role.getContextId()));
}
} 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;
}
Aggregations