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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations