Search in sources :

Example 6 with Group

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

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

the class LdapProvisioning method getGroupBasic.

/*
     * like getGroup(DistributionListBy keyType, String key)
     * the difference are:
     *     - cached
     *     - entry returned only contains minimal group attrs
     *     - entry returned does not contain members (the member or zimbraMailForwardingAddress attribute)
     */
@Override
public Group getGroupBasic(Key.DistributionListBy keyType, String key) throws ServiceException {
    Group group = getGroupFromCache(keyType, key);
    if (group != null) {
        return group;
    }
    // fetch from LDAP
    group = getGroupInternal(keyType, key, true, false);
    // cache it
    if (group != null) {
        putInGroupCache(group);
    }
    return group;
}
Also used : Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)

Example 8 with Group

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

the class LdapProvisioning method cleanGroupMembersCache.

private void cleanGroupMembersCache(Group group) {
    /*
         * Fully loaded DLs(containing members attribute) are not cached
         * (those obtained via Provisioning.getGroup().
         *
         * if the modified instance (the instance being passed in) is not the same
         * instance in cache, clean the group members cache on the cached instance
         */
    Group cachedInstance = getGroupFromCache(DistributionListBy.id, group.getId());
    if (cachedInstance != null && group != cachedInstance) {
        cachedInstance.removeCachedData(EntryCacheDataKey.GROUP_MEMBERS);
    }
    // also always clean it on the modified instance
    group.removeCachedData(EntryCacheDataKey.GROUP_MEMBERS);
}
Also used : Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)

Example 9 with Group

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

the class SoapProvisioning method getGroups.

@Override
public List<Group> getGroups(Account acct, boolean directOnly, Map<String, String> via) throws ServiceException {
    ArrayList<Group> result = new ArrayList<Group>();
    GetAccountMembershipResponse resp = invokeJaxb(new GetAccountMembershipRequest(getSelector(acct)));
    for (DLInfo dlInfo : resp.getDlList()) {
        String viaList = dlInfo.getVia();
        if (directOnly && viaList != null) {
            continue;
        }
        Group group = makeGroup(dlInfo);
        if (via != null && viaList != null) {
            via.put(group.getName(), viaList);
        }
        result.add(group);
    }
    return result;
}
Also used : Group(com.zimbra.cs.account.Group) ArrayList(java.util.ArrayList) DLInfo(com.zimbra.soap.admin.type.DLInfo)

Example 10 with Group

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

the class BUG_66387 method fixAccount.

private void fixAccount(String name, String[] allowFromAddresses) throws ServiceException {
    ++numInspected;
    Account account = prov.get(AccountBy.name, name);
    if (account == null) {
        // this shouldn't happen
        printer.println("Account " + name + " not found!  Skipping.");
        return;
    }
    boolean modified = false;
    printer.println("# Account: " + account.getName());
    String[] addrs = account.getAllowFromAddress();
    printer.println("  Current value = " + StringUtil.join(", ", addrs));
    Set<String> remainingAddrs = new HashSet<String>();
    for (String addr : addrs) {
        NamedEntry entry = lookupEntry(addr);
        if (entry instanceof Account) {
            if (!entry.getId().equalsIgnoreCase(account.getId())) {
                doGrant(entry, account, addr);
                modified = true;
            } else {
                printer.println("    - removing redundant address " + addr);
                modified = true;
            }
        } else if (entry instanceof Group) {
            doGrant(entry, account, addr);
            modified = true;
        } else {
            remainingAddrs.add(addr);
        }
    }
    if (modified) {
        Map<String, Object> attrsMap = new HashMap<String, Object>();
        if (!remainingAddrs.isEmpty()) {
            String[] remaining = remainingAddrs.toArray(new String[0]);
            attrsMap.put(Provisioning.A_zimbraAllowFromAddress, remaining);
            printer.println("  New value = " + StringUtil.join(", ", remaining));
        } else {
            attrsMap.put(Provisioning.A_zimbraAllowFromAddress, "");
            printer.println("  New value = <unset>");
        }
        prov.modifyAttrs(account, attrsMap, false, false);
        ++numFixed;
    } else {
        printer.println("  No change needed");
    }
    printer.println();
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) Group(com.zimbra.cs.account.Group) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9