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


Java SearchResultEntry类代码示例

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


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

示例1: rolesFromDN

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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: getLoginDn

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
private String getLoginDn(String username) {

		String loginDn = null;

		try {

			Filter userFilter = Filter.create(userSearchFilter);
			Filter loginFilter = getLoginFilter(username);
			Filter filter = Filter.createANDFilter(userFilter, loginFilter);

			List<SearchResultEntry> searchResultEntries = search(filter);
			if (!searchResultEntries.isEmpty()) {
				loginDn = searchResultEntries.get(0).getDN();
			}
		}
		catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}

		return loginDn;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:22,代码来源:DirectoryService.java

示例3: getEntryByMail

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例4: getEntryById

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例5: get

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
public UserLdapDetails get(SearchResultEntry entry) {
  String company = "";
  try {
    company = getCompanyByDn(entry.getParentDNString());
  } catch (LDAPException e) {
    logger.warn("Failed to extract company from entry");
  }

  return new UserLdapDetails(
    entry.getAttributeValue("givenName"),
    entry.getAttributeValue("sn"),
    entry.getAttributeValue("mail"),
    entry.getAttributeValue("telephoneNumber"),
    entry.getAttributeValue("l"),
    entry.getAttributeValue("title"),
    company
  );
}
 
开发者ID:sinnerschrader,项目名称:SkillWill,代码行数:19,代码来源:UserLdapDetailsFactory.java

示例6: getLoadBalancingAlgorithmStatuses

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例7: setup

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
@Before
public void setup() throws Exception {
  LdapLookupConfig config = new LdapLookupConfig("ou=users,dc=example,dc=com",
      "uid", ImmutableSet.of("admin"), "ou=roles,dc=example,dc=com");
  ldapAuthenticator = new LdapAuthenticator(ldapConnectionFactory, config);

  List<SearchResultEntry> dnResults =
      Arrays.asList(new SearchResultEntry(PEOPLE_DN, new Attribute[]{}));
  List<SearchResultEntry> roleResults =
      Arrays.asList(new SearchResultEntry("cn=admin,ou=roles", new Attribute[]{}));

  when(ldapConnectionFactory.getLDAPConnection()).thenReturn(ldapConnection);

  when(ldapConnection.search(argThat(new IsDnSearch()))).thenReturn(dnSearchResult);
  when(dnSearchResult.getEntryCount()).thenReturn(1);
  when(dnSearchResult.getSearchEntries()).thenReturn(dnResults);

  when(ldapConnection.search(argThat(new IsRoleSearch()))).thenReturn(roleSearchResult);
  when(roleSearchResult.getEntryCount()).thenReturn(1);
  when(roleSearchResult.getSearchEntries()).thenReturn(roleResults);
}
 
开发者ID:square,项目名称:keywhiz,代码行数:22,代码来源:LdapAuthenticatorTest.java

示例8: setAccountRoles

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例9: searchAlternateNames

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
private Set<AuthorName> searchAlternateNames(String uid, AuthorName primaryName) {

		Set<AuthorName> alternateNames = new HashSet<AuthorName>();
		String filter = "(&(objectClass=weillCornellEduSORRecord)(weillCornellEduCWID=" + uid + "))";
		List<SearchResultEntry> results = searchWithBaseDN(filter, "ou=sors,dc=weill,dc=cornell,dc=edu");
		for (SearchResultEntry entry : results) {
			AuthorName authorName = new AuthorName(
					entry.getAttributeValue("givenName"),
					entry.getAttributeValue("weillCornellEduMiddleName"),
					entry.getAttributeValue("sn").replace("- M.D.", "")); //Added fix for some surnames having degree in their surnames - M.D.
			if (!primaryName.equals(authorName)) {
				alternateNames.add(authorName);
			}
		}
		return alternateNames;
	}
 
开发者ID:wcmc-its,项目名称:ReCiter,代码行数:17,代码来源:LdapIdentityDaoImpl.java

示例10: getUserRoles

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例11: lookup

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
@Override
public SearchResultEntry lookup(String dn, String... attributes) throws ConnectionException {
	if (StringHelper.equalsIgnoreCase(dn, "o=gluu")) {
		(new Exception()).printStackTrace();
	}

	try {
		if (attributes == null) {
			return getConnectionPool().getEntry(dn);
		} else {
			return getConnectionPool().getEntry(dn, attributes);
		}
	} catch (Exception ex) {
		throw new ConnectionException("Failed to lookup entry", ex);
	}
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:17,代码来源:LdapOperationsServiceImpl.java

示例12: compare

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
public int compare(T entry1, T entry2, String attributeName) {
	Object value1 = ((SearchResultEntry) entry1).getAttribute(attributeName);
	Object value2 = ((SearchResultEntry) entry2).getAttribute(attributeName);

	if ((value1 == null) && (value2 == null)) {
		return 0;
	}
	if ((value1 == null) && (value2 != null)) {
		return -1;
	} else if ((value1 != null) && (value2 == null)) {
		return 1;
	}

	if (value1 instanceof Date) {
		return ((Date) value1).compareTo((Date) value2);
	} else if (value1 instanceof Integer) {
		return ((Integer) value1).compareTo((Integer) value2);
	} else if (value1 instanceof String && value2 instanceof String) {
		if (caseSensetive) {
			return ((String) value1).compareTo((String) value2);
		} else {
			return ((String) value1).toLowerCase().compareTo(((String) value2).toLowerCase());
		}
	}
          return 0;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:27,代码来源:LdapOperationsServiceImpl.java

示例13: getAttributeResultEntryLDIF

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
public List<SearchResultEntry> getAttributeResultEntryLDIF(LDAPConnection connection, List<String> patterns, String baseDN) {
	List<SearchResultEntry> searchResultEntryList = new ArrayList<SearchResultEntry>();
	try {
		for (String pattern : patterns) {
			String[] targetArray = new String[] { pattern };
			Filter inumFilter = Filter.createSubstringFilter("inum", null,targetArray, null);
			Filter searchFilter = Filter.createORFilter(inumFilter);
			SearchResultEntry sr = connection.searchForEntry(baseDN,SearchScope.SUB, searchFilter, null);
			searchResultEntryList.add(sr);
		}

		return searchResultEntryList;
	} catch (LDAPException le) {
		if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
			log.error("Failed to search ldif record", le);
			return null;
		}
	}
	return null;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:21,代码来源:LdifDataUtility.java

示例14: removeSubtreeThroughIteration

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的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

示例15: find

import com.unboundid.ldap.sdk.SearchResultEntry; //导入依赖的package包/类
@Override
protected List<AttributeData> find(String dn, String ... ldapReturnAttributes) {
	// Load entry

	try {
		SearchResultEntry entry = this.ldapOperationService.lookup(dn, ldapReturnAttributes);
		List<AttributeData> result = getAttributeDataList(entry);
		if (result != null) {
			return result;
		}
	} catch (Exception ex) {
		throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
	}

	throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:17,代码来源:LdapEntryManager.java


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