本文整理汇总了Java中com.unboundid.ldap.sdk.SearchResult.getEntryCount方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getEntryCount方法的具体用法?Java SearchResult.getEntryCount怎么用?Java SearchResult.getEntryCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.unboundid.ldap.sdk.SearchResult
的用法示例。
在下文中一共展示了SearchResult.getEntryCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntryByMail
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private SearchResultEntry getEntryByMail(String mail) {
try {
for (String ou : allOUs()) {
String dn = ldapUserBaseDN.replace("{}", ou);
SearchRequest ldapRequest = new SearchRequest(dn, SearchScope.SUB, "(mail=" + mail + ")");
SearchResult ldapResult = ldapConnection.search(ldapRequest);
if (ldapResult.getEntryCount() > 0) {
return ldapResult.getSearchEntries().get(0);
}
}
return null;
} catch (LDAPException e) {
return null;
}
}
示例2: getEntryById
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private SearchResultEntry getEntryById(String id) {
try {
for (String ou : allOUs()) {
String dn = ldapUserBaseDN.replace("{}", ou);
SearchRequest ldapRequest = new SearchRequest(dn, SearchScope.SUB, "(uid=" + id + ")");
SearchResult ldapResult = ldapConnection.search(ldapRequest);
if (ldapResult.getEntryCount() > 0) {
return ldapResult.getSearchEntries().get(0);
}
}
return null;
} catch (LDAPException e) {
return null;
}
}
示例3: setAccountRoles
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) {
String accountDN = accountSearchResult.getDN();
String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN));
groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername()));
// Fill in attributes into groupMemberPattern
for (Attribute attribute : accountSearchResult.getAttributes()) {
groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue()));
}
SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn"));
if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) {
for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) {
SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i);
String roleName = groupEntry.getAttribute("cn").getValue();
account.getAuthorizations().addRole(roleName);
}
}
}
示例4: removeSubtreeThroughIteration
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private void removeSubtreeThroughIteration(String dn) {
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.createPresenceFilter("objectClass")), 0, 0, null, "dn");
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn));
}
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn), ex);
}
List<String> removeEntriesDn = new ArrayList<String>(searchResult.getEntryCount());
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
removeEntriesDn.add(searchResultEntry.getDN());
}
Collections.sort(removeEntriesDn, LINE_LENGHT_COMPARATOR);
for (String removeEntryDn : removeEntriesDn) {
remove(removeEntryDn);
}
}
示例5: getLDIF
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Override
public List<String[]> getLDIF(String dn, String[] attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.create("objectclass=*")), toLdapSearchScope(SearchScope.BASE), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", dn, null), ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
示例6: getLDIFTree
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Override
public List<String[]> getLDIFTree(String baseDN, Filter searchFilter, String... attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter),
ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
示例7: getServerStatus
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private ServerStatus getServerStatus() throws Exception
{
SearchResult result =
findMonitorEntries("ds-general-monitor-entry");
if (result.getEntryCount() != 1)
{
throw new Exception(String.format(
"Expected one and only one general monitor entry; " +
"actual number was %d", result.getEntryCount()));
}
SearchResultEntry entry = result.getSearchEntries().get(0);
return new ServerStatus(
entry.getAttributeValues("unavailable-alert-type"),
entry.getAttributeValues("degraded-alert-type"));
}
示例8: getServletStatuses
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private List<ServletStatus> getServletStatuses() throws Exception
{
List<String> enabledServlets = new ArrayList<>();
List<ServletStatus> servletStatuses = new ArrayList<>();
if (!servletsToCheck.isEmpty())
{
SearchResult result =
findMonitorEntries("ds-http-servlet-config-monitor-entry",
"enabled-servlet-and-path");
if (result.getEntryCount() != 1)
{
throw new Exception(String.format(
"Expected one and only one HTTP servlet config monitor entry; " +
"actual number was %d", result.getEntryCount()));
}
SearchResultEntry entry = result.getSearchEntries().get(0);
for (String servletAndPath : entry.getAttributeValues("enabled-servlet-and-path"))
{
final String parsedServletName = parseServletName(servletAndPath);
if (parsedServletName != null)
{
enabledServlets.add(parsedServletName);
}
}
for (String servletToCheck : servletsToCheck)
{
if (enabledServlets.contains(servletToCheck))
{
servletStatuses.add(new ServletStatus(servletToCheck, true));
}
else
{
servletStatuses.add(new ServletStatus(servletToCheck, false));
}
}
}
return servletStatuses;
}
示例9: dnFromUsername
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private String dnFromUsername(String username) throws LDAPException, GeneralSecurityException {
String baseDN = config.getUserBaseDN();
String lookup = String.format("(%s=%s)", config.getUserAttribute(), username);
SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, lookup);
LDAPConnection connection = connectionFactory.getLDAPConnection();
try {
SearchResult sr = connection.search(searchRequest);
if (sr.getEntryCount() == 0) {
throw new LDAPException(ResultCode.INVALID_CREDENTIALS);
}
return sr.getSearchEntries().get(0).getDN();
} finally {
connection.close();
}
}
示例10: scrollSimplePagedResultsControl
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private ASN1OctetString scrollSimplePagedResultsControl(LDAPConnection ldapConnection, String dn, Filter filter, SearchScope scope, Control[] controls, int startIndex) throws LDAPException, InvalidSimplePageControlException {
SearchRequest searchRequest = new SearchRequest(dn, scope, filter, "dn");
int currentStartIndex = startIndex;
ASN1OctetString cookie = null;
do {
int pageSize = Math.min(currentStartIndex, 100);
searchRequest.setControls(new Control[]{new SimplePagedResultsControl(pageSize, cookie, true)});
setControls(searchRequest, controls);
SearchResult searchResult = ldapConnection.search(searchRequest);
currentStartIndex -= searchResult.getEntryCount();
try {
SimplePagedResultsControl c = SimplePagedResultsControl.get(searchResult);
if (c != null) {
cookie = c.getCookie();
}
} catch (LDAPException ex) {
log.error("Error while accessing cookie", ex);
throw new InvalidSimplePageControlException(ex.getResultCode(), "Error while accessing cookie");
}
} while ((cookie != null) && (cookie.getValueLength() > 0) && (currentStartIndex > 0));
return cookie;
}
示例11: lookupDnByUid
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
/**
* Looks the uid in ldap and return the DN
*/
protected String lookupDnByUid(String uid, String baseDN) throws SearchException {
Filter filter = Filter.createEqualityFilter(LdapOperationsServiceImpl.uid, uid);
SearchResult searchResult = search(baseDN, filter, 1, 1);
if ((searchResult != null) && searchResult.getEntryCount() > 0) {
return searchResult.getSearchEntries().get(0).getDN();
}
return null;
}
示例12: contains
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Override
protected boolean contains(String baseDN, Filter filter, String[] objectClasses, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to check contain entries is null");
}
// Create filter
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), 1, 1, null, ldapReturnAttributes);
if ((searchResult == null) || !ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (SearchException ex) {
if (!(ResultCode.NO_SUCH_OBJECT_INT_VALUE == ex.getResultCode())) {
throw new EntryPersistenceException(
String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
}
return (searchResult != null) && (searchResult.getEntryCount() > 0);
}
示例13: getTeamsFromLdap
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
String loggingInUserDN = loggingInUser.getDN();
user.teams.clear(); // Clear the users team memberships - we're going to get them from LDAP
String groupBase = settings.getString(Keys.realm.ldap.groupBase, "");
String groupMemberPattern = settings.getString(Keys.realm.ldap.groupMemberPattern, "(&(objectClass=group)(member=${dn}))");
groupMemberPattern = StringUtils.replace(groupMemberPattern, "${dn}", escapeLDAPSearchFilter(loggingInUserDN));
groupMemberPattern = StringUtils.replace(groupMemberPattern, "${username}", escapeLDAPSearchFilter(simpleUsername));
// Fill in attributes into groupMemberPattern
for (Attribute userAttribute : loggingInUser.getAttributes())
groupMemberPattern = StringUtils.replace(groupMemberPattern, "${" + userAttribute.getName() + "}", escapeLDAPSearchFilter(userAttribute.getValue()));
SearchResult teamMembershipResult = doSearch(ldapConnection, groupBase, groupMemberPattern);
if (teamMembershipResult != null && teamMembershipResult.getEntryCount() > 0) {
for (int i = 0; i < teamMembershipResult.getEntryCount(); i++) {
SearchResultEntry teamEntry = teamMembershipResult.getSearchEntries().get(i);
String teamName = teamEntry.getAttribute("cn").getValue();
TeamModel teamModel = getTeamModel(teamName);
if (teamModel == null)
teamModel = createTeamFromLdap(teamEntry);
user.teams.add(teamModel);
teamModel.addUser(user.getName());
}
}
}
示例14: authenticate
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Override
public Account authenticate(final String username, final String password) {
LDAPConnection ldapConnection = getLdapConnection();
if (ldapConnection != null) {
try {
boolean alreadyAuthenticated = false;
if (!Strings.isNullOrEmpty(ldapBindPattern)) {
try {
String bindUser = ldapBindPattern.replace("${username}", escapeLDAPSearchFilter(username));
ldapConnection.bind(bindUser, password);
alreadyAuthenticated = true;
} catch (LDAPException e) {
return null;
}
}
// Find the logging in user's DN
String searchPattern = accountPattern.replace("${username}", escapeLDAPSearchFilter(username));
SearchResult result = doSearch(ldapConnection, accountBase, searchPattern);
if (result != null && result.getEntryCount() == 1) {
SearchResultEntry accountSearchResult = result.getSearchEntries().get(0);
String accountDN = accountSearchResult.getDN();
if (alreadyAuthenticated || isAuthenticated(ldapConnection, accountDN, password)) {
log.debug("Authentication succeeded for '{}' against '{}'", username, getRealmName());
Account account = null;
synchronized (this) {
account = new Account(username, new StandardCredentials(username, password));
setAccountRoles(ldapConnection, accountSearchResult, account);
setAccountAttributes(accountSearchResult, account);
cacheAccount(account);
}
return account;
} else {
log.debug("Authentication failed for '{}' against '{}'", username, getRealmName());
}
} else if (result == null || result.getSearchEntries().size() == 0) {
log.debug("No account found for '{}' in '{}'", username, getRealmName());
}
} finally {
ldapConnection.close();
}
}
return null;
}
示例15: findEntries
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Override
public <T> List<T> findEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, BatchOperation<T> batchOperation, int startIndex, int sizeLimit, int chunkSize) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getLdapAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(scope), batchOperation, startIndex, chunkSize, sizeLimit, null, currentLdapReturnAttributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter),
ex);
}
if (searchResult.getEntryCount() == 0) {
return new ArrayList<T>(0);
}
List<T> entries = createEntities(entryClass, propertiesAnnotations,
searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
// Default sort if needed
sortEntriesIfNeeded(entryClass, entries);
return entries;
}