当前位置: 首页>>代码示例>>Java>>正文


Java SearchResult类代码示例

本文整理汇总了Java中com.unboundid.ldap.sdk.SearchResult的典型用法代码示例。如果您正苦于以下问题:Java SearchResult类的具体用法?Java SearchResult怎么用?Java SearchResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SearchResult类属于com.unboundid.ldap.sdk包,在下文中一共展示了SearchResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rolesFromDN

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
private Set<String> rolesFromDN(String userDN) throws LDAPException, GeneralSecurityException {
  SearchRequest searchRequest = new SearchRequest(config.getRoleBaseDN(),
      SearchScope.SUB, Filter.createEqualityFilter("uniqueMember", userDN));
  Set<String> roles = Sets.newLinkedHashSet();

  LDAPConnection connection = connectionFactory.getLDAPConnection();
  try {
    SearchResult sr = connection.search(searchRequest);

    for (SearchResultEntry sre : sr.getSearchEntries()) {
      X500Name x500Name = new X500Name(sre.getDN());
      RDN[] rdns = x500Name.getRDNs(BCStyle.CN);
      if (rdns.length == 0) {
        logger.error("Could not create X500 Name for role:" + sre.getDN());
      } else {
        String commonName = IETFUtils.valueToString(rdns[0].getFirst().getValue());
        roles.add(commonName);
      }
    }
  } finally {
    connection.close();
  }

  return roles;
}
 
开发者ID:square,项目名称:keywhiz,代码行数:26,代码来源:LdapAuthenticator.java

示例2: 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;
  }
}
 
开发者ID:sinnerschrader,项目名称:SkillWill,代码行数:18,代码来源:LdapService.java

示例3: 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;
  }
}
 
开发者ID:sinnerschrader,项目名称:SkillWill,代码行数:17,代码来源:LdapService.java

示例4: getLoadBalancingAlgorithmStatuses

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
private List<LoadBalancingAlgorithmStatus> getLoadBalancingAlgorithmStatuses()
        throws LDAPException
{
  List<LoadBalancingAlgorithmStatus> lbaStatuses = new ArrayList<>();
  SearchResult result =
          findMonitorEntries("ds-load-balancing-algorithm-monitor-entry", "*");
  for (SearchResultEntry entry : result.getSearchEntries())
  {
    lbaStatuses.add(new LoadBalancingAlgorithmStatus(
            entry.getAttributeValue("algorithm-name"),
            parseAvailabilityString(entry.getAttributeValue("health-check-state")),
            entry.getAttributeValueAsInteger("num-available-servers"),
            entry.getAttributeValueAsInteger("num-degraded-servers"),
            entry.getAttributeValueAsInteger("num-unavailable-servers")));
  }
  return lbaStatuses;
}
 
开发者ID:pingidentity,项目名称:status-servlet,代码行数:18,代码来源:StatusClient.java

示例5: doSearch

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
private SearchResult doSearch(LDAPConnection ldapConnection, String base, boolean dereferenceAliases, String filter, List<String> attributes) {
    try {
        SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
        if (dereferenceAliases) {
            searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
        }
        if (attributes != null) {
            searchRequest.setAttributes(attributes);
        }
        return ldapConnection.search(searchRequest);

    } catch (LDAPException e) {
        if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
            log.error(e.getDiagnosticMessage());
        } else {
            log.error("Problem searching LDAP", e);
        }
        return null;
    }
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:21,代码来源:LdapRealm.java

示例6: 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);
        }
    }
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:22,代码来源:LdapRealm.java

示例7: getUserRoles

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
@Override
public Set<String> getUserRoles(String username) throws Exception {
    LOGGER.debug("getRoles("+username+")");

    Objects.requireNonNull(username);

    Set<String> roles = new HashSet<>();

    String filter = "(uid=" + username + ")";

    SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter);
    SearchResult searchResult = connectionPool.search(searchRequest);
    List<SearchResultEntry> searchResultEntries = searchResult.getSearchEntries();

    if(searchResultEntries.isEmpty()) {
        LOGGER.warn("No result found roles for user: " + username);
        return new HashSet<String>();
    } else if (searchResultEntries.size() > 1) {
        LOGGER.error("Multiples users found and only one was expected for user: " + username);
        return new HashSet<String>();
    } else {
        for(SearchResultEntry searchResultEntry : searchResultEntries) {
            String[] groups = searchResultEntry.getAttributeValues("memberOf");
            if(null != groups) {
                for(String group : groups) {
                    for (RDN rdn : new DN(group).getRDNs()) {
                        if (rdn.hasAttribute("cn")) {
                            roles.addAll(Arrays.asList(rdn.getAttributeValues()));
                            break;
                        }
                    }
                }
            }
        }
    }

    return roles;
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:39,代码来源:LdapRolesProvider.java

示例8: 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);
   	}
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:23,代码来源:LdapEntryManager.java

示例9: 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;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:25,代码来源:LdapEntryManager.java

示例10: 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;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:26,代码来源:LdapEntryManager.java

示例11: runSearch

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
private void runSearch(LDAPConnection connection, SearchRequest searchRequest, CRUDOperationContext ctx, SearchResultProcessor searchRunner) {
    execute(ctx, new ExecutionHandler() {

        @Override
        void onSuccess(LDAPResult searchResult) {
            for (SearchResultEntry entry : ((SearchResult) searchResult).getSearchEntries()) {
                searchRunner.process(entry);
            }
        }

        @Override
        SearchResult execute() throws LDAPException {
            return connection.search(searchRequest);
        }
    });
}
 
开发者ID:lightblue-platform,项目名称:lightblue-ldap,代码行数:17,代码来源:LdapCRUDController.java

示例12: getUsers

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
@Override
public List<org.geomajas.security.UserInfo> getUsers(UserFilter userFilter) {
	List<org.geomajas.security.UserInfo> users = new ArrayList<org.geomajas.security.UserInfo>();
	if (allUsersDn == null) {
		log.warn("Getting users from LDAP requires configuration of allUsersDn property");
	} else {
		SearchRequest request = createSearchRequest(allUsersDn);
		LdapFilterVisitor visitor = new LdapFilterVisitor();
		Filter ldapFilter = (Filter) userFilter.accept(visitor, null);
		if (ldapFilter != null) {
			Filter f = request.getFilter();
			request.setFilter(Filter.createANDFilter(f, ldapFilter));
		}
		SearchResult result = execute(request, null, null);
		if (result != null) {
			for (SearchResultEntry entry : result.getSearchEntries()) {
				users.add(getUserInfo(entry));
			}
		}
	}
	return users;
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:23,代码来源:LdapAuthenticationService.java

示例13: search

import com.unboundid.ldap.sdk.SearchResult; //导入依赖的package包/类
@Override
public void search(SearchScope scope, String filter, String[] attributes,
    Handler<AsyncResult<SearchResult>> resultHandler) {
  
  if(attributes == null) attributes = new String[] {};

  try {

    SearchRequest request = new SearchRequest(config.getSearchBase(), scope, filter,
        attributes);
    resultHandler.handle(Future.<SearchResult>succeededFuture(getConnection().search(request)));
  } catch (Throwable t) {

    resultHandler.handle(Future.failedFuture(t));
  }
}
 
开发者ID:jspare-projects,项目名称:vertx-jspare,代码行数:17,代码来源:LdapClientImpl.java

示例14: 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"));
}
 
开发者ID:pingidentity,项目名称:status-servlet,代码行数:16,代码来源:StatusClient.java

示例15: 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;
}
 
开发者ID:pingidentity,项目名称:status-servlet,代码行数:39,代码来源:StatusClient.java


注:本文中的com.unboundid.ldap.sdk.SearchResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。