Search in sources :

Example 1 with ZSearchResultEntry

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

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

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

the class LdapProvisioning method getDataSourcesByQuery.

private List<DataSource> getDataSourcesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
    List<DataSource> result = new ArrayList<DataSource>();
    try {
        String base = entry.getDN();
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            result.add(new LdapDataSource((Account) entry, sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup data source via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) 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) DataSource(com.zimbra.cs.account.DataSource) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 4 with ZSearchResultEntry

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

the class LdapProvisioning method getGroupByQuery.

private Group getGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly, boolean loadFromMaster) throws ServiceException {
    try {
        String[] returnAttrs = basicAttrsOnly ? BASIC_GROUP_ATTRS : null;
        ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, loadFromMaster, returnAttrs);
        if (sr != null) {
            ZAttributes attrs = sr.getAttributes();
            List<String> objectclass = attrs.getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
            Group grp = null;
            if (objectclass.contains(AttributeClass.OC_zimbraDistributionList)) {
                grp = makeDistributionList(sr.getDN(), attrs, basicAttrsOnly);
            } else if (objectclass.contains(AttributeClass.OC_zimbraGroup)) {
                grp = makeDynamicGroup(initZlc, sr.getDN(), attrs);
            }
            if (grp != null && objectclass != null && objectclass.contains(AttributeClass.OC_zimbraHabGroup)) {
                grp.setHABGroup(Boolean.TRUE);
            }
            return grp;
        }
    } catch (LdapMultipleEntriesMatchedException e) {
        throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getGroupByQuery", e);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup group via query: " + filter.toFilterString() + " message:" + e.getMessage(), e);
    }
    return null;
}
Also used : Group(com.zimbra.cs.account.Group) 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) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 5 with ZSearchResultEntry

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

the class LdapProvisioning method getIdentitiesByQuery.

private List<Identity> getIdentitiesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
    List<Identity> result = new ArrayList<Identity>();
    try {
        String base = entry.getDN();
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            result.add(new LdapIdentity((Account) entry, sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup identity via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) 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) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity)

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