Search in sources :

Example 6 with ZSearchResultEntry

use of com.zimbra.cs.ldap.ZSearchResultEntry 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 7 with ZSearchResultEntry

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

the class LdapProvisioning method searchCOS.

private List<Cos> searchCOS(ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
    List<Cos> result = new ArrayList<Cos>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.cosBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            result.add(new LdapCos(sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup cos via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 8 with ZSearchResultEntry

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

the class LdapProvisioning method getDynamicGroupByQuery.

private DynamicGroup getDynamicGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
    try {
        String[] returnAttrs = basicAttrsOnly ? BASIC_DYNAMIC_GROUP_ATTRS : null;
        ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, false, returnAttrs);
        if (sr != null) {
            DynamicGroup grp = makeDynamicGroup(initZlc, sr.getDN(), sr.getAttributes());
            List<String> objectclass = sr.getAttributes().getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
            if (grp != null && objectclass != null && objectclass.contains(AttributeClass.OC_zimbraHabGroup)) {
                grp.setHABGroup(Boolean.TRUE);
            }
            return grp;
        }
    } catch (LdapMultipleEntriesMatchedException e) {
        throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getDynamicGroupByQuery", e);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup group via query: " + filter.toFilterString() + " message:" + e.getMessage(), e);
    }
    return null;
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapMultipleEntriesMatchedException(com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 9 with ZSearchResultEntry

use of com.zimbra.cs.ldap.ZSearchResultEntry 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)

Example 10 with ZSearchResultEntry

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

the class ZLdapHelper method searchForEntry.

@Override
@TODOEXCEPTIONMAPPING
public ZSearchResultEntry searchForEntry(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean useMaster, String[] returnAttrs) throws LdapMultipleEntriesMatchedException, ServiceException {
    ZLdapContext zlc = initZlc;
    try {
        if (zlc == null) {
            zlc = LdapClient.getContext(LdapServerType.get(useMaster), LdapUsage.SEARCH);
        }
        ZSearchControls sc = (returnAttrs == null) ? ZSearchControls.SEARCH_CTLS_SUBTREE() : ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
        ZSearchResultEnumeration ne = zlc.searchDir(base, filter, sc);
        if (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            if (ne.hasMore()) {
                String dups = LdapUtil.formatMultipleMatchedEntries(sr, ne);
                throw LdapException.MULTIPLE_ENTRIES_MATCHED(base, filter.toFilterString(), dups);
            }
            ne.close();
            return sr;
        }
    /*  all callsites with the following @TODOEXCEPTIONMAPPING pattern can have ease of mind now and remove the
         * TODOEXCEPTIONMAPPING annotation
         *
        } catch (NameNotFoundException e) {
            return null;
        } catch (InvalidNameException e) {
            return null;
        } catch (NamingException e) {
            throw ServiceException.FAILURE("unable to lookup account via query: "+query+" message: "+e.getMessage(), e);
        */
    } finally {
        if (initZlc == null)
            LdapClient.closeContext(zlc);
    }
    return null;
}
Also used : ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) TODOEXCEPTIONMAPPING(com.zimbra.cs.ldap.LdapTODO.TODOEXCEPTIONMAPPING)

Aggregations

ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)35 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)27 ServiceException (com.zimbra.common.service.ServiceException)19 AccountServiceException (com.zimbra.cs.account.AccountServiceException)18 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)18 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)15 ArrayList (java.util.ArrayList)15 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)12 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)6 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)5 LdapMultipleEntriesMatchedException (com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException)3 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)3 ZAttributes (com.zimbra.cs.ldap.ZAttributes)3 Account (com.zimbra.cs.account.Account)2 Cos (com.zimbra.cs.account.Cos)2 DynamicGroup (com.zimbra.cs.account.DynamicGroup)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)2 LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)2 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)2