use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class ParticallyDenied method isSubTarget.
private static boolean isSubTarget(Provisioning prov, Entry targetSup, Entry targetSub) throws ServiceException {
if (targetSup instanceof Domain) {
Domain domain = (Domain) targetSup;
Domain targetSubInDomain = TargetType.getTargetDomain(prov, targetSub);
if (targetSubInDomain == null)
// not a domain-ed entry
return false;
else {
if (domain.getId().equals(targetSubInDomain.getId()))
return true;
else {
// see if targetSub is in a group that is in the domain
GroupMembership groups = null;
if (targetSub instanceof Account)
groups = prov.getGroupMembership((Account) targetSub, false);
else if (targetSub instanceof DistributionList)
groups = prov.getGroupMembership((DistributionList) targetSub, false);
else
return false;
for (String groupId : groups.groupIds()) {
DistributionList group = prov.getDLBasic(Key.DistributionListBy.id, groupId);
Domain groupInDomain = prov.getDomain(group);
if (// hmm, log a warn if groupInDomain is null? throw internal err?
groupInDomain != null && domain.getId().equals(groupInDomain.getId()))
return true;
}
}
}
return false;
} else if (targetSup instanceof DistributionList) {
DistributionList dl = (DistributionList) targetSup;
String subId = null;
if (// covers cr too
targetSub instanceof Account)
return prov.inDistributionList((Account) targetSub, dl.getId());
else if (targetSub instanceof DistributionList)
return prov.inDistributionList((DistributionList) targetSub, dl.getId());
else
return false;
} else if (targetSup instanceof GlobalGrant)
return true;
else {
/*
* is really an error, somehow our logic of finding sub-targets
* is wrong, throw FAILURE and fix if we get here. The granting attemp
* will be denied, but that's fine.
*/
throw ServiceException.FAILURE("internal error, unexpected entry type: " + targetSup.getLabel(), null);
}
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class GetAdminConsoleUIComp method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetAdminConsoleUICompRequest req = JaxbUtil.elementToJaxb(request);
AccountSelector accountSel = req.getAccount();
DistributionListSelector dlSel = req.getDl();
Element resp = zsc.createElement(AdminConstants.GET_ADMIN_CONSOLE_UI_COMP_RESPONSE);
if ((null != accountSel) && (null != dlSel)) {
throw ServiceException.INVALID_REQUEST("can only specify eith account or dl", null);
}
Account authedAcct = getAuthenticatedAccount(zsc);
Set<String> added = new HashSet<String>();
GroupMembership aclGroups = null;
if (accountSel != null) {
AccountBy by = accountSel.getBy().toKeyAccountBy();
String key = accountSel.getKey();
Account acct = prov.get(by, key);
AccountHarvestingCheckerUsingCheckRight checker = new AccountHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewAccountAdminUI);
if (acct == null) {
defendAgainstAccountHarvestingWhenAbsent(by, key, zsc, checker);
} else {
if (!authedAcct.getId().equals(acct.getId())) {
defendAgainstAccountHarvesting(acct, by, key, zsc, checker);
}
addValues(acct, resp, added, false);
aclGroups = prov.getGroupMembership(acct, true);
}
} else if (dlSel != null) {
Key.DistributionListBy by = dlSel.getBy().toKeyDistributionListBy();
String key = dlSel.getKey();
DistributionList dl = prov.getDLBasic(by, key);
GroupHarvestingCheckerUsingCheckRight checker = new GroupHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewDistributionListAdminUI);
if (dl == null) {
defendAgainstGroupHarvestingWhenAbsent(by, key, zsc, checker);
} else {
defendAgainstGroupHarvesting(dl, by, key, zsc, checker);
addValues(dl, resp, added, false);
aclGroups = prov.getGroupMembership(dl, true);
}
} else {
// use the authed account
addValues(authedAcct, resp, added, false);
aclGroups = prov.getGroupMembership(authedAcct, true);
}
if (aclGroups != null) {
for (String groupId : aclGroups.groupIds()) {
DistributionList dl = prov.get(Key.DistributionListBy.id, groupId);
addValues(dl, resp, added, true);
}
}
return resp;
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestLdapProvDynamicGroup method getGroupMembership.
/*
* Test Provisioning.getGroupMembership
*/
@Test
public void getGroupMembership() throws Exception {
Group group = createDynamicGroup(genGroupNameLocalPart());
Group otherDynamicGroup = createDynamicGroup(genGroupNameLocalPart("other-dynamic"));
Group otherStaticGroup = provUtil.createDistributionList(genGroupNameLocalPart("other-static"), domain);
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
String externalAddr = "user@external.com";
GuestAccount guestAcct = new GuestAccount(externalAddr, null);
prov.addGroupMembers(group, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherDynamicGroup, new String[] { acct.getName(), externalAddr });
prov.addGroupMembers(otherStaticGroup, new String[] { acct.getName(), externalAddr });
Set<String> expectedMemberOf = Sets.newHashSet(Verify.makeResultStr(group.getId(), Boolean.FALSE), Verify.makeResultStr(otherDynamicGroup.getId(), Boolean.FALSE), Verify.makeResultStr(otherStaticGroup.getId(), Boolean.FALSE));
Set<String> expectedIds = Sets.newHashSet(Verify.makeResultStr(group.getId()), Verify.makeResultStr(otherDynamicGroup.getId()), Verify.makeResultStr(otherStaticGroup.getId()));
/*
* verify membership for acct
*/
GroupMembership membership = prov.getGroupMembership(acct, false);
List<MemberOf> memberOfList = membership.memberOf();
List<String> groupIdList = membership.groupIds();
Set<String> actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
Set<String> actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
/*
* verify membership for guest acct
*/
membership = prov.getGroupMembership(guestAcct, false);
memberOfList = membership.memberOf();
groupIdList = membership.groupIds();
actualMemberOf = Sets.newHashSet();
for (MemberOf memberOf : memberOfList) {
actualMemberOf.add(Verify.makeResultStr(memberOf.getId(), memberOf.isAdminGroup()));
}
actualIds = Sets.newHashSet();
for (String id : groupIdList) {
actualIds.add(Verify.makeResultStr(id));
}
Verify.verifyEquals(expectedMemberOf, actualMemberOf);
Verify.verifyEquals(expectedIds, actualIds);
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestGroups method doGetCustomDynamicGroupMembership.
private void doGetCustomDynamicGroupMembership(int acctNum) throws ServiceException {
String acctName = String.format(acctPatt, acctNum);
Account acct = ldapProv.getAccountByName(acctName);
GroupMembership membership = ldapProv.getCustomDynamicGroupMembership(acct, false);
String groupNames = groupInfo(membership.groupIds());
assertEquals(String.format("Number of dynamic groups with custom memberURL s which contain %s groups=%s", acct.getName(), groupNames), 1, membership.groupIds().size());
String cosName = String.format(customDLPatt, acctNum % NUM_COS + 1);
Group grp = groups.get(membership.groupIds().get(0));
String groupName = (grp == null) ? "UNKNOWN(not created by this test)" : grp.getName();
assertEquals(String.format("Name of dynamic group with custom memberURL s which contains %s", acctName), cosName, groupName);
}
use of com.zimbra.cs.account.Provisioning.GroupMembership in project zm-mailbox by Zimbra.
the class TestGroups method testDLupdateGroupMembershipWithoutViaWithAliases.
public void testDLupdateGroupMembershipWithoutViaWithAliases() throws Exception {
Account acct = ldapProv.getAccountByName(acctWithAlias);
GroupMembership membership = new GroupMembership();
long start = System.currentTimeMillis();
DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, null, /* via */
false, /* adminGroupsOnly */
false);
ZimbraLog.test.info("testDLupdateGroupMembershipWithoutVia %s size=%d", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size());
for (int cnt = 1; cnt <= NUM_NORMAL_DL; cnt++) {
String nam = String.format(normalDLPatt, cnt);
DistributionList dl = ldapProv.get(DistributionListBy.name, nam);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", nam, dl.getId()), membership.groupIds().contains(dl.getId()));
}
DistributionList dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getId(), dl.getId()), membership.groupIds().contains(dl.getId()));
Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias), NUM_NORMAL_DL + 2, membership.memberOf().size());
acct = ldapProv.getAccountByName(acctWithAlias2);
membership = new GroupMembership();
start = System.currentTimeMillis();
DistributionList.updateGroupMembership(ldapProv, (ZLdapContext) null, membership, acct, null, /* via */
false, /* adminGroupsOnly */
false);
ZimbraLog.test.info("testDLupdateGroupMembershipWithoutVia %s size=%d", ZimbraLog.elapsedTime(start, System.currentTimeMillis()), membership.groupIds().size());
dl = ldapProv.get(DistributionListBy.name, dlWithAlias);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
dl = ldapProv.get(DistributionListBy.name, dlWithAlias2);
Assert.assertTrue(String.format("DL %s (id=%s) in membership", dl.getName(), dl.getId()), membership.groupIds().contains(dl.getId()));
Assert.assertEquals(String.format("Number of DLs User %s is a member of", acctWithAlias2), 2, membership.memberOf().size());
}
Aggregations