Search in sources :

Example 1 with EntryCacheDataKey

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

the class LdapProvisioning method getGroupMembers.

@Override
public String[] getGroupMembers(Group group) throws ServiceException {
    EntryCacheDataKey cacheKey = EntryCacheDataKey.GROUP_MEMBERS;
    String[] members = null;
    if (group.isHABGroup() && group instanceof DynamicGroup) {
        DynamicGroup dynGroup = getDynamicGroup(Key.DistributionListBy.name, group.getName(), null, Boolean.FALSE);
        members = dynGroup.getAllMembers(true);
        Arrays.sort(members);
    } else {
        members = (String[]) group.getCachedData(cacheKey);
        if (members != null) {
            return members;
        }
        // should never be null
        members = group.getAllMembers();
        assert (members != null);
        Arrays.sort(members);
        // catch it
        group.setCachedData(cacheKey, members);
    }
    return members;
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey)

Example 2 with EntryCacheDataKey

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

the class TestLdapProvEntry method setCachedData.

@Test
public void setCachedData() throws Exception {
    EntryCacheDataKey KEY = EntryCacheDataKey.PERMISSION;
    String DATA = "abc";
    entry.setCachedData(KEY, DATA);
    Object dataCached = entry.getCachedData(KEY);
    assertEquals(DATA, dataCached);
}
Also used : EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey)

Example 3 with EntryCacheDataKey

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

the class LdapProvisioning method getAllDirectDLs.

/**
 * -  Get list of ids from EntryCacheDataKey.GROUPEDENTRY_DIRECT_GROUPIDS for "entry"
 *    -  Entry not cached:
 *       -  Get all addresses of this entry that can be identified as a member in a static group.
 *       -  Get direct groups for those addresses using filterFactory.distributionListsByMemberAddrs
 *          i.e. using an OR filter on Provisioning.A_zimbraMailForwardingAddress
 *       -  See if prov's Group Cache has this group already.  If so, use that! otherwise add it
 *       -  Put list of ids to EntryCacheDataKey.GROUPEDENTRY_DIRECT_GROUPIDS for "entry"
 *    -  Entry is cached:
 *       -  Get all the direct groups.  If any have been deleted, update the cache to reflect that
 * @param prov
 * @param entry
 * @return
 * @throws ServiceException
 */
private List<DistributionList> getAllDirectDLs(LdapProvisioning prov, Entry entry) throws ServiceException {
    if (!(entry instanceof GroupedEntry)) {
        throw ServiceException.FAILURE("internal error", null);
    }
    EntryCacheDataKey cacheKey = EntryCacheDataKey.GROUPEDENTRY_DIRECT_GROUPIDS;
    @SuppressWarnings("unchecked") List<String> directGroupIds = (List<String>) entry.getCachedData(cacheKey);
    List<DistributionList> directGroups = null;
    if (directGroupIds == null) {
        String[] addrs = ((GroupedEntry) entry).getAllAddrsAsGroupMember();
        // fetch from LDAP
        directGroups = prov.getAllDistributionListsForAddresses(addrs, true);
        // - build the group id list and cache it on the entry
        // - add each group in cache only if it is not already in.
        // we do not want to overwrite the entry in cache, because it
        // might already have all its direct group ids cached on it.
        // - if the group is already in cache, return the cached instance
        // instead of the instance we just fetched, because the cached
        // instance might have its direct group ids cached on it.
        directGroupIds = new ArrayList<String>(directGroups.size());
        List<DistributionList> directGroupsToReturn = new ArrayList<DistributionList>(directGroups.size());
        for (DistributionList group : directGroups) {
            String groupId = group.getId();
            directGroupIds.add(groupId);
            DistributionList cached = getDLFromCache(Key.DistributionListBy.id, groupId);
            if (cached == null) {
                putInGroupCache(group);
                directGroupsToReturn.add(group);
            } else {
                directGroupsToReturn.add(cached);
            }
        }
        entry.setCachedData(cacheKey, directGroupIds);
        return directGroupsToReturn;
    } else {
        /*
             * The entry already have direct group ids cached.
             * Go through each of them and fetch the groups,
             * eithr from cache or from LDAP (prov.getDLBasic).
             */
        directGroups = new ArrayList<DistributionList>();
        Set<String> idsToRemove = null;
        for (String groupId : directGroupIds) {
            DistributionList group = prov.getDLBasic(Key.DistributionListBy.id, groupId);
            if (group == null) {
                // remove it from our direct group id cache on the entry
                if (idsToRemove == null) {
                    idsToRemove = new HashSet<String>();
                }
                idsToRemove.add(groupId);
            } else {
                directGroups.add(group);
            }
        }
        // update our direct group id cache if needed
        if (idsToRemove != null) {
            // create a new object, do *not* update directly on the cached copy
            List<String> updatedDirectGroupIds = new ArrayList<String>();
            for (String id : directGroupIds) {
                if (!idsToRemove.contains(id)) {
                    updatedDirectGroupIds.add(id);
                }
            }
            // swap in the new data
            entry.setCachedData(cacheKey, updatedDirectGroupIds);
        }
    }
    return directGroups;
}
Also used : EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey) ArrayList(java.util.ArrayList) GroupedEntry(com.zimbra.cs.account.GroupedEntry) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) AddressList(com.zimbra.cs.account.AddressList) DistributionList(com.zimbra.cs.account.DistributionList) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 4 with EntryCacheDataKey

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

the class LdapProvisioning method getGroupMembership.

/**
 * @return distribution lists and both custom and normal dynamic groups the account is a member of
 */
@Override
public GroupMembership getGroupMembership(Account acct, boolean adminGroupsOnly) throws ServiceException {
    EntryCacheDataKey cacheKey = adminGroupsOnly ? EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP_ADMINS_ONLY : EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP;
    GroupMembership cacheableGroups = (GroupMembership) acct.getCachedData(cacheKey);
    if (cacheableGroups == null) {
        cacheableGroups = setupGroupedEntryCacheData(acct, adminGroupsOnly);
    }
    return cacheableGroups.clone();
}
Also used : EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey)

Example 5 with EntryCacheDataKey

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

the class LdapProvisioning method getGroupMembership.

@Override
public GroupMembership getGroupMembership(DistributionList dl, boolean adminGroupsOnly) throws ServiceException {
    EntryCacheDataKey cacheKey = adminGroupsOnly ? EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP_ADMINS_ONLY : EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP;
    GroupMembership groups = (GroupMembership) dl.getCachedData(cacheKey);
    if (groups != null) {
        return groups;
    }
    groups = new GroupMembership();
    DistributionList.updateGroupMembership(this, (ZLdapContext) null, groups, dl, null, /* via */
    false, /* adminGroupsOnly */
    false);
    dl.setCachedData(EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP, groups);
    if (adminGroupsOnly) {
        // filter out non-admin groups
        groups = getAdminAclGroups(groups);
        dl.setCachedData(EntryCacheDataKey.GROUPEDENTRY_MEMBERSHIP_ADMINS_ONLY, groups);
    }
    return groups;
}
Also used : EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey)

Aggregations

EntryCacheDataKey (com.zimbra.cs.account.EntryCacheDataKey)5 AddressList (com.zimbra.cs.account.AddressList)1 DistributionList (com.zimbra.cs.account.DistributionList)1 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1 GroupedEntry (com.zimbra.cs.account.GroupedEntry)1 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)1 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1