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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations