我是一名大学生,我在springboot中进行了一个应用,以通过ldap对用户进行身份验证。 我可以使用ldap.unboundid做到这一点,但是现在我想显示ldap服务器上所有用户的名称,这是否可能,如果可以,您能举些例子吗?
这是我的代码,可在ldap中对用户进行身份验证:
public class LDAPAuthentication implements Authentication {
LdapConfigurations ldapConfig;
LDAPConnection ldapConnection;
SearchResult searchResult;
public LDAPAuthentication(LdapConfigurations ldapConfig) {
this.ldapConfig = ldapConfig;
}
@Override
public UserEntity authenticate(String username, String password) {
try {
LDAPURL ldapUrl = new LDAPURL(ldapConfig.getUrl());
LDAPConnectionOptions ldapConnectionOptions = new LDAPConnectionOptions();
ldapConnectionOptions.setConnectTimeoutMillis(50);
ldapConnection = new LDAPConnection(ldapConnectionOptions, ldapUrl.getHost(), ldapUrl.getPort(),
username + ldapConfig.getLdapDomain(), password);
ldapConnection.bind(username + ldapConfig.getLdapDomain(), password);
String lookup = String.format("(%s=%s)", "sAMAccountName", username);
SearchRequest searchRequest = new SearchRequest(ldapConfig.getBaseDn(), SearchScope.SUB, lookup);
searchResult = ldapConnection.search(searchRequest);
ldapConnection.close();
} catch (LDAPException e) {
e.printStackTrace();
return null;
}
答案 0 :(得分:1)
如果要查询AD,则需要对AD进行更改,或者需要分页结果。在https://docs.ldap.com/ldap-sdk/docs/getting-started/controls.html上搜索“简单的分页结果控件”