use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestSearchDirectory method searchDirectory.
private List searchDirectory(String key, boolean expectTooMany) throws Exception {
final String FILTER_1 = "(|(uid=*%n*)(cn=*%n*)(sn=*%n*)(gn=*%n*)(displayName=*%n*)(zimbraId=%n)(mail=*%n*)(zimbraMailAlias=*%n*)(zimbraMailDeliveryAddress=*%n*)(zimbraDomainName=*%n*))";
final String[] ATTRS = new String[] { "displayName", "zimbraId", "zimbraMailHost", "uid", "zimbraAccountStatus", "zimbraLastLogonTimestamp", "description", "zimbraMailStatus", "zimbraCalResType", "zimbraDomainType", "zimbraDomainName" };
/*
int flags = 0;
flags |= Provisioning.SD_ACCOUNT_FLAG;
flags |= Provisioning.SD_ALIAS_FLAG;
flags |= Provisioning.SD_DISTRIBUTION_LIST_FLAG;
flags |= Provisioning.SD_CALENDAR_RESOURCE_FLAG;
flags |= Provisioning.SD_DOMAIN_FLAG;
*/
String query = expandFilter(FILTER_1, key);
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setDomain(null);
options.setMaxResults(5000);
options.setFilterString(null, query);
options.setReturnAttrs(ATTRS);
options.setSortOpt(SortOpt.SORT_ASCENDING);
options.setSortAttr("name");
options.setConvertIDNToAscii(true);
List results = null;
boolean good = false;
try {
results = prov.searchDirectory(options);
good = true;
} catch (AccountServiceException e) {
if (expectTooMany && e.getCode().equals(AccountServiceException.TOO_MANY_SEARCH_RESULTS)) {
good = true;
}
} catch (Exception e) {
e.printStackTrace();
}
assertTrue(good);
return results;
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class RemoveDistributionListAlias method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
RemoveDistributionListAliasRequest req = JaxbUtil.elementToJaxb(request);
String id = req.getId();
String alias = req.getAlias();
Group group = getGroupFromContext(context);
String dlName = "";
try {
defendAgainstGroupHarvesting(group, DistributionListBy.id, id, zsc, Admin.R_removeGroupAlias, Admin.R_removeDistributionListAlias);
} catch (AccountServiceException ase) {
// still may want to remove the alias, even if it doesn't point at anything
// note: if we got a permission denied instead of AccountServiceException,
// means we don't have the rights so shouldn't get any further
}
if (group != null) {
dlName = group.getName();
}
// if the admin can remove an alias in the domain
checkDomainRightByEmail(zsc, alias, Admin.R_deleteAlias);
// even if dl is null, we still invoke removeAlias and throw an exception afterwards.
// this is so dangling aliases can be cleaned up as much as possible
prov.removeGroupAlias(group, alias);
ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RemoveDistributionListAlias", "name", dlName, "alias", alias }));
if (group == null) {
throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(id);
}
return zsc.jaxbToElement(new RemoveDistributionListAliasResponse());
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvCos method renameCosToExisting.
@Test
public void renameCosToExisting() throws Exception {
String OLD_COS_NAME = Names.makeCosName(genCosName("old"));
String NEW_COS_NAME = Provisioning.DEFAULT_COS_NAME;
Cos cos = createCos(OLD_COS_NAME);
String cosId = cos.getId();
boolean caughtException = false;
try {
prov.renameCos(cos.getId(), NEW_COS_NAME);
} catch (AccountServiceException e) {
if (AccountServiceException.COS_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteCos(cos);
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvDataSource method createDataSourceAlreadyExists.
@Test
public void createDataSourceAlreadyExists() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
Account acct = createAccount(ACCT_NAME_LOCALPART);
DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
boolean caughtException = false;
try {
createDataSourceRaw(acct, DATA_SOURCE_NAME);
} catch (AccountServiceException e) {
if (AccountServiceException.DATA_SOURCE_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteDataSource(acct, dataSource);
deleteAccount(acct);
}
use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.
the class TestLdapProvCos method createCosAlreadyExists.
@Test
public void createCosAlreadyExists() throws Exception {
String COS_NAME = Names.makeCosName(genCosName());
Cos cos = createCos(COS_NAME);
boolean caughtException = false;
try {
prov.createCos(COS_NAME, new HashMap<String, Object>());
} catch (AccountServiceException e) {
if (AccountServiceException.COS_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteCos(cos);
}
Aggregations