Search in sources :

Example 1 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllServers.

@Override
public List<Server> getAllServers(String service) throws ServiceException {
    List<Server> result = new ArrayList<Server>();
    ZLdapFilter filter;
    if (service != null) {
        filter = filterFactory.serverByService(service);
    } else {
        filter = filterFactory.allServers();
    }
    try {
        Map<String, Object> serverDefaults = getConfig().getServerDefaults();
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.serverBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapServer s = new LdapServer(sr.getDN(), sr.getAttributes(), serverDefaults, this);
            result.add(s);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all servers", e);
    }
    if (result.size() > 0)
        serverCache.put(result, true);
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) 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) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 2 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllAlwaysOnClusters.

@Override
public List<AlwaysOnCluster> getAllAlwaysOnClusters() throws ServiceException {
    List<AlwaysOnCluster> result = new ArrayList<AlwaysOnCluster>();
    ZLdapFilter filter = filterFactory.allAlwaysOnClusters();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.alwaysOnClusterBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapAlwaysOnCluster c = new LdapAlwaysOnCluster(sr.getDN(), sr.getAttributes(), null, this);
            result.add(c);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all alwaysOnClusters", e);
    }
    if (result.size() > 0)
        alwaysOnClusterCache.put(result, true);
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) 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) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 3 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.

the class LdapProvisioning method isEmptyOu.

/**
 * @param habOrgUnitName  organizational unit name
 * @param domainDn the domain distinguishedd name
 * @return true if the ou has groups or false if empty
 * @throws ServiceException
 */
private static boolean isEmptyOu(String habOrgUnitName, String domainDn) throws ServiceException {
    ZLdapContext zlc = null;
    boolean empty = false;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_OU);
        String baseDN = createOuDn(habOrgUnitName, domainDn);
        String filter = "(objectClass=zimbraDistributionList)";
        String[] returnAttrs = new String[] { "cn" };
        ZLdapFilter zFilter = ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ALL_DISTRIBUTION_LISTS, filter);
        ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
        ZSearchResultEnumeration ne = zlc.searchDir(baseDN, zFilter, searchControls);
        empty = !ne.hasMore();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE(String.format("Unable to delete HAB org unit: %s for domain=%s", habOrgUnitName, domainDn), e);
    } finally {
        LdapClient.closeContext(zlc);
    }
    return empty;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) 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)

Example 4 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllXMPPComponents.

@Override
public List<XMPPComponent> getAllXMPPComponents() throws ServiceException {
    List<XMPPComponent> result = new ArrayList<XMPPComponent>();
    try {
        String base = mDIT.xmppcomponentBaseDN();
        ZLdapFilter filter = filterFactory.allXMPPComponents();
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapXMPPComponent x = new LdapXMPPComponent(sr.getDN(), sr.getAttributes(), this);
            result.add(x);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all XMPPComponents", e);
    }
    if (result.size() > 0) {
        xmppComponentCache.put(result, true);
    }
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) 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) ArrayList(java.util.ArrayList) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 5 with ZLdapFilter

use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.

the class LdapProvisioning method getDNforAccountById.

public String getDNforAccountById(String zimbraId, ZLdapContext zlc, boolean loadFromMaster) {
    if (zimbraId == null) {
        return null;
    }
    ZLdapFilter filter = filterFactory.accountById(zimbraId);
    try {
        String[] retAttrs = new String[] { Provisioning.A_zimbraId };
        /* Just 1 attr to save bandwidth */
        ZSearchResultEntry sr;
        sr = getSearchResultForAccountByQuery(mDIT.mailBranchBaseDN(), filter, zlc, loadFromMaster, retAttrs);
        // search again under the admin base if not found and admin base is not under mail base
        if (sr == null && !mDIT.isUnder(mDIT.mailBranchBaseDN(), mDIT.adminBaseDN())) {
            sr = getSearchResultForAccountByQuery(mDIT.adminBaseDN(), filter, zlc, loadFromMaster, retAttrs);
        }
        if (sr != null) {
            return sr.getDN();
        }
    } catch (ServiceException e) {
        ZimbraLog.search.debug("unable to lookup DN for account via query: %s", filter.toFilterString(), e);
    }
    return null;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)123 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)15 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)13 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)10 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)10 ServiceException (com.zimbra.common.service.ServiceException)9 AccountServiceException (com.zimbra.cs.account.AccountServiceException)8 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)8 ArrayList (java.util.ArrayList)8 Server (com.zimbra.cs.account.Server)7 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)7 Account (com.zimbra.cs.account.Account)6 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)6 NamedEntry (com.zimbra.cs.account.NamedEntry)5 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)5 BySearchResultEntrySearcher (com.zimbra.cs.account.ldap.BySearchResultEntrySearcher)5 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)5 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)3