Search in sources :

Example 1 with AlwaysOnCluster

use of com.zimbra.cs.account.AlwaysOnCluster 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 2 with AlwaysOnCluster

use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.

the class LdapProvisioning method extendLifeInCacheOrFlush.

public void extendLifeInCacheOrFlush(Entry entry) {
    if (entry instanceof Account) {
        accountCache.replace((Account) entry);
    } else if (entry instanceof LdapCos) {
        cosCache.replace((LdapCos) entry);
    } else if (entry instanceof Domain) {
        domainCache.replace((Domain) entry);
    } else if (entry instanceof Server) {
        serverCache.replace((Server) entry);
    } else if (entry instanceof UCService) {
        ucServiceCache.replace((UCService) entry);
    } else if (entry instanceof XMPPComponent) {
        xmppComponentCache.replace((XMPPComponent) entry);
    } else if (entry instanceof LdapZimlet) {
        zimletCache.replace((LdapZimlet) entry);
    } else if (entry instanceof LdapAlwaysOnCluster) {
        alwaysOnClusterCache.replace((AlwaysOnCluster) entry);
    } else if (entry instanceof Group) {
        /*
             * DLs returned by Provisioning.get(DistributionListBy) and
             * DLs/dynamic groups returned by Provisioning.getGroup(DistributionListBy)
             * are "not" cached.
             *
             * DLs returned by Provisioning.getDLBasic(DistributionListBy) and
             * DLs/dynamic groups returned by Provisioning.getGroupBasic(DistributionListBy)
             * "are" cached.
             *
             * Need to flush out the cached entries if the instance being modified is not
             * in cache. (i.e. the instance being modified was obtained by get/getGroup)
             */
        Group modifiedInstance = (Group) entry;
        Group cachedInstance = getGroupFromCache(DistributionListBy.id, modifiedInstance.getId());
        if (cachedInstance != null && modifiedInstance != cachedInstance) {
            groupCache.remove(cachedInstance);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) UCService(com.zimbra.cs.account.UCService) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent)

Example 3 with AlwaysOnCluster

use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.

the class LdapProvisioning method refreshEntry.

void refreshEntry(Entry entry, ZLdapContext initZlc) throws ServiceException {
    try {
        String dn = ((LdapEntry) entry).getDN();
        ZAttributes attributes = helper.getAttributes(initZlc, dn);
        Map<String, Object> attrs = attributes.getAttrs();
        Map<String, Object> defaults = null;
        Map<String, Object> secondaryDefaults = null;
        Map<String, Object> overrideDefaults = null;
        if (entry instanceof Account) {
            //
            // We can get here from either modifyAttrsInternal or reload path.
            //
            // If we got here from modifyAttrsInternal, zimbraCOSId on account
            // might have been changed, added, removed, but entry now still contains
            // the old attrs.  Create a temp Account object from the new attrs, and then
            // use the same cos of the temp Account object for our entry object.
            //
            // If we got here from reload, attrs are likely not changed, the callsites
            // just want a refreshed object.  For this case it's best if we still
            // always resolve the COS correctly.  makeAccount is a cheap call and won't
            // add any overhead like loading cos/domain from LDAP: even if cos/domain
            // has to be loaded (because not in cache) in the getCOS(temp) call, it's
            // just the same as calling (buggy) getCOS(entry) before.
            //
            // We only need the temp object for the getCOS call, don't need to setup
            // primary/secondary defaults on the temp object because:
            //     zimbraCOSId is only on account(of course), and that's all needed
            //     for determining the COS for the account in the getCOS call: if
            //     zimbraCOSId is not set on account, it will fallback to the domain
            //     default COS, then fallback to the system default COS.
            //
            Account temp = makeAccountNoDefaults(dn, attributes);
            Cos cos = getCOS(temp);
            if (cos != null)
                defaults = cos.getAccountDefaults();
            Domain domain = getDomain((Account) entry);
            if (domain != null)
                secondaryDefaults = domain.getAccountDefaults();
        } else if (entry instanceof Domain) {
            defaults = getConfig().getDomainDefaults();
        } else if (entry instanceof Server) {
            defaults = getConfig().getServerDefaults();
            AlwaysOnCluster aoc = getAlwaysOnCluster((Server) entry);
            if (aoc != null) {
                overrideDefaults = aoc.getServerOverrides();
            }
        }
        if (defaults == null && secondaryDefaults == null)
            entry.setAttrs(attrs);
        else
            entry.setAttrs(attrs, defaults, secondaryDefaults, overrideDefaults);
        extendLifeInCacheOrFlush(entry);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to refresh entry", e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) 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) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) ZAttributes(com.zimbra.cs.ldap.ZAttributes) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain)

Example 4 with AlwaysOnCluster

use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.

the class LdapProvisioning method flushCache.

@Override
public void flushCache(CacheEntryType type, CacheEntry[] entries) throws ServiceException {
    switch(type) {
        case all:
            if (entries != null) {
                throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing all", null);
            }
            ZimbraLog.account.info("Flushing all LDAP entry caches");
            flushCache(CacheEntryType.account, null);
            flushCache(CacheEntryType.group, null);
            flushCache(CacheEntryType.config, null);
            flushCache(CacheEntryType.globalgrant, null);
            flushCache(CacheEntryType.cos, null);
            flushCache(CacheEntryType.domain, null);
            flushCache(CacheEntryType.mime, null);
            flushCache(CacheEntryType.server, null);
            flushCache(CacheEntryType.alwaysOnCluster, null);
            flushCache(CacheEntryType.zimlet, null);
            break;
        case account:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    AccountBy accountBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? AccountBy.id : AccountBy.name;
                    Account account = getFromCache(accountBy, entry.mEntryIdentity);
                    /*
                     * We now call removeFromCache instead of reload for flushing an account
                     * from cache.   This change was originally for bug 25028, but that would still
                     * need an extrat step to flush cache after the account's zimbraCOSId changed.
                     * (if we call reload insteasd of removeFromCache, flush cache of the account would
                     * not clear the mDefaults for inherited attrs, that was the bug.)
                     * Bug 25028 is now taken care of by the callback.  We still call removeFromCache
                     * for flushing account cache, because that does a cleaner flush.
                     *
                     * Note, we only call removeFromCache for account.
                     * We should *NOT* do removeFromCache when flushing global config and cos caches.
                     *
                     * Because the "mDefaults" Map(contains a ref to the old instance of COS.mAccountDefaults for
                     * all the accountInherited COS attrs) stored in all the cached accounts.   Same for the
                     * inherited attrs of server/domain from global config.  If we do removeFromCache for flushing
                     * cos/global config, then after FlushCache(cos) if you do a ga on a cached account, it still
                     * shows the old COS value for values that are inherited from COS.   Although, for newly loaded
                     * accounts or when a cached account is going thru auth(that'll trigger a reload) they will get
                     * the new COS values(refreshed as a result of FlushCache(cos)).
                     */
                    if (account != null) {
                        removeFromCache(account);
                    }
                }
            } else {
                accountCache.clear();
            }
            return;
        case group:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.DistributionListBy dlBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.DistributionListBy.id : Key.DistributionListBy.name;
                    removeGroupFromCache(dlBy, entry.mEntryIdentity);
                }
            } else {
                allDLs.clear();
                groupCache.clear();
            }
            return;
        case config:
            if (entries != null) {
                throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing global config", null);
            }
            Config config = getConfig();
            reload(config, false);
            EphemeralStore.clearFactory();
            return;
        case globalgrant:
            if (entries != null) {
                throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing global grant", null);
            }
            GlobalGrant globalGrant = getGlobalGrant();
            reload(globalGrant, false);
            return;
        case cos:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.CosBy cosBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.CosBy.id : Key.CosBy.name;
                    Cos cos = getFromCache(cosBy, entry.mEntryIdentity);
                    if (cos != null)
                        reload(cos, false);
                }
            } else
                cosCache.clear();
            return;
        case domain:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.DomainBy domainBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.DomainBy.id : Key.DomainBy.name;
                    Domain domain = getFromCache(domainBy, entry.mEntryIdentity, GetFromDomainCacheOption.BOTH);
                    if (domain != null) {
                        if (domain instanceof DomainCache.NonExistingDomain)
                            domainCache.removeFromNegativeCache(domainBy, entry.mEntryIdentity);
                        else
                            reload(domain, false);
                    }
                }
            } else
                domainCache.clear();
            return;
        case mime:
            mimeTypeCache.flushCache(this);
            return;
        case server:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.ServerBy serverBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.ServerBy.id : Key.ServerBy.name;
                    Server server = get(serverBy, entry.mEntryIdentity);
                    if (server != null)
                        reload(server, false);
                }
            } else
                serverCache.clear();
            return;
        case alwaysOnCluster:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.AlwaysOnClusterBy clusterBy = Key.AlwaysOnClusterBy.id;
                    AlwaysOnCluster cluster = get(clusterBy, entry.mEntryIdentity);
                    if (cluster != null)
                        reload(cluster, false);
                }
            } else
                alwaysOnClusterCache.clear();
            return;
        case zimlet:
            if (entries != null) {
                for (CacheEntry entry : entries) {
                    Key.ZimletBy zimletBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.ZimletBy.id : Key.ZimletBy.name;
                    Zimlet zimlet = getFromCache(zimletBy, entry.mEntryIdentity);
                    if (zimlet != null)
                        reload(zimlet, false);
                }
            } else
                zimletCache.clear();
            return;
        default:
            throw ServiceException.INVALID_REQUEST("invalid cache type " + type, null);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) Config(com.zimbra.cs.account.Config) LdapConfig(com.zimbra.cs.account.ldap.entry.LdapConfig) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) GalSearchConfig(com.zimbra.cs.gal.GalSearchConfig) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) AccountBy(com.zimbra.common.account.Key.AccountBy) Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) LdapGlobalGrant(com.zimbra.cs.account.ldap.entry.LdapGlobalGrant) GlobalGrant(com.zimbra.cs.account.GlobalGrant) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey) Key(com.zimbra.common.account.Key) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) DataKey(com.zimbra.cs.account.callback.CallbackContext.DataKey) PreAuthKey(com.zimbra.cs.account.PreAuthKey)

Example 5 with AlwaysOnCluster

use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.

the class GetAllAlwaysOnClusters method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    List<AlwaysOnCluster> clusters = prov.getAllAlwaysOnClusters();
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    Element response = zsc.createElement(AdminConstants.GET_ALL_ALWAYSONCLUSTERS_RESPONSE);
    for (Iterator<AlwaysOnCluster> it = clusters.iterator(); it.hasNext(); ) {
        AlwaysOnCluster cluster = it.next();
        if (aac.hasRightsToList(cluster, Admin.R_listAlwaysOnCluster, null))
            GetAlwaysOnCluster.encodeAlwaysOnCluster(response, cluster, null, aac.getAttrRightChecker(cluster));
    }
    return response;
}
Also used : AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

AlwaysOnCluster (com.zimbra.cs.account.AlwaysOnCluster)14 LdapAlwaysOnCluster (com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster)7 Element (com.zimbra.common.soap.Element)5 Provisioning (com.zimbra.cs.account.Provisioning)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)5 ServiceException (com.zimbra.common.service.ServiceException)4 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 Account (com.zimbra.cs.account.Account)3 Domain (com.zimbra.cs.account.Domain)3 GuestAccount (com.zimbra.cs.account.GuestAccount)3 Server (com.zimbra.cs.account.Server)3 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)3 LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)3 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)3 LdapServer (com.zimbra.cs.account.ldap.entry.LdapServer)3 InMemoryLdapServer (com.zimbra.cs.ldap.unboundid.InMemoryLdapServer)3 Cos (com.zimbra.cs.account.Cos)2 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)2 Key (com.zimbra.common.account.Key)1