use of com.zimbra.cs.account.accesscontrol.GranteeType in project zm-mailbox by Zimbra.
the class CheckRight method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Element eTarget = request.getElement(AdminConstants.E_TARGET);
String targetType = eTarget.getAttribute(AdminConstants.A_TYPE);
TargetBy targetBy = null;
String target = null;
if (TargetType.fromCode(targetType).needsTargetIdentity()) {
targetBy = TargetBy.fromString(eTarget.getAttribute(AdminConstants.A_BY));
target = eTarget.getText();
}
Element eGrantee = request.getElement(AdminConstants.E_GRANTEE);
GranteeType granteeType = GranteeType.fromCode(eGrantee.getAttribute(AdminConstants.A_TYPE, GranteeType.GT_EMAIL.getCode()));
if ((granteeType != GranteeType.GT_USER) && (granteeType != GranteeType.GT_EMAIL)) {
throw ServiceException.INVALID_REQUEST("invalid grantee type " + granteeType, null);
}
GranteeBy granteeBy = GranteeBy.fromString(eGrantee.getAttribute(AdminConstants.A_BY));
String granteeVal = eGrantee.getText();
Element eRight = request.getElement(AdminConstants.E_RIGHT);
String right = eRight.getText();
Element eAttrs = request.getOptionalElement(AdminConstants.E_ATTRS);
Map<String, Object> attrs = (eAttrs == null) ? null : AdminService.getAttrs(request);
MailTarget grantee = null;
NamedEntry ne = GranteeType.lookupGrantee(Provisioning.getInstance(), granteeType, granteeBy, granteeVal);
if (ne instanceof MailTarget) {
grantee = (MailTarget) ne;
} else {
grantee = new GuestAccount(granteeVal, null);
}
if (!granteeVal.equals(zsc.getAuthtokenAccountId())) {
/* Make sure authenticated account has the right to check rights for this grantee.
*/
checkCheckRightRight(zsc, (grantee instanceof Account) ? GranteeType.GT_USER : GranteeType.GT_GROUP, granteeBy, granteeVal, true);
}
ViaGrant via = new ViaGrant();
boolean result = RightCommand.checkRight(Provisioning.getInstance(), targetType, targetBy, target, grantee, right, attrs, via);
Element resp = zsc.createElement(AdminConstants.CHECK_RIGHT_RESPONSE);
resp.addAttribute(AdminConstants.A_ALLOW, result);
if (via.available()) {
Element eVia = resp.addElement(AdminConstants.E_VIA);
Element eViaTarget = eVia.addElement(AdminConstants.E_TARGET);
eViaTarget.addAttribute(AdminConstants.A_TYPE, via.getTargetType());
eViaTarget.setText(via.getTargetName());
Element eViaGrantee = eVia.addElement(AdminConstants.E_GRANTEE);
eViaGrantee.addAttribute(AdminConstants.A_TYPE, via.getGranteeType());
eViaGrantee.setText(via.getGranteeName());
Element eViaRight = eVia.addElement(AdminConstants.E_RIGHT);
eViaRight.addAttribute(AdminConstants.A_DENY, via.isNegativeGrant());
eViaRight.setText(via.getRight());
}
return resp;
}
use of com.zimbra.cs.account.accesscontrol.GranteeType in project zm-mailbox by Zimbra.
the class TestACLAll method execTest.
private void execTest(String note, TargetType grantedOnTargetType, TestGranteeType testGranteeType, Right right) throws Exception {
System.out.println("testing (" + note + "): " + "grant target=" + grantedOnTargetType.getCode() + ", grantee type=" + testGranteeType.getCode() + ", right=" + right.getName());
//
// 1. some basic preparation
// create a domain
//
Domain domain = createDomain();
boolean isUserRight = right.isUserRight();
//
// 2. setup grantee
//
List<Account> allowedAccts = new ArrayList<Account>();
List<Account> deniedAccts = new ArrayList<Account>();
NamedEntry grantee = null;
String granteeName = null;
String secret = null;
Object gt = testGranteeType.getGranteeType();
GranteeType granteeType = null;
if (gt instanceof GranteeType) {
granteeType = (GranteeType) gt;
switch(granteeType) {
case GT_USER:
if (isUserRight) {
grantee = createUserAccount(domain);
allowedAccts.add((Account) grantee);
deniedAccts.add(createUserAccount(domain));
} else {
grantee = createDelegatedAdminAccount(domain);
allowedAccts.add((Account) grantee);
deniedAccts.add(createDelegatedAdminAccount(domain));
}
granteeName = grantee.getName();
break;
case GT_GROUP:
if (isUserRight) {
grantee = createUserDistributionList(domain);
Account allowedAcct = createUserAccount(domain);
allowedAccts.add(allowedAcct);
prov.addMembers((DistributionList) grantee, new String[] { allowedAcct.getName() });
// external members are also honored if the right is a user right
Account guestAcct = createGuestAccount("guest@guest.com", "test123");
allowedAccts.add(guestAcct);
prov.addMembers((DistributionList) grantee, new String[] { guestAcct.getName() });
deniedAccts.add(createUserAccount(domain));
} else {
grantee = createAdminDistributionList(domain);
Account allowedAcct = createDelegatedAdminAccount(domain);
allowedAccts.add(allowedAcct);
prov.addMembers((DistributionList) grantee, new String[] { allowedAcct.getName() });
deniedAccts.add(createDelegatedAdminAccount(domain));
}
granteeName = grantee.getName();
break;
case GT_EXT_GROUP:
// create a domain and use it for the external group
Domain extDomain = createDomain();
String extDomainDN = ((LdapDomain) extDomain).getDN();
String acctLocalpart = "acct-ext";
//
// Configure the domain for external AD auth
//
Map<String, Object> domainAttrs = Maps.newHashMap();
if (isUserRight) {
domain.setAuthMech(AuthMech.ad.name(), domainAttrs);
} else {
domain.setAuthMechAdmin(AuthMech.ad.name(), domainAttrs);
}
/* ==== mock test ====
// setup auth
domain.addAuthLdapURL("ldap://localhost:389", domainAttrs);
domain.setAuthLdapBindDn("uid=%u,ou=people," + extDomainDN, domainAttrs);
// setup external group search parameters
domain.setAuthLdapSearchBindDn(LC.zimbra_ldap_userdn.value(), domainAttrs);
domain.setAuthLdapSearchBindPassword(LC.zimbra_ldap_password.value(), domainAttrs);
domain.setExternalGroupLdapSearchBase(extDomainDN, domainAttrs);
domain.setExternalGroupLdapSearchFilter("(&(objectClass=zimbraGroup)(cn=%u))", domainAttrs);
domain.setExternalGroupHandlerClass("com.zimbra.qa.unittest.UnittestGroupHandler", domainAttrs);
mProv.modifyAttrs(domain, domainAttrs);
// create a group in the external directory and add a member
Group extGroup = createUserDynamicGroup(extDomain); // doesn't matter if the group is user or admin
String extGroupName = extGroup.getName();
Account extAcct = createUserAccount(acctLocalpart, extDomain);
mProv.addGroupMembers(extGroup, new String[]{extAcct.getName()});
// create the admin account in Zimbra directory and map it to the external account
Account zimbraAcct = createDelegatedAdminAccount(acctLocalpart, domain);
allowedAccts.add(zimbraAcct);
*/
domain.addAuthLdapURL("***", domainAttrs);
domain.setAuthLdapSearchBindDn("***", domainAttrs);
domain.setAuthLdapSearchBindPassword("***", domainAttrs);
domain.setExternalGroupLdapSearchBase("OU=Engineering,DC=vmware,DC=com", domainAttrs);
domain.setExternalGroupLdapSearchFilter("(&(objectClass=group)(mail=%n))", domainAttrs);
domain.setExternalGroupHandlerClass("com.zimbra.cs.account.grouphandler.ADGroupHandler", domainAttrs);
prov.modifyAttrs(domain, domainAttrs);
// "ESPPEnrollment-USA@vmware.com";
String extGroupName = "ENG_pao_users_home4@vmware.com";
// create the admin account in Zimbra directory and map it to the external account
Account zimbraAcct = createDelegatedAdminAccount(acctLocalpart, domain);
zimbraAcct.setAuthLdapExternalDn("CN=Phoebe Shao,OU=PAO_Users,OU=PaloAlto_California_USA,OU=NALA,OU=SITES,OU=Engineering,DC=vmware,DC=com");
allowedAccts.add(zimbraAcct);
// =======================
granteeName = domain.getName() + ":" + extGroupName;
break;
case GT_AUTHUSER:
if (isUserRight) {
allowedAccts.add(createUserAccount("allowed-user-acct", domain));
deniedAccts.add(createGuestAccount("not-my-guest@external.com", "test123"));
} else {
deniedAccts.add(createDelegatedAdminAccount("denied-da-acct", domain));
}
break;
case GT_DOMAIN:
grantee = createDomain();
if (isUserRight) {
allowedAccts.add(createUserAccount("allowed-user-acct", (Domain) grantee));
Domain notGrantee = createDomain();
deniedAccts.add(createUserAccount("denied-user-acct", notGrantee));
} else {
deniedAccts.add(createDelegatedAdminAccount("denied-da-acct", (Domain) grantee));
// TODO: TEST R_crossDomainAdmin
}
granteeName = grantee.getName();
break;
case GT_GUEST:
// an email address
granteeName = "be-my-guest@guest.com";
// password
secret = "test123";
if (isUserRight) {
allowedAccts.add(createGuestAccount(granteeName, secret));
deniedAccts.add(createGuestAccount("not-my-guest@external.com", "bad"));
} else {
deniedAccts.add(createDelegatedAdminAccount("denied-da-acct", domain));
deniedAccts.add(createGuestAccount(granteeName, secret));
}
break;
case GT_KEY:
// a display name
granteeName = "be-my-guest";
// access key
secret = "test123";
if (isUserRight) {
allowedAccts.add(createKeyAccount(granteeName, secret));
deniedAccts.add(createKeyAccount("not-my-guest", "bad"));
} else {
deniedAccts.add(createDelegatedAdminAccount("denied-da-acct", domain));
deniedAccts.add(createKeyAccount(granteeName, secret));
}
break;
case GT_PUBLIC:
if (isUserRight) {
allowedAccts.add(anonAccount());
} else {
deniedAccts.add(anonAccount());
}
break;
default:
fail();
}
} else {
// dynamic group
assertEquals(TestGranteeType.GRANTEE_DYNAMIC_GROUP, testGranteeType);
granteeType = GranteeType.GT_GROUP;
if (isUserRight) {
grantee = createUserDynamicGroup(domain);
Account allowedAcct = createUserAccount(domain);
allowedAccts.add(allowedAcct);
prov.addGroupMembers((DynamicGroup) grantee, new String[] { allowedAcct.getName() });
// external members are also honored if the right is a user right
Account guestAcct = createGuestAccount("guest@guest.com", "test123");
allowedAccts.add(guestAcct);
prov.addGroupMembers((DynamicGroup) grantee, new String[] { guestAcct.getName() });
deniedAccts.add(createUserAccount(domain));
} else {
grantee = createAdminDynamicGroup(domain);
Account allowedAcct = createDelegatedAdminAccount(domain);
allowedAccts.add(allowedAcct);
prov.addGroupMembers((DynamicGroup) grantee, new String[] { allowedAcct.getName() });
deniedAccts.add(createDelegatedAdminAccount(domain));
}
granteeName = grantee.getName();
}
//
// 3. setup expectations for the granting action
//
boolean expectInvalidRequest = false;
if (isUserRight) {
expectInvalidRequest = !expectedIsRightGrantableOnTargetType(right, grantedOnTargetType);
} else {
// is admin right
if (!granteeType.allowedForAdminRights()) {
expectInvalidRequest = true;
}
if (!expectInvalidRequest) {
if (granteeType == GranteeType.GT_DOMAIN && right != Admin.R_crossDomainAdmin) {
expectInvalidRequest = true;
}
}
if (!expectInvalidRequest) {
expectInvalidRequest = !expectedIsRightGrantableOnTargetType(right, grantedOnTargetType);
}
}
//
// 4. setup target on which the right is to be granted
//
Entry grantedOnTarget = null;
String targetName = null;
switch(grantedOnTargetType) {
case account:
grantedOnTarget = createUserAccount("target-acct", domain);
targetName = ((Account) grantedOnTarget).getName();
break;
case calresource:
grantedOnTarget = createCalendarResource("target-cr", domain);
targetName = ((CalendarResource) grantedOnTarget).getName();
break;
case cos:
grantedOnTarget = createCos();
targetName = ((Cos) grantedOnTarget).getName();
break;
case dl:
grantedOnTarget = createUserDistributionList("target-distributionlist", domain);
targetName = ((DistributionList) grantedOnTarget).getName();
break;
case group:
grantedOnTarget = createUserDynamicGroup("target-dynamicgroup", domain);
targetName = ((DynamicGroup) grantedOnTarget).getName();
break;
case domain:
grantedOnTarget = domain;
targetName = domain.getName();
break;
case server:
grantedOnTarget = createServer();
targetName = ((Server) grantedOnTarget).getName();
break;
case alwaysoncluster:
grantedOnTarget = createAlwaysOnCluster();
targetName = ((AlwaysOnCluster) grantedOnTarget).getName();
break;
case ucservice:
grantedOnTarget = createUCService();
targetName = ((UCService) grantedOnTarget).getName();
break;
case xmppcomponent:
// skip for now
return;
case zimlet:
grantedOnTarget = createZimlet();
targetName = ((Zimlet) grantedOnTarget).getName();
break;
case config:
grantedOnTarget = getConfig();
break;
case global:
grantedOnTarget = getGlobalGrant();
break;
default:
fail();
}
//
// grant right on the target
//
boolean gotInvalidRequestException = false;
try {
// TODO: in a different test, test granting by a different authed account:
// global admin, delegated admin, user
//
Account grantingAccount = globalAdmin;
RightCommand.grantRight(prov, grantingAccount, grantedOnTargetType.getCode(), TargetBy.name, targetName, granteeType.getCode(), GranteeBy.name, granteeName, secret, right.getName(), null);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
gotInvalidRequestException = true;
} else {
e.printStackTrace();
fail();
}
}
//
// 5. verify the grant
//
assertEquals(expectInvalidRequest, gotInvalidRequestException);
// after group creation using the target object returned from the create call.
if (grantedOnTarget instanceof Group) {
grantedOnTarget = prov.getGroupBasic(Key.DistributionListBy.id, ((Group) grantedOnTarget).getId());
}
//
if (right.isComboRight()) {
for (Right rt : ((ComboRight) right).getAllRights()) {
setupTargetAndVerify(domain, grantedOnTarget, grantedOnTargetType, rt, true, allowedAccts, deniedAccts, !gotInvalidRequestException);
}
} else {
setupTargetAndVerify(domain, grantedOnTarget, grantedOnTargetType, right, false, allowedAccts, deniedAccts, !gotInvalidRequestException);
}
}
use of com.zimbra.cs.account.accesscontrol.GranteeType in project zm-mailbox by Zimbra.
the class TestACLEffectiveRights method getAllEffectiveRights.
@Test
public void getAllEffectiveRights() throws Exception {
Domain domain = provUtil.createDomain(genDomainSegmentName() + "." + BASE_DOMAIN_NAME);
Account target = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
Account grantee = provUtil.createDelegatedAdmin(genAcctNameLocalPart("da"), domain);
Account grantingAccount = globalAdmin;
TargetType targetType = TargetType.getTargetType(target);
GranteeType granteeType = GranteeType.GT_USER;
Right right = ADMIN_PRESET_ACCOUNT;
RightCommand.grantRight(prov, grantingAccount, targetType.getCode(), TargetBy.name, target.getName(), granteeType.getCode(), GranteeBy.name, grantee.getName(), null, right.getName(), null);
AllEffectiveRights allEffRights = RightCommand.getAllEffectiveRights(prov, granteeType.getCode(), GranteeBy.name, grantee.getName(), false, false);
Map<TargetType, RightsByTargetType> rbttMap = allEffRights.rightsByTargetType();
RightsByTargetType rbtt = rbttMap.get(targetType);
boolean found = false;
for (RightCommand.RightAggregation rightsByEntries : rbtt.entries()) {
Set<String> targetNames = rightsByEntries.entries();
if (targetNames.contains(target.getName())) {
// this RightAggregation contains our target
// see if it contains out right
EffectiveRights effRights = rightsByEntries.effectiveRights();
List<String> presetRights = effRights.presetRights();
if (presetRights.contains(right.getName())) {
found = true;
}
}
}
assertTrue(found);
}
Aggregations