本文整理汇总了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;
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
}
}
}