我已经使用Apache director studio设置了一个ldap服务器:
这是我的代码:
import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.ldap.sdk.*;
import com.unboundid.ldap.sdk.controls.SimplePagedResultsControl;
public class App {
/**
* @param args
* @throws LDAPException
*/
public static void main(String[] args) throws LDAPException {
LDAPConnection connection = new LDAPConnection("localhost", 10389, "uid=admin,ou=system","secret");//"cn=admin4directory,dc=ilex-si,dc=eu", "M3d2p5a4!");
//SearchRequest searchRequest = new SearchRequest("ou=people,dc=ilex-si,dc=eu", SearchScope.SUB,"(ixuid=*)");
SearchRequest searchRequest = new SearchRequest("ou=people,dc=example,dc=com", SearchScope.BASE,Filter.createEqualityFilter("objectClass", "person"));
ASN1OctetString cookie = null;
do
{
searchRequest.setControls(
new Control[] { new SimplePagedResultsControl(500, cookie) });
SearchResult searchResult = connection.search(searchRequest);
// Do something with the entries that are returned.
cookie = null;
for (Control c : searchResult.getResponseControls())
{
if (c instanceof SimplePagedResultsControl)
{
cookie = ((SimplePagedResultsControl) c).getCookie();
System.out.println("\ncookie = "+ cookie.toString());
}
}
} while ((cookie != null) && (cookie.getValueLength() > 0));
connection.close();
}
}
我想进行分页查询,但是使用此代码我返回了一个空白cookie。 如何打印cn = john smit和cn robert smith值?
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.abc</groupId>
<artifactId>LDAPPagedQueryExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LDAPPagedQueryExample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools</groupId>
<artifactId>maven-mule-plugin</artifactId>
<version>1.6</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
谢谢。
答案 0 :(得分:0)
您确定SearchScope.BASE必须至少为SearchScope.ONE或更好的SearchScope.SUB。
不确定隐含的是什么“如何打印cn = john smit和cn robert smith值?”