use of org.apache.directory.fortress.core.FinderException in project directory-fortress-core by apache.
the class AdminRoleDAO method getRole.
/**
* This method will retrieve the AdminRole from {@link GlobalIds#ADMIN_ROLE_ROOT} container by name.
*
* @param adminRole maps to {@link AdminRole#name}.
* @return AdminRole back to client.
* @throws FinderException in the event LDAP errors occur.
*/
AdminRole getRole(AdminRole adminRole) throws FinderException {
AdminRole entity = null;
LdapConnection ld = null;
String dn = getDn(adminRole);
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, ROLE_ATRS);
if (findEntry != null) {
entity = unloadLdapEntry(findEntry, 0, adminRole.getContextId());
}
if (entity == null) {
String warning = "getRole name [" + adminRole.getName() + "] no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning);
}
} catch (LdapNoSuchObjectException e) {
String warning = "getRole name [" + adminRole.getName() + "] Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning, e);
} catch (LdapException e) {
String error = "getRole dn [" + dn + "] LEXCD=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_READ_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.fortress.core.FinderException 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.fortress.core.FinderException 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.fortress.core.FinderException in project directory-fortress-core by apache.
the class RoleDAO method getRole.
/**
* @param role
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
Role getRole(Role role) throws FinderException {
Role entity = null;
LdapConnection ld = null;
String dn = getDn(role.getName(), role.getContextId());
try {
ld = getAdminConnection();
Entry findEntry = read(ld, dn, ROLE_ATRS);
if (findEntry != null) {
entity = unloadLdapEntry(findEntry, 0, role.getContextId());
}
if (entity == null) {
String warning = "getRole no entry found dn [" + dn + "]";
throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
}
} catch (LdapNoSuchObjectException e) {
String warning = "getRole Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
} catch (LdapException e) {
String error = "getRole dn [" + dn + "] LEXCD=" + e;
throw new FinderException(GlobalErrIds.ROLE_READ_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return entity;
}
use of org.apache.directory.fortress.core.FinderException 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