Search in sources :

Example 26 with ZSearchResultEntry

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

the class LdapProvisioning method getAllCos.

@Override
public List<Cos> getAllCos() throws ServiceException {
    List<Cos> result = new ArrayList<Cos>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.cosBaseDN(), filterFactory.allCoses(), ZSearchControls.SEARCH_CTLS_SUBTREE());
        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 list all COS", e);
    }
    Collections.sort(result);
    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 27 with ZSearchResultEntry

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

the class ExternalGroup method searchGroup.

private static ExternalGroup searchGroup(DomainBy domainBy, String extGroupGrantee, boolean asAdmin) throws ServiceException {
    LdapProv prov = LdapProv.getInst();
    ExternalGroupInfo extGrpInfo = ExternalGroupInfo.parse(extGroupGrantee);
    String zimbraDomain = extGrpInfo.getZimbraDmain();
    String extGroupName = extGrpInfo.getExternalGroupName();
    Domain domain = prov.get(domainBy, zimbraDomain);
    if (domain == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(zimbraDomain);
    }
    String searchBase = domain.getExternalGroupLdapSearchBase();
    String filterTemplate = domain.getExternalGroupLdapSearchFilter();
    if (searchBase == null) {
        searchBase = LdapConstants.DN_ROOT_DSE;
    }
    String searchFilter = LdapUtil.computeDn(extGroupName, filterTemplate);
    GroupHandler groupHandler = getGroupHandler(domain);
    ZLdapContext zlc = null;
    try {
        zlc = groupHandler.getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);
        ZSearchResultEntry entry = prov.getHelper().searchForEntry(searchBase, FilterId.EXTERNAL_GROUP, searchFilter, zlc, new String[] { "mail" });
        if (entry != null) {
            return makeExternalGroup(domain, groupHandler, extGroupName, entry.getDN(), entry.getAttributes());
        } else {
            return null;
        }
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) GroupHandler(com.zimbra.cs.account.grouphandler.GroupHandler) Domain(com.zimbra.cs.account.Domain) ExternalGroupInfo(com.zimbra.cs.account.accesscontrol.ZimbraACE.ExternalGroupInfo) LdapProv(com.zimbra.cs.account.ldap.LdapProv) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 28 with ZSearchResultEntry

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

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

the class LdapProvisioning method getAllMimeTypesByQuery.

@Override
public List<MimeTypeInfo> getAllMimeTypesByQuery() throws ServiceException {
    List<MimeTypeInfo> mimeTypes = new ArrayList<MimeTypeInfo>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(mDIT.mimeBaseDN(), filterFactory.allMimeEntries(), 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", 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 30 with ZSearchResultEntry

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

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