Search in sources :

Example 1 with Zimlet

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

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

the class LdapProvisioning method createZimlet.

@Override
public Zimlet createZimlet(String name, Map<String, Object> zimletAttrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(zimletAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_ZIMLET);
        String hasKeyword = LdapConstants.LDAP_FALSE;
        if (zimletAttrs.containsKey(A_zimbraZimletKeyword)) {
            hasKeyword = ProvisioningConstants.TRUE;
        }
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(zimletAttrs);
        entry.setAttr(A_objectClass, "zimbraZimletEntry");
        entry.setAttr(A_zimbraZimletEnabled, ProvisioningConstants.FALSE);
        entry.setAttr(A_zimbraZimletIndexingEnabled, hasKeyword);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        String dn = mDIT.zimletNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        Zimlet zimlet = lookupZimlet(name, zlc);
        AttributeManager.getInstance().postModify(zimletAttrs, zimlet, callbackContext);
        return zimlet;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.ZIMLET_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create zimlet: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

Example 3 with Zimlet

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

the class DeleteZimlet method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Element z = request.getElement(AdminConstants.E_ZIMLET);
    String name = z.getAttribute(AdminConstants.A_NAME);
    Zimlet zimlet = prov.getZimlet(name);
    if (zimlet == null)
        throw AccountServiceException.NO_SUCH_ZIMLET(name);
    checkRight(zsc, context, zimlet, Admin.R_deleteZimlet);
    String id = zimlet.getId();
    prov.deleteZimlet(name);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "DeleteZimlet", "name", name, "id", id }));
    Element response = zsc.createElement(AdminConstants.DELETE_ZIMLET_RESPONSE);
    return response;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 4 with Zimlet

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

the class ZimletUtil method ldapDeploy.

public static Zimlet ldapDeploy(ZimletFile zf) throws ServiceException, IOException, ZimletException {
    ZimletDescription zd = zf.getZimletDescription();
    String zimletName = zd.getName();
    Map<String, Object> attrs = descToMap(zd);
    List<String> targets = zd.getTargets();
    if (targets != null && targets.size() > 0) {
        attrs.put(Provisioning.A_zimbraZimletTarget, targets);
    }
    String disableZimletUndeploy = zd.getDisableUIUndeploy();
    if (disableZimletUndeploy != null && disableZimletUndeploy.equalsIgnoreCase("true")) {
        attrs.put(Provisioning.A_zimbraAdminExtDisableUIUndeploy, ProvisioningConstants.TRUE);
    }
    if (zd.isExtension()) {
        attrs.put(Provisioning.A_zimbraZimletIsExtension, ProvisioningConstants.TRUE);
    } else {
        attrs.put(Provisioning.A_zimbraZimletIsExtension, ProvisioningConstants.FALSE);
    }
    ZimbraLog.zimlet.info("Deploying Zimlet " + zimletName + " in LDAP.");
    // add zimlet entry to ldap
    Provisioning prov = Provisioning.getInstance();
    Zimlet zim = prov.getZimlet(zimletName);
    if (zim == null) {
        zim = prov.createZimlet(zimletName, attrs);
    } else {
        prov.modifyAttrs(zim, attrs);
    }
    return zim;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 5 with Zimlet

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

the class ZimletUtil method getZimletConfig.

public static ZimletConfig getZimletConfig(String zimlet) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Zimlet z = prov.getZimlet(zimlet);
    if (z == null) {
        throw AccountServiceException.NO_SUCH_ZIMLET(zimlet);
    }
    String cf = z.getAttr(Provisioning.A_zimbraZimletHandlerConfig);
    if (cf == null) {
        return null;
    }
    try {
        return new ZimletConfig(cf);
    } catch (ZimletException e) {
        ZimbraLog.zimlet.warn("Unable to load zimlet config for " + z.getName(), e);
    }
    return null;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Aggregations

Zimlet (com.zimbra.cs.account.Zimlet)37 Provisioning (com.zimbra.cs.account.Provisioning)16 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)11 Element (com.zimbra.common.soap.Element)8 HashMap (java.util.HashMap)8 ServiceException (com.zimbra.common.service.ServiceException)7 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Cos (com.zimbra.cs.account.Cos)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Entry (com.zimbra.cs.account.Entry)3 NamedEntry (com.zimbra.cs.account.NamedEntry)3 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)2 ZimbraACE (com.zimbra.cs.account.accesscontrol.ZimbraACE)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Key (com.zimbra.common.account.Key)1 AccountBy (com.zimbra.common.account.Key.AccountBy)1 DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)1