conn.connect(LDAP_HOST, LDAP_PORT);
// conn.authenticate("cn=Manager,dc=example,dc=com", "secret");
conn.bind(ldapVersion, ROOT_DN, ROOT_PASSWORD.getBytes("utf-8"));
System.out.println("========> create ldap entry " + EXO_DEVELOPER_DN);
LDAPAttributeSet attributeSet = new LDAPAttributeSet();
attributeSet.add(new LDAPAttribute("objectClass", "person"));
attributeSet.add(new LDAPAttribute("cn", "exo"));
attributeSet.add(new LDAPAttribute("sn", "platform"));
attributeSet.add(new LDAPAttribute("telephonenumber", "0989654990"));
LDAPEntry newEntry = new LDAPEntry(EXO_DEVELOPER_DN, attributeSet);
conn.add(newEntry);
System.out.println("<======Added object: " + EXO_DEVELOPER_DN + " successfully.");
System.out.println("\nAdded object: " + EXO_DEVELOPER_DN + " successfully.");
LDAPSearchResults results = conn.search(DEVELOPER_UNIT_DN, // search only
// the object in
// the subtree of
// this dn
LDAPConnection.SCOPE_SUB, // return
// all the
// objects
// that
// match
// the
// filter
// criteria
// and in
// the sub
// tree
"(objectclass=person)", // query
// filter, (
// objectclass
// =*) for
// all the
// object
null, // return all the attributes
// of the object
false); // return attrs and values
// assertEquals("Expect to find 1 entry", 1, results.getCount()) ;
while (results.hasMore())
{
LDAPEntry nextEntry = null;
nextEntry = results.next();
System.out.println("\n entry: " + nextEntry.getDN());
System.out.println(" Attributes: ");
LDAPAttributeSet attrs = nextEntry.getAttributeSet();
printLDAPAttributeSet(attrs);
}
System.out.println(" ---> count: " + results.getCount());
System.out.println("<======search " + DEVELOPER_UNIT_DN + " successfully.");
// delete the new created ldap entry