Search in sources :

Example 21 with ZSearchResultEntry

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

the class LdapProvisioning method getAllUCServices.

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

Example 22 with ZSearchResultEntry

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

the class LdapProvisioning method getAddressListByQuery.

private List<AddressListInfo> getAddressListByQuery(String base, ZLdapFilter filter, boolean activeOnly, boolean getDN) throws ServiceException {
    List<AddressListInfo> result = new ArrayList<AddressListInfo>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), null, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            if (getDN) {
                AddressListInfo adl = new AddressListInfo(sr.getDN());
                result.add(adl);
            } else {
                ZAttributes attrs = sr.getAttributes();
                if (attrs != null) {
                    boolean active = Boolean.parseBoolean(attrs.getAttrString(Provisioning.A_zimbraIsAddressListActive));
                    boolean addToRes = activeOnly ? active : Boolean.TRUE;
                    if (addToRes) {
                        AddressListInfo adl = new AddressListInfo(attrs.getAttrString(Provisioning.A_zimbraId), attrs.getAttrString(Provisioning.A_uid), attrs.getAttrString(Provisioning.A_description));
                        if (!activeOnly) {
                            adl.setActive(active);
                            adl.setGalFilter(attrs.getAttrString(Provisioning.A_zimbraAddressListGalFilter));
                            adl.setLdapFilter(attrs.getAttrString(Provisioning.A_zimbraAddressListLdapFilter));
                        }
                        result.add(adl);
                    }
                }
            }
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup address lists via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) 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) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 23 with ZSearchResultEntry

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

the class LdapProvisioning method listAllZimlets.

@Override
public List<Zimlet> listAllZimlets() throws ServiceException {
    List<Zimlet> result = new ArrayList<Zimlet>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.zimletBaseDN(), filterFactory.allZimlets(), ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            result.add(new LdapZimlet(sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all zimlets", e);
    }
    Collections.sort(result);
    return result;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) 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) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 24 with ZSearchResultEntry

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

the class LdapProvisioning method getMimeTypesByQuery.

@Override
public List<MimeTypeInfo> getMimeTypesByQuery(String mimeType) throws ServiceException {
    List<MimeTypeInfo> mimeTypes = new ArrayList<MimeTypeInfo>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.mimeBaseDN(), filterFactory.mimeEntryByMimeType(mimeType), ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            mimeTypes.add(new LdapMimeType(sr, this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to get mime types for " + mimeType, e);
    }
    return mimeTypes;
}
Also used : LdapMimeType(com.zimbra.cs.account.ldap.entry.LdapMimeType) 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) MimeTypeInfo(com.zimbra.cs.mime.MimeTypeInfo) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 25 with ZSearchResultEntry

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

the class LdapProvisioning method getDistributionListByQuery.

private DistributionList getDistributionListByQuery(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
    String[] returnAttrs = basicAttrsOnly ? BASIC_DL_ATTRS : null;
    DistributionList dl = null;
    try {
        ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, searchControls, initZlc, LdapServerType.REPLICA);
        if (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            dl = makeDistributionList(sr.getDN(), sr.getAttributes(), basicAttrsOnly);
            List<String> objectclass = sr.getAttributes().getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
            if (dl != null && objectclass != null && objectclass.contains(AttributeClass.OC_zimbraHabGroup)) {
                dl.setHABGroup(Boolean.TRUE);
            }
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup distribution list via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return dl;
}
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) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

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