-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.java
76 lines (60 loc) · 2.29 KB
/
App.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.redhat.cp;
import java.io.PrintStream;
import java.util.List;
import org.apache.directory.api.ldap.model.ldif.LdifReader;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
import org.apache.directory.api.ldap.model.ldif.LdapLdifException;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.ldap.client.api.LdapNetworkConnection;
import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.api.ldap.model.cursor.Cursor;
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
import org.apache.directory.api.ldap.model.entry.Entry;
public class App
{
public App() {}
public static void main(String[] args)
{
try
{
System.out.println("Connecting server ...");
LdapConnection connection = new LdapNetworkConnection( "com", 389 );
EntryCursor cursor = connection.search( "ou=u", "(objectclass=*)", SearchScope.ONELEVEL );
for ( Entry entry : cursor )
{
System.out.println("=============================");
//assertNotNull( entry );
//System.out.println( entry );
System.out.println(entry.get("cn"));
System.out.println(entry.get("memberOf"));
System.out.println(entry.get("rn"));
}
cursor.close();
System.out.println("Closing connection ...");
connection.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
try
{
System.out.println("Openning ldif file locally ...");
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdifFile("allldap.ldif");
//String dn = "cn=ravi ravi,[email protected]";
for (LdifEntry entry : entries) {
String name = entry.getDn().getName();
System.out.println("dn="+name+"EOR");
//if (name.equals(dn)) {
System.out.println(entry.get("cn"));
System.out.println(entry.get("memberOf"));
// System.out.println(entry.get("mail"));
// System.out.println(entry.get("mozillaNickname"));
//}
}
} catch (LdapLdifException e) {
System.out.println("Error: " + e.getMessage());
}
System.out.println("Hello World!");
}
}