use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method CMBSearchAccountsOnly.
@Test
public void CMBSearchAccountsOnly() throws Exception {
Account acct1 = createAccount(genAcctNameLocalPart("1"));
Map<String, Object> acct2Attrs = Maps.newHashMap();
acct2Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "TRUE");
Account acct2 = createAccount(genAcctNameLocalPart("2"), acct2Attrs);
Map<String, Object> acct3Attrs = Maps.newHashMap();
acct3Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
Account acct3 = createAccount(genAcctNameLocalPart("3"), acct3Attrs);
String[] returnAttrs = { Provisioning.A_displayName, Provisioning.A_zimbraId, Provisioning.A_uid, Provisioning.A_zimbraArchiveAccount, Provisioning.A_zimbraMailHost };
// use domain so our assertion will work, production code does not a domain
SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, returnAttrs);
searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
ZLdapFilter filter = ZLdapFilterFactory.getInstance().CMBSearchAccountsOnly();
searchOpts.setFilter(filter);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
Verify.verifyEquals(Lists.newArrayList(acct3, acct1), accounts, true);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
/*
// legacy code and LDAP trace before refactoring
List<NamedEntry> accounts = prov.searchAccounts(
"(|(!(" + Provisioning.A_zimbraExcludeFromCMBSearch + "=*))(" +
Provisioning.A_zimbraExcludeFromCMBSearch + "=FALSE))",
attrs, null, false, Provisioning.searchDirectoryStringToMask("accounts"));
Oct 9 13:00:09 pshao-macbookpro-2 slapd[73952]: conn=1327 op=101 SRCH base="" scope=2 deref=0 filter="(&(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE))(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource))))"
Oct 9 13:00:09 pshao-macbookpro-2 slapd[73952]: conn=1327 op=101 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
/*
* LDAP trace after reactoring
*
Oct 9 13:43:26 pshao-macbookpro-2 slapd[73952]: conn=1345 op=107 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovaccount" scope=2 deref=0 filter="(&(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource)))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))"
Oct 9 13:43:26 pshao-macbookpro-2 slapd[73952]: conn=1345 op=107 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method namedEntryListToNameSet.
Set<String> namedEntryListToNameSet(List<NamedEntry> entries, UnicodeOrACE unicodeOrACE) {
Set<String> nameSet = new HashSet<String>();
for (NamedEntry entry : entries) {
String name;
if (entry instanceof MailTarget) {
if (unicodeOrACE == UnicodeOrACE.UNICODE) {
name = ((MailTarget) entry).getUnicodeName();
} else {
name = entry.getName();
}
} else {
name = entry.getName();
}
nameSet.add(name);
}
return nameSet;
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestSearchDirectory method testResponsContainsEphemeralAttrs.
@Test
public void testResponsContainsEphemeralAttrs() throws Exception {
String acctName = String.format("user1@%s", domain.getName());
Account acct = provUtil.createAccount(acctName, PASSWORD);
Date date = new Date();
acct.setLastLogonTimestamp(date);
List<NamedEntry> results = searchDirectory(acct.getName(), false);
acct = (Account) results.get(0);
String timestamp = acct.getAttr(Provisioning.A_zimbraLastLogonTimestamp);
assertEquals(LdapDateUtil.toGeneralizedTime(date), timestamp);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class CollectAllEffectiveRights method collect.
private void collect() throws ServiceException {
if (mRightBearer instanceof GlobalAdmin) {
for (TargetType tt : TargetType.values()) {
EffectiveRights er = new EffectiveRights(tt.getCode(), null, null, mRightBearer.getId(), mRightBearer.getName());
Entry target;
if (TargetType.config == tt) {
target = mProv.getConfig();
} else if (TargetType.global == tt) {
target = mProv.getGlobalGrant();
} else {
target = PseudoTarget.createPseudoTarget(mProv, tt, null, null, true, null, null, null);
}
CollectEffectiveRights.getEffectiveRights(mRightBearer, target, tt, mExpandSetAttrs, mExpandGetAttrs, er);
mResult.setAll(tt, er);
}
return;
}
// we want all target types
Set<TargetType> targetTypesToSearch = new HashSet<TargetType>(Arrays.asList(TargetType.values()));
// get the set of zimbraId of the grantees to search for
Set<String> granteeIdsToSearch = mGrantee.getIdAndGroupIds();
// add external group grants that *may* apply
if (mGrantee.isAccount()) {
Domain domain = mProv.getDomain(mGrantee.getAccount());
granteeIdsToSearch.add(ZimbraACE.ExternalGroupInfo.encode(domain.getId(), ""));
}
SearchGrants searchGrants = new SearchGrants(mProv, targetTypesToSearch, granteeIdsToSearch);
Set<GrantsOnTarget> grantsOnTargets = searchGrants.doSearch().getResults(true);
// staging for group grants
Set<Group> groupsWithGrants = new HashSet<Group>();
//
for (GrantsOnTarget grantsOnTarget : grantsOnTargets) {
Entry grantedOnEntry = grantsOnTarget.getTargetEntry();
ZimbraACL acl = grantsOnTarget.getAcl();
TargetType targetType = TargetType.getTargetType(grantedOnEntry);
if (targetType == TargetType.global) {
computeRightsInheritedFromGlobalGrant();
} else if (targetType == TargetType.domain) {
computeRightsInheritedFromDomain((Domain) grantedOnEntry);
computeSubDomainRightsInheritedFromDomain(acl, (Domain) grantedOnEntry);
} else if (targetType == TargetType.dl) {
groupsWithGrants.add((DistributionList) grantedOnEntry);
} else if (targetType == TargetType.group) {
groupsWithGrants.add((DynamicGroup) grantedOnEntry);
}
}
//
// Stage 2
//
// process group grants
//
// first, shape all members in all groups with grants into "shapes"
//
// e.g. if the grant search returned three groups: A, B, C
// group A contains members m1, m2, m3
// group B contains members m2, m3, m4
// group C contains members m5
//
// (assuming all m{X} are accounts)
//
// After "shaping", the accountShapes Set will contain 4 shapes:
// shape A - m1
// shape AB - m2, m3
// shape B - m4
// shape C - m5
//
/*
* because of bug 68820, we have to also take into accounts all sub groups
* of groupsWithGrants when we build shapes - even if the sub groups don't
* have any grants.
*
* Prior to bug 68820, we didn't have to do this(i.e. add in sub groups
* that don't have any grants when shapes are computed), because sub groups
* dont't have grants would never affect how grants are inherited - all grants
* get inherited to sub groups and their member accounts/crs.
*
* But bug 68820 introduced a new right modifier - DISINHERIT_SUB_GROUPS,
* that controls whether a grant on a group can be inherited by sub groups and
* their account/cr members.
*
* Now the input groups for calculating shapes are:
* union of (groups have grants and all their sub groups)
*
* This will result in more shares than before if non ofthe sub groups has grants,
* but if spawned shapes actually have the same effective rights, they will be
* merged by RightsByTargetType.addAggregation(), in that it checks if ther are
* already an aggregation with the exact the same right. If there are, then just
* add the targets to the existing aggregation, instead of adding new ones.
*/
Set<String> processedGroups = new HashSet<String>();
Set<GroupShape> accountShapes = new HashSet<GroupShape>();
Set<GroupShape> calendarResourceShapes = new HashSet<GroupShape>();
Set<GroupShape> distributionListShapes = new HashSet<GroupShape>();
for (Group group : groupsWithGrants) {
String groupName = group.getName().toLowerCase();
if (processedGroups.contains(groupName)) {
continue;
} else {
processedGroups.add(groupName);
}
AllGroupMembers allMembers = getAllGroupMembers(group);
GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
// no need to get TargetType.group members of the group, because
// dynamic group cannot be a member of a Distribution list or another
// dynamic group
processedGroups.add(group.getId());
/*
* handle sub groups. allMembers already contains a flat set of all members
* of group that is a DistributionList, just go through the flat set and compute
* shares for each. If group is a dynamic group, we should never get into
* the following loop, because there should be no nested groups member of
* dynamic group.
*/
for (String nestedGoupMember : allMembers.getMembers(TargetType.dl)) {
String nestedGoupMemberName = nestedGoupMember.toLowerCase();
if (processedGroups.contains(nestedGoupMemberName)) {
continue;
} else {
processedGroups.add(nestedGoupMemberName);
}
DistributionList subDl = mProv.get(DistributionListBy.name, nestedGoupMemberName);
// sanity check, shout not be null
if (subDl != null) {
AllGroupMembers allMembersOfSubDl = getAllGroupMembers(subDl);
GroupShape.shapeMembers(TargetType.account, accountShapes, allMembersOfSubDl);
GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembersOfSubDl);
GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembersOfSubDl);
}
}
}
if (ZimbraLog.acl.isDebugEnabled()) {
GroupShape.debug("accountShapes", accountShapes);
GroupShape.debug("calendarResourceShapes", calendarResourceShapes);
GroupShape.debug("distributionListShapes", distributionListShapes);
}
// then, for each group shape, generate a RightAggregation and record in the AllEffectiveRights.
// if any of the entries in a shape also have grants as an individual, the effective rigths for
// those entries will be replaced in stage 3.
Set<String> entryIdsHasGrants = new HashSet<String>();
for (GrantsOnTarget grantsOnTarget : grantsOnTargets) {
Entry grantedOnEntry = grantsOnTarget.getTargetEntry();
if (grantedOnEntry instanceof NamedEntry) {
entryIdsHasGrants.add(((NamedEntry) grantedOnEntry).getId());
}
}
computeRightsOnGroupShape(TargetType.account, accountShapes, entryIdsHasGrants);
computeRightsOnGroupShape(TargetType.calresource, calendarResourceShapes, entryIdsHasGrants);
computeRightsOnGroupShape(TargetType.dl, distributionListShapes, entryIdsHasGrants);
//
for (GrantsOnTarget grantsOnTarget : grantsOnTargets) {
Entry grantedOnEntry = grantsOnTarget.getTargetEntry();
ZimbraACL acl = grantsOnTarget.getAcl();
TargetType targetType = TargetType.getTargetType(grantedOnEntry);
if (targetType != TargetType.global) {
computeRightsOnEntry(targetType, grantedOnEntry);
}
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class RightCommand method getAllEffectiveRights.
public static AllEffectiveRights getAllEffectiveRights(Provisioning prov, String granteeType, GranteeBy granteeBy, String grantee, boolean expandSetAttrs, boolean expandGetAttrs) throws ServiceException {
AdminConsoleCapable acc = verifyAdminConsoleCapable();
// grantee
GranteeType gt = GranteeType.fromCode(granteeType);
NamedEntry granteeEntry = GranteeType.lookupGrantee(prov, gt, granteeBy, grantee);
RightBearer rightBearer = RightBearer.newRightBearer(granteeEntry);
AllEffectiveRights aer;
String cacheKey = null;
if (ALL_EFFECTIVE_RIGHTS_CACHE != null) {
cacheKey = String.format("%s-%s-%s-%b-%b", rightBearer.getId(), gt.getCode(), granteeEntry.getId(), expandSetAttrs, expandGetAttrs);
aer = ALL_EFFECTIVE_RIGHTS_CACHE.getIfPresent(cacheKey);
if (aer == null) {
aer = getAllEffectiveRights(acc, gt, granteeEntry, rightBearer, expandSetAttrs, expandGetAttrs);
ALL_EFFECTIVE_RIGHTS_CACHE.put(cacheKey, aer);
}
} else {
aer = getAllEffectiveRights(acc, gt, granteeEntry, rightBearer, expandSetAttrs, expandGetAttrs);
}
return aer;
}
Aggregations