Search in sources :

Example 6 with Config

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

the class PseudoTarget method createPseudoTarget.

/**
     * construct a pseudo target
     *
     * if targetType is a domain-ed type: account. cr, dl:
     * then exactly one of the following must be passed in:
     *    - domainBy == null
     *      domainStr == null
     *      createPseudoDomain == true
     *    or
     *    - domainBy != null
     *      domainStr != null
     *      createPseudoDomain == false
     *
     * @param prov
     * @param targetType
     * @param domainBy
     * @param domainStr
     * @param createPseudoDomain
     * @param cosBy
     * @param cosStr
     * @param domainName used only when targetType is domain, ignored otherwise.
     *                   if not null, the pseudo domain will be created with the provided domainName,
     *                   not a pseudo name.
     *                   This is only used/needed for computing settable attrs when creating a domain.
     *                   We need to be able to traverse the domain hierarchy for grants with the subDomain modifier.
     * @return
     * @throws ServiceException
     */
public static Entry createPseudoTarget(Provisioning prov, TargetType targetType, Key.DomainBy domainBy, String domainStr, boolean createPseudoDomain, Key.CosBy cosBy, String cosStr, String domainName) throws ServiceException {
    Entry targetEntry = null;
    Config config = prov.getConfig();
    String zimbraId = PseudoZimbraId.getPseudoZimbraId();
    Map<String, Object> attrMap = new HashMap<String, Object>();
    attrMap.put(Provisioning.A_zimbraId, zimbraId);
    Domain pseudoDomain = null;
    Domain domain = null;
    if (targetType == TargetType.account || targetType == TargetType.calresource || targetType == TargetType.dl || targetType == TargetType.group) {
        if (createPseudoDomain) {
            domain = pseudoDomain = (Domain) createPseudoTarget(prov, TargetType.domain, null, null, false, null, null);
        } else {
            if (domainBy == null || domainStr == null)
                throw ServiceException.INVALID_REQUEST("domainBy and domain identifier is required", null);
            domain = prov.get(domainBy, domainStr);
        }
        if (domain == null) {
            throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
        }
    }
    switch(targetType) {
        case account:
        case calresource:
            Cos cos = null;
            if (cosBy != null && cosStr != null) {
                cos = prov.get(cosBy, cosStr);
                if (cos == null) {
                    throw AccountServiceException.NO_SUCH_COS(cosStr);
                }
                attrMap.put(Provisioning.A_zimbraCOSId, cos.getId());
            } else {
                String domainCosId = domain != null ? domain.getAttr(Provisioning.A_zimbraDomainDefaultCOSId, null) : null;
                if (domainCosId != null) {
                    cos = prov.get(Key.CosBy.id, domainCosId);
                }
                if (cos == null) {
                    cos = prov.get(Key.CosBy.name, Provisioning.DEFAULT_COS_NAME);
                }
            }
            if (targetType == TargetType.account) {
                targetEntry = new PseudoAccount("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
            } else {
                targetEntry = new PseudoCalendarResource("pseudo@" + domain.getName(), zimbraId, attrMap, cos.getAccountDefaults(), prov, pseudoDomain);
            }
            break;
        case cos:
            targetEntry = new PseudoCos("pseudocos", zimbraId, attrMap, prov);
            break;
        case dl:
            targetEntry = new PseudoDistributionList("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
            break;
        case group:
            targetEntry = new PseudoDynamicGroup("pseudo@" + domain.getName(), zimbraId, attrMap, prov, pseudoDomain);
            break;
        case domain:
            String name = domainName == null ? "pseudo.pseudo" : domainName;
            targetEntry = new PseudoDomain(name, zimbraId, attrMap, config.getDomainDefaults(), prov);
            break;
        case server:
            targetEntry = new PseudoServer("pseudo.pseudo", zimbraId, attrMap, config.getServerDefaults(), prov);
            break;
        case alwaysoncluster:
            targetEntry = new PseudoAlwaysOnCluster("pseudo.pseudo", zimbraId, attrMap, null, prov);
            break;
        case ucservice:
            targetEntry = new PseudoUCService("pseudo", zimbraId, attrMap, prov);
            break;
        case xmppcomponent:
            targetEntry = new PseudoXMPPComponent("pseudo", zimbraId, attrMap, prov);
            break;
        case zimlet:
            targetEntry = new PseudoZimlet("pseudo", zimbraId, attrMap, prov);
            break;
        default:
            throw ServiceException.INVALID_REQUEST("unsupported target for createPseudoTarget: " + targetType.getCode(), null);
    }
    return targetEntry;
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config) Cos(com.zimbra.cs.account.Cos) Entry(com.zimbra.cs.account.Entry) Domain(com.zimbra.cs.account.Domain)

Example 7 with Config

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

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

the class BUG_57425 method doGlobalConfig.

private void doGlobalConfig(ZLdapContext zlc) throws ServiceException {
    Config config = prov.getConfig();
    doEntry(zlc, config, "global config");
}
Also used : Config(com.zimbra.cs.account.Config)

Example 9 with Config

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

the class BUG_57855 method upgradeZimbraGalLdapFilterDef.

void upgradeZimbraGalLdapFilterDef() throws ServiceException {
    Config config = prov.getConfig();
    String attrName = Provisioning.A_zimbraGalLdapFilterDef;
    String[] addValues = new String[] { "email_has:(mail=*%s*)", "email2_has:(mail=*%s*)", "email3_has:(mail=*%s*)", "department_has:(ou=*%s*)" };
    Set<String> curValues = config.getMultiAttrSet(attrName);
    Map<String, Object> attrs = new HashMap<String, Object>();
    for (String value : addValues) {
        if (!curValues.contains(value)) {
            StringUtil.addToMultiMap(attrs, "+" + attrName, value);
        }
    }
    modifyAttrs(config, attrs);
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config)

Example 10 with Config

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

the class BUG_47934 method upgradeZimbraGalLdapFilterDef.

void upgradeZimbraGalLdapFilterDef() throws ServiceException {
    Config config = prov.getConfig();
    Pair[] values = { new Pair<String, String>("zimbraAccounts:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))", "zimbraAccounts:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))"), new Pair<String, String>("zimbraAccountAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))", "zimbraAccountAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(zimbraPhoneticFirstName=%s*)(zimbraPhoneticLastName=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))"), new Pair<String, String>("zimbraAccountSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))", "zimbraAccountSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))"), new Pair<String, String>("zimbraAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList)))", "zimbraAutoComplete:(&(|(displayName=%s*)(cn=%s*)(sn=%s*)(gn=%s*)(zimbraPhoneticFirstName=%s*)(zimbraPhoneticLastName=%s*)(mail=%s*)(zimbraMailDeliveryAddress=%s*)(zimbraMailAlias=%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList)))"), new Pair<String, String>("zimbraSearch:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList)))", "zimbraSearch:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList)))") };
    Set<String> curValues = config.getMultiAttrSet(Provisioning.A_zimbraGalLdapFilterDef);
    Map<String, Object> attrs = new HashMap<String, Object>();
    for (Pair<String, String> change : values) {
        String oldValue = change.getFirst();
        String newValue = change.getSecond();
        if (curValues.contains(oldValue)) {
            StringUtil.addToMultiMap(attrs, "-" + Provisioning.A_zimbraGalLdapFilterDef, oldValue);
            StringUtil.addToMultiMap(attrs, "+" + Provisioning.A_zimbraGalLdapFilterDef, newValue);
        }
    }
    modifyAttrs(config, attrs);
}
Also used : HashMap(java.util.HashMap) Config(com.zimbra.cs.account.Config) Pair(com.zimbra.common.util.Pair)

Aggregations

Config (com.zimbra.cs.account.Config)73 HashMap (java.util.HashMap)24 Provisioning (com.zimbra.cs.account.Provisioning)10 Test (org.junit.Test)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)7 RetentionPolicy (com.zimbra.soap.mail.type.RetentionPolicy)7 Element (com.zimbra.common.soap.Element)6 Policy (com.zimbra.soap.mail.type.Policy)6 Cos (com.zimbra.cs.account.Cos)5 Server (com.zimbra.cs.account.Server)5 Domain (com.zimbra.cs.account.Domain)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Pair (com.zimbra.common.util.Pair)3 HashSet (java.util.HashSet)3 SMTPMessage (com.sun.mail.smtp.SMTPMessage)2 ZFilterAction (com.zimbra.client.ZFilterAction)2 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)2 ZFilterCondition (com.zimbra.client.ZFilterCondition)2 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)2