本文整理汇总了Java中com.unboundid.ldap.sdk.SearchResult.getSearchEntries方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getSearchEntries方法的具体用法?Java SearchResult.getSearchEntries怎么用?Java SearchResult.getSearchEntries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.unboundid.ldap.sdk.SearchResult
的用法示例。
在下文中一共展示了SearchResult.getSearchEntries方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: 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;
}
示例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: 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;
}
示例8: getStoreAdapterStatuses
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private List<StoreAdapterStatus> getStoreAdapterStatuses() throws LDAPException
{
List<StoreAdapterStatus> storeAdapterStatuses = new ArrayList<>();
SearchResult result =
findMonitorEntries("ds-store-adapter-monitor-entry",
"store-adapter-name", "store-adapter-status");
for (SearchResultEntry entry : result.getSearchEntries())
{
storeAdapterStatuses.add(new StoreAdapterStatus(
entry.getAttributeValue("store-adapter-name"),
parseAvailabilityString(entry.getAttributeValue("store-adapter-status"))));
}
return storeAdapterStatuses;
}
示例9: getPasswordLastSet
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private long getPasswordLastSet() {
long pwdLastSet = -1;
LDAPConnection ldapConnection = null;
try {
ldapConnection = getLdapConnection(userDn, getLdapPassword(), url);
String[] attributes = new String[] {Constants.AD_PWD_LAST_SET};
String filter = "(" + Constants.AD_SAM_ACCOUNT_NAME + "=" + username + ")";
SearchResult searchResult = ldapConnection.search(baseDn, SearchScope.SUB, filter, attributes);
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
Attribute pwdLastSetAttribute = searchResultEntry.getAttribute(Constants.AD_PWD_LAST_SET);
pwdLastSet = pwdLastSetAttribute.getValueAsLong();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return pwdLastSet;
}
示例10: getMaxPasswordAge
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
private long getMaxPasswordAge() {
long maxPwdAge = -1;
LDAPConnection ldapConnection = null;
try {
ldapConnection = getLdapConnection(userDn, getLdapPassword(), url);
String[] attributes = new String[] {Constants.AD_MAX_PWD_AGE};
String filter = "(" + Constants.AD_OBJECT_CLASS + "=" + Constants.AD_DOMAIN + ")";
SearchResult searchResult = ldapConnection.search(baseDn, SearchScope.BASE, filter, attributes);
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
Attribute maxPwdAgeAttribute = searchResultEntry.getAttribute(Constants.AD_MAX_PWD_AGE);
maxPwdAge = maxPwdAgeAttribute.getValueAsLong();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return maxPwdAge;
}
示例11: testInMemBind
import com.unboundid.ldap.sdk.SearchResult; //导入方法依赖的package包/类
@Test
public void testInMemBind() throws Exception {
String user = "cn=test,dc=staticsecurity,dc=geomajas,dc=org";
LDAPConnection connection = new LDAPConnection("localhost", PORT);
BindResult auth = connection.bind(user, "cred");
System.out.println("auth " + auth);
System.out.println(" rc " + auth.getResultCode());
System.out.println(" cu " + auth.getResultCode().isConnectionUsable());
System.out.println(" dn " + auth.getMatchedDN());
System.out.println(" dm " + auth.getDiagnosticMessage());
SearchRequest request = new SearchRequest(user,
SearchScope.ONE, Filter.createEqualityFilter("objectclass", "person"),
"cn", "groupMembership", "givenName", "sn", "ou");
SearchResult search = connection.search(request);
System.out.println(search);
System.out.println("count " + search.getEntryCount());
System.out.println("count " + search.getSearchEntries());
for (SearchResultEntry se : search.getSearchEntries()) {
System.out.println("-- cn " + se.getAttributeValue("cn"));
System.out.println(" givenName " + se.getAttributeValue("givenName"));
System.out.println(" sn " + se.getAttributeValue("sn"));
System.out.println(" ou " + se.getAttributeValue("ou"));
System.out.println(" groupMembership ");
if (null != se.getAttributeValues("groupMembership")) {
for (String val : se.getAttributeValues("groupMembership")) {
System.out.println(" " + val);
}
}
}
}