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


Java LDAPConnection.search方法代码示例

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


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

示例1: rolesFromDN

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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: doSearch

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

示例3: dnFromUsername

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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();
  }
}
 
开发者ID:square,项目名称:keywhiz,代码行数:19,代码来源:LdapAuthenticator.java

示例4: scrollSimplePagedResultsControl

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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;
}
 
开发者ID:GluuFederation,项目名称:oxCore,代码行数:26,代码来源:LdapOperationsServiceImpl.java

示例5: getPasswordLastSet

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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;
	}
 
开发者ID:chrisipa,项目名称:ad-password-handler,代码行数:28,代码来源:PasswordExpirationHandler.java

示例6: getMaxPasswordAge

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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;
}
 
开发者ID:chrisipa,项目名称:ad-password-handler,代码行数:28,代码来源:PasswordExpirationHandler.java

示例7: doSearch

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的package包/类
private SearchResult doSearch(LDAPConnection ldapConnection, String base, String filter) {
	try {
		return ldapConnection.search(base, SearchScope.SUB, filter);
	} catch (LDAPSearchException e) {
		logger.error("Problem Searching LDAP", e);
		
		return null;
	}
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:10,代码来源:LdapUserService.java

示例8: testInMemBind

import com.unboundid.ldap.sdk.LDAPConnection; //导入方法依赖的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);
			}
		}
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:33,代码来源:LdapTest.java


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