use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvAlias method testCreateAlias_aliasNameExistsButIsNotAnAlias.
@Test
public void testCreateAlias_aliasNameExistsButIsNotAnAlias() throws Exception {
String testName = getTestName();
// create the domain
String domainName = underscoreToHyphen(testName) + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// create another account
String acct2Name = getEmail("acct-2", domainName);
Account acct2 = prov.createAccount(acct2Name, PASSWORD, new HashMap<String, Object>());
// create a distribution list
String dlName = getEmail("dl", domainName);
DistributionList dl = prov.createDistributionList(dlName, new HashMap<String, Object>());
boolean good = false;
try {
prov.addAlias(acct, acct2Name);
} catch (ServiceException e) {
if (AccountServiceException.ACCOUNT_EXISTS.equals(e.getCode()))
good = true;
}
assertTrue(good);
try {
prov.addAlias(acct, dlName);
} catch (ServiceException e) {
if (AccountServiceException.ACCOUNT_EXISTS.equals(e.getCode()))
good = true;
}
assertTrue(good);
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvAlias method testCreateAlias_aliasExistAndDangling.
/*
* test adding an alias to account but the alias is "dangling"
* i.e. the alias entry exists but points to a non-existing entry
*
* The dangling alias should be removed then recreated and then added to the account
*/
@Test
public void testCreateAlias_aliasExistAndDangling() throws Exception {
String testName = getTestName();
// create the domain
String domainName = underscoreToHyphen(testName) + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// add an alias to the account
String aliasName = getEmail("alias-1", domainName);
prov.addAlias(acct, aliasName);
// remember the zimbraId of the alias entry
List<NamedEntry> aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 1);
String origZimbraIdOfAlias = aliases.get(0).getId();
// create 2 DLs
String dl1Name = getEmail("dl-1", domainName);
DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
String dl2Name = getEmail("dl-2", domainName);
DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
// add the alias to the two DLs
prov.addMembers(dl1, new String[] { aliasName });
prov.addMembers(dl2, new String[] { aliasName });
// now, hack it to delete the orig account entry
{
LdapEntry ldapAccount = (LdapEntry) acct;
((LdapProv) prov).getHelper().deleteEntry(ldapAccount.getDN(), LdapUsage.UNITTEST);
}
// now , try to add the alias to another account
String otherAcctName = getEmail("acct-other", domainName);
Account otherAcct = prov.createAccount(otherAcctName, PASSWORD, new HashMap<String, Object>());
prov.addAlias(otherAcct, aliasName);
// reload all entries
// mProv.reload(acct); this account should be gone already
prov.reload(otherAcct);
prov.reload(dl1);
prov.reload(dl2);
Set<String> values;
// ensure the alias is added to the other account
values = acct.getMultiAttrSet(Provisioning.A_mail);
assertTrue(values.contains(aliasName));
values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
assertTrue(values.contains(aliasName));
// ensure the alias is removed from all the DLs
values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
assertFalse(values.contains(aliasName));
// ensure the alias entry is is recreated (by verifing that it's got a diff zimbraId)
aliases = searchAliasesInDomain(domain);
assertEquals(aliases.size(), 1);
assertFalse(aliases.get(0).getId().equals(origZimbraIdOfAlias));
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class TestProvIDN method createDistributionList.
private DistributionList createDistributionList(String email, String description) throws Exception {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_description, "=====" + description + "=====");
DistributionList dl = prov.createDistributionList(email, attrs);
assertNotNull(dl);
return dl;
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class GetDistributionList method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetDistributionListRequest req = JaxbUtil.elementToJaxb(request);
int limit = (req.getLimit() == null) ? 0 : req.getLimit();
if (limit < 0) {
throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
}
int offset = (req.getOffset() == null) ? 0 : req.getOffset();
if (offset < 0) {
throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
}
boolean sortAscending = !Boolean.FALSE.equals(req.isSortAscending());
Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.distributionList);
DistributionListSelector dlSel = req.getDl();
DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
AttrRightChecker arc = null;
Group group = getGroupFromContext(context);
if (group == null) {
if (DistributionListBy.name.equals(dlBy)) {
Entry pseudoTarget = pseudoTargetInSameDomainAsEmail(TargetType.dl, dlSel.getKey());
if (null != pseudoTarget) {
AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) pseudoTarget, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(pseudoTarget);
}
}
if (arc != null) {
defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
} else {
defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, Admin.R_getDistributionList);
}
} else if (group.isDynamic()) {
AdminAccessControl aac = checkDynamicGroupRight(zsc, (DynamicGroup) group, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(group);
} else {
AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) group, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(group);
}
defendAgainstGroupHarvesting(group, dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_RESPONSE);
Element eDL = encodeDistributionList(response, group, true, false, reqAttrs, arc);
// return member info only if the authed has right to see zimbraMailForwardingAddress
boolean allowMembers = true;
if (group.isDynamic()) {
allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_member);
} else {
allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_zimbraMailForwardingAddress);
}
if (allowMembers) {
encodeMembers(response, eDL, group, offset, limit, sortAscending);
}
return response;
}
use of com.zimbra.cs.account.DistributionList in project zm-mailbox by Zimbra.
the class GetDistributionListMembership method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetDistributionListMembershipRequest req = JaxbUtil.elementToJaxb(request);
int limit = (req.getLimit() == null) ? 0 : req.getLimit();
if (limit < 0) {
throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
}
int offset = (req.getOffset() == null) ? 0 : req.getOffset();
if (offset < 0) {
throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
}
DistributionListSelector dlSel = req.getDl();
DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
String dlKey = dlSel.getKey();
DistributionList distributionList = prov.get(dlBy, dlKey);
defendAgainstGroupHarvesting(distributionList, dlBy, dlKey, zsc, Admin.R_getDistributionListMembership, /* shouldn't be used */
Admin.R_getDistributionListMembership);
HashMap<String, String> via = new HashMap<String, String>();
List<DistributionList> lists = prov.getDistributionLists(distributionList, false, via);
Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_MEMBERSHIP_RESPONSE);
for (DistributionList dl : lists) {
Element dlEl = response.addNonUniqueElement(AdminConstants.E_DL);
dlEl.addAttribute(AdminConstants.A_NAME, dl.getName());
dlEl.addAttribute(AdminConstants.A_ID, dl.getId());
String viaDl = via.get(dl.getName());
if (viaDl != null)
dlEl.addAttribute(AdminConstants.A_VIA, viaDl);
}
return response;
}
Aggregations