use of org.apache.directory.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor 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;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class OrgUnitDAO method findOrgs.
/**
* @param orgUnit
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
List<OrgUnit> findOrgs(OrgUnit orgUnit) throws FinderException {
List<OrgUnit> orgUnitList = new ArrayList<>();
LdapConnection ld = null;
String orgUnitRoot = getOrgRoot(orgUnit);
try {
String searchVal = encodeSafeText(orgUnit.getName(), GlobalIds.ROLE_LEN);
String filter = GlobalIds.FILTER_PREFIX + ORGUNIT_OBJECT_CLASS_NM + ")(" + SchemaConstants.OU_AT + "=" + searchVal + "*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, ORGUNIT_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
orgUnitList.add(getEntityFromLdapEntry(searchResults.getEntry(), sequence++, orgUnit.getContextId()));
}
} catch (LdapException e) {
String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught LdapException=" + e;
int errCode;
if (orgUnit.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
} else {
errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
}
throw new FinderException(errCode, error, e);
} catch (CursorException e) {
String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught CursorException=" + e;
int errCode;
if (orgUnit.getType() == OrgUnit.Type.PERM) {
errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
} else {
errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return orgUnitList;
}
Aggregations