use of com.zimbra.cs.ldap.ZSearchControls in project zm-mailbox by Zimbra.
the class LdapProvisioning method addressExistsUnderDN.
/*
* returns if any one of addrs is an email address under the specified baseDN
*/
private boolean addressExistsUnderDN(ZLdapContext zlc, String baseDN, String[] addrs) throws ServiceException {
ZLdapFilter filter = filterFactory.addrsExist(addrs);
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, 1, null);
try {
long count = helper.countEntries(baseDN, filter, searchControls, zlc, LdapServerType.MASTER);
return count > 0;
} catch (LdapSizeLimitExceededException e) {
return true;
}
}
use of com.zimbra.cs.ldap.ZSearchControls in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAddressList.
/**
* @param id id of the address list
* @return AddressList object
* @throws ServiceException if an error occurs while querying LDAP.
*/
@Override
public AddressList getAddressList(String zimbraId) throws ServiceException {
AddressList list = null;
try {
ZimbraLog.ldap.info("Called addresslist");
String[] returnAttrs = { "objectClass", Provisioning.A_uid, Provisioning.A_zimbraId, Provisioning.A_zimbraAddressListGalFilter, Provisioning.A_description, Provisioning.A_zimbraIsAddressListActive, Provisioning.A_zimbraAddressListLdapFilter };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = helper.searchDir(mDIT.mailBranchBaseDN(), filterFactory.addressListById(zimbraId), searchControls, null, LdapServerType.MASTER);
if (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
String dn = sr.getDN();
ZimbraLog.ldap.debug("Got address list: %s with attributes : %s", dn, sr.getAttributes());
Map<String, Object> attrs = sr.getAttributes().getAttrs();
String name = (String) attrs.get(Provisioning.A_displayName);
list = new AddressList(dn, name, zimbraId, attrs, null, this);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE(String.format("Unable to fetch address list '%s'", zimbraId), e);
}
return list;
}
use of com.zimbra.cs.ldap.ZSearchControls in project zm-mailbox by Zimbra.
the class LdapProvisioning method getEmptyAliasDomainIds.
public List<String> getEmptyAliasDomainIds(ZLdapContext zlc, Domain targetDomain, boolean subordinateCheck) throws ServiceException {
List<String> aliasDomainIds = new ArrayList<String>();
ZSearchResultEnumeration ne = null;
try {
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, new String[] { Provisioning.A_zimbraId, Provisioning.A_zimbraDomainName });
ne = helper.searchDir(mDIT.domainBaseDN(), filterFactory.domainAliases(targetDomain.getId()), searchControls, zlc, LdapServerType.MASTER);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
String aliasDomainId = sr.getAttributes().getAttrString(Provisioning.A_zimbraId);
String aliasDomainName = sr.getAttributes().getAttrString(Provisioning.A_zimbraDomainName);
// make sure the alias domain is ready to be deleted
String aliasDomainDn = sr.getDN();
String acctBaseDn = mDIT.domainDNToAccountBaseDN(aliasDomainDn);
String dynGroupsBaseDn = mDIT.domainDNToDynamicGroupsBaseDN(aliasDomainDn);
if (subordinateCheck && (hasSubordinates(zlc, acctBaseDn) || hasSubordinates(zlc, dynGroupsBaseDn))) {
throw ServiceException.FAILURE("alias domain " + aliasDomainName + " of domain " + targetDomain.getName() + " is not empty", null);
}
if (aliasDomainId != null) {
aliasDomainIds.add(aliasDomainId);
}
}
} finally {
ne.close();
}
return aliasDomainIds;
}
use of com.zimbra.cs.ldap.ZSearchControls in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchDirSizeLimitExceeded.
@Test
public void searchDirSizeLimitExceeded() throws Exception {
int SIZE_LIMIT = 5;
String base = LdapConstants.DN_ROOT_DSE;
ZLdapFilter filter = filterFactory.anyEntry();
String[] returnAttrs = new String[] { "objectClass" };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, SIZE_LIMIT, returnAttrs);
int numFound = 0;
boolean caughtException = false;
try {
ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
numFound++;
}
ne.close();
} catch (LdapSizeLimitExceededException e) {
caughtException = true;
}
assertTrue(caughtException);
/*
// unboundid does not return entries if LdapSizeLimitExceededException
// is thrown, See commons on ZLdapContext.searchDir().
if (testConfig != TestLdap.TestConfig.UBID) {
assertEquals(SIZE_LIMIT, numFound);
}
*/
}
use of com.zimbra.cs.ldap.ZSearchControls in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchDirNotFound.
@Test
public void searchDirNotFound() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.allSignatures();
String[] returnAttrs = new String[] { "objectClass" };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
int numFound = 0;
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
numFound++;
}
ne.close();
assertEquals(0, numFound);
}
Aggregations