use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapExample method deleteEntry.
public void deleteEntry() throws Exception {
String dn = "uid=user1,ou=people,dc=test,dc=com";
GenericLdapConfig ldapConfig = getLdapConfig();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(ldapConfig, LdapUsage.DELETE);
zlc.deleteEntry(dn);
} finally {
// Note: this is important!!
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapExample method search.
public void search() throws Exception {
String base = "cn=servers,cn=zimbra";
String filter = "(objectClass=zimbraServer)";
String[] returnAttrs = new String[] { "objectClass", "cn" };
ZLdapFilter zFilter = ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ZMCONFIGD, filter);
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
GenericLdapConfig ldapConfig = getLdapConfig();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(ldapConfig, LdapUsage.SEARCH);
ZSearchResultEnumeration ne = zlc.searchDir(base, zFilter, searchControls);
while (ne.hasMore()) {
ZSearchResultEntry entry = ne.next();
String dn = entry.getDN();
ZAttributes attrs = entry.getAttributes();
String cn = attrs.getAttrString("cn");
String[] objectClasses = attrs.getMultiAttrString("objectClass");
System.out.println("dn = " + dn);
System.out.println("cn = " + cn);
for (String objectClass : objectClasses) {
System.out.println("objetClass = " + objectClass);
}
}
ne.close();
} catch (LdapSizeLimitExceededException e) {
e.printStackTrace();
throw e;
} finally {
// Note: this is important!!
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapExample method createEntry.
public void createEntry() throws Exception {
// dn of entry to create
String dn = "uid=user1,ou=people,dc=test,dc=com";
GenericLdapConfig ldapConfig = getLdapConfig();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(ldapConfig, LdapUsage.ADD);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.setDN(dn);
entry.addAttr("objectClass", "inetOrgPerson");
entry.addAttr("objectClass", "zimbraAccount");
entry.addAttr("objectClass", "amavisAccount");
entry.setAttr("uid", "user1");
entry.setAttr("cn", "user1");
entry.setAttr("sn", "lastname");
entry.setAttr("zimbraAccountStatus", "active");
entry.setAttr("zimbraId", "ba6198a3-bb49-4425-94b0-d4e9354e87b5");
entry.addAttr("mail", "user1@trest.com");
entry.addAttr("mail", "user-one@test.com");
zlc.createEntry(entry);
} finally {
// Note: this is important!!
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class Cleanup method deleteEntireBranchByDN.
// dn itself will also be deleted
private static void deleteEntireBranchByDN(String dn) throws Exception {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UNITTEST);
deleteEntireBranch(zlc, dn);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class Cleanup method deleteAllChildrenUnderDN.
// dn itself will not be deleted
private static void deleteAllChildrenUnderDN(String dn, Set<String> ignoreDNs) throws Exception {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UNITTEST);
List<String> childrenDNs = getDirectChildrenDNs(zlc, dn);
for (String childDN : childrenDNs) {
if (ignoreDNs == null || !ignoreDNs.contains(childDN)) {
deleteEntireBranch(zlc, childDN);
}
}
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations