Search in sources :

Example 16 with AccountServiceException

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;
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ArrayList(java.util.ArrayList) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List) AccountServiceException(com.zimbra.cs.account.AccountServiceException)

Example 17 with AccountServiceException

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());
}
Also used : Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) RemoveDistributionListAliasResponse(com.zimbra.soap.admin.message.RemoveDistributionListAliasResponse) RemoveDistributionListAliasRequest(com.zimbra.soap.admin.message.RemoveDistributionListAliasRequest) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Provisioning(com.zimbra.cs.account.Provisioning)

Example 18 with AccountServiceException

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);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Cos(com.zimbra.cs.account.Cos)

Example 19 with AccountServiceException

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);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) DataSource(com.zimbra.cs.account.DataSource)

Example 20 with AccountServiceException

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);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Cos(com.zimbra.cs.account.Cos)

Aggregations

AccountServiceException (com.zimbra.cs.account.AccountServiceException)44 ServiceException (com.zimbra.common.service.ServiceException)22 LdapException (com.zimbra.cs.ldap.LdapException)20 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)20 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)20 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)19 Account (com.zimbra.cs.account.Account)14 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)14 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)13 Date (java.util.Date)13 Domain (com.zimbra.cs.account.Domain)10 HashMap (java.util.HashMap)10 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)5 Cos (com.zimbra.cs.account.Cos)4 Test (org.junit.Test)4 DistributionList (com.zimbra.cs.account.DistributionList)3 GuestAccount (com.zimbra.cs.account.GuestAccount)3 Server (com.zimbra.cs.account.Server)3 Signature (com.zimbra.cs.account.Signature)3