Search in sources :

Example 11 with ZSearchControls

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;
    }
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)

Example 12 with ZSearchControls

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;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) AddressList(com.zimbra.cs.account.AddressList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 13 with ZSearchControls

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;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 14 with ZSearchControls

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);
        }
        */
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 15 with ZSearchControls

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);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)15 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)14 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)12 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)10 ServiceException (com.zimbra.common.service.ServiceException)5 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)4 ArrayList (java.util.ArrayList)3 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)2 HashSet (java.util.HashSet)2 AddressList (com.zimbra.cs.account.AddressList)1 DistributionList (com.zimbra.cs.account.DistributionList)1 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 GenericLdapConfig (com.zimbra.cs.ldap.LdapServerConfig.GenericLdapConfig)1 TODOEXCEPTIONMAPPING (com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)1 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 TestLdapZLdapFilter (com.zimbra.qa.unittest.prov.ldap.TestLdapZLdapFilter)1