use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class SdDAO method search.
/**
* @param roles
* @param sdSet
* @return
* @throws org.apache.directory.fortress.core.FinderException
*/
Set<SDSet> search(Set<String> roles, SDSet sdSet) throws FinderException {
Set<SDSet> sdList = new HashSet<>();
LdapConnection ld = null;
String ssdRoot = getSdRoot(sdSet.getContextId());
String objectClass = SSD_OBJECT_CLASS_NM;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
objectClass = DSD_OBJECT_CLASS_NM;
}
try {
if (CollectionUtils.isNotEmpty(roles)) {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(objectClass);
filterbuf.append(")(|");
for (String rle : roles) {
filterbuf.append("(");
filterbuf.append(ROLES);
filterbuf.append("=");
filterbuf.append(rle);
filterbuf.append(")");
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, ssdRoot, SearchScope.SUBTREE, filterbuf.toString(), SD_SET_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
sdList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
}
}
} catch (LdapException e) {
String error = "search type [" + sdSet.getType() + "] caught LdapException=" + e.getMessage();
int errCode;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} catch (CursorException e) {
String error = "search type [" + sdSet.getType() + "] caught CursorException=" + e.getMessage();
int errCode;
if (sdSet.getType() == SDSet.SDType.DYNAMIC) {
errCode = GlobalErrIds.DSD_SEARCH_FAILED;
} else {
errCode = GlobalErrIds.SSD_SEARCH_FAILED;
}
throw new FinderException(errCode, error, e);
} finally {
closeAdminConnection(ld);
}
return sdList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method findUsers.
/**
* @param user
* @param limit
* @return
* @throws FinderException
*/
List<String> findUsers(User user, int limit) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(user.getContextId(), GlobalIds.USER_ROOT);
try {
String searchVal = encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.UID_AT);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("*))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID, false, limit);
while (searchResults.next()) {
Entry entry = searchResults.getEntry();
userList.add(getAttribute(entry, SchemaConstants.UID_AT));
}
} catch (LdapException e) {
String warning = "findUsers caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAssignedUsers.
/**
* @param roles
* @return
* @throws FinderException
*/
Set<String> getAssignedUsers(Set<String> roles, String contextId) throws FinderException {
Set<String> userSet = new HashSet<>();
LdapConnection ld = null;
String userRoot = getRootDn(contextId, GlobalIds.USER_ROOT);
try {
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(|");
if (CollectionUtils.isNotEmpty(roles)) {
for (String roleVal : roles) {
String filteredVal = encodeSafeText(roleVal, GlobalIds.USERID_LEN);
filterbuf.append("(");
filterbuf.append(GlobalIds.USER_ROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(filteredVal);
filterbuf.append(")");
}
} else {
return null;
}
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), USERID_ATRS, false, GlobalIds.BATCH_SIZE);
while (searchResults.next()) {
userSet.add(getAttribute(searchResults.getEntry(), SchemaConstants.UID_AT));
}
} catch (LdapException e) {
String warning = "getAssignedUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.URLE_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userSet;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method findUsersList.
/**
* @param searchVal
* @return
* @throws FinderException
*/
List<String> findUsersList(String searchVal, String contextId) throws FinderException {
List<String> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(contextId, GlobalIds.USER_ROOT);
try {
searchVal = encodeSafeText(searchVal, GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(Config.getInstance().getProperty(USER_OBJECT_CLASS));
filterbuf.append(")(");
filterbuf.append(SchemaConstants.UID_AT);
filterbuf.append("=");
filterbuf.append(searchVal);
filterbuf.append("*))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add((unloadLdapEntry(searchResults.getEntry(), sequence++, contextId)).getUserId());
}
} catch (LdapException e) {
String warning = "findUsersList caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "findUsersList caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class UserDAO method getAssignedUsers.
/**
* @param role
* @return
* @throws FinderException
*/
List<User> getAssignedUsers(AdminRole role) throws FinderException {
List<User> userList = new ArrayList<>();
LdapConnection ld = null;
String userRoot = getRootDn(role.getContextId(), GlobalIds.USER_ROOT);
try {
String roleVal = encodeSafeText(role.getName(), GlobalIds.USERID_LEN);
StringBuilder filterbuf = new StringBuilder();
filterbuf.append(GlobalIds.FILTER_PREFIX);
filterbuf.append(USERS_AUX_OBJECT_CLASS_NAME);
filterbuf.append(")(");
filterbuf.append(GlobalIds.USER_ADMINROLE_ASSIGN);
filterbuf.append("=");
filterbuf.append(roleVal);
filterbuf.append("))");
ld = getAdminConnection();
SearchCursor searchResults = search(ld, userRoot, SearchScope.ONELEVEL, filterbuf.toString(), defaultAtrs, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
userList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, role.getContextId()));
}
} catch (LdapException e) {
String warning = "getAssignedUsers admin role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_USER_SEARCH_FAILED, warning, e);
} catch (CursorException e) {
String warning = "getAssignedUsers admin role name [" + role.getName() + "] caught LDAPException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_USER_SEARCH_FAILED, warning, e);
} finally {
closeAdminConnection(ld);
}
return userList;
}
Aggregations