Search in sources :

Example 31 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class ImapPath method isValidImapPath.

/**
     * Mostly checking that the path doesn't clash with any paths we don't want to expose via IMAP.
     * Separated out from isVisible() to aid IMAP LSUB command support.
     */
boolean isValidImapPath() throws ServiceException {
    if (mCredentials != null) {
        if (mCredentials.isHackEnabled(ImapCredentials.EnabledHack.WM5)) {
            String lcname = mPath.toLowerCase();
            if (lcname.startsWith("sent items") && (lcname.length() == 10 || lcname.charAt(10) == '/'))
                return false;
        }
    }
    try {
        // you cannot access your own mailbox via the /home/username mechanism
        if (mOwner != null && belongsTo(mCredentials))
            return false;
        getFolder();
        if (mFolder instanceof Folder) {
            Folder folder = (Folder) mFolder;
            // hide all system folders and the user root folder
            if (folder.getId() == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
                return false;
            }
            // hide spam folder unless anti-spam feature is enabled.
            if (folder.getId() == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
                return false;
            }
            boolean isMailFolders = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
            if (!isVisible(folder.getDefaultView(), isMailFolders)) {
                return false;
            }
            // hide subfolders of trashed mountpoints
            if (mReferent != this && folder.inTrash() && !((Mountpoint) folder).getTarget().equals(mReferent.asItemId())) {
                return false;
            }
            // hide other users' mountpoints and mountpoints that point to the same mailbox
            if (folder instanceof Mountpoint && mReferent == this && mScope != Scope.UNPARSED) {
                return false;
            }
            // search folder visibility depends on an account setting
            if (folder instanceof SearchFolder) {
                return ((SearchFolder) folder).isImapVisible() && ImapFolder.getTypeConstraint((SearchFolder) folder).size() > 0;
            }
        } else {
            ZFolder zfolder = (ZFolder) mFolder;
            int folderId = asItemId().getId();
            // the mailbox root folder is not visible
            if (folderId == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
                return false;
            }
            // hide spam folder unless anti-spam feature is enabled.
            if (folderId == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
                return false;
            }
            // calendars, briefcases, etc. are not surfaced in IMAP
            ZFolder.View view = zfolder.getDefaultView();
            if (view == ZFolder.View.appointment || view == ZFolder.View.task || view == ZFolder.View.wiki || view == ZFolder.View.document) {
                return false;
            }
            // hide other users' mountpoints and mountpoints that point to the same mailbox
            if (zfolder instanceof ZMountpoint && mReferent == this && mScope != Scope.UNPARSED) {
                return false;
            }
            // hide all remote searchfolders
            if (zfolder instanceof ZSearchFolder) {
                return false;
            }
        }
    } catch (NoSuchItemException ignore) {
    // 6.3.9.  LSUB Command
    //   The server MUST NOT unilaterally remove an existing mailbox name from the subscription list even if a
    //   mailbox by that name no longer exists.
    } catch (AccountServiceException ase) {
        if (!AccountServiceException.NO_SUCH_ACCOUNT.equals(ase.getCode())) {
            throw ase;
        }
    } catch (ServiceException se) {
        if (ServiceException.PERM_DENIED.equals(se.getCode())) {
            // Path probably OK.  For subscriptions, don't disallow path for possibly temporary permissions issue
            return true;
        }
        throw se;
    }
    return mReferent == this ? true : mReferent.isValidImapPath();
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Folder(com.zimbra.cs.mailbox.Folder) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder)

Example 32 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvServer method createServerAlreadyExists.

@Test
public void createServerAlreadyExists() throws Exception {
    String SERVER_NAME = Names.makeServerName(genServerName());
    Server server = createServer(SERVER_NAME);
    boolean caughtException = false;
    try {
        prov.createServer(SERVER_NAME, new HashMap<String, Object>());
    } catch (AccountServiceException e) {
        if (AccountServiceException.SERVER_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteServer(server);
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) Server(com.zimbra.cs.account.Server)

Example 33 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvModifyAttrs method invalidAttrName.

@Test
public void invalidAttrName() throws Exception {
    // settting muliple values to a single-valued attr
    String ATTR_NAME = "bogus";
    String ATTR_VALUE = "invalidAttrValue";
    Account acct = createAccount(genAcctNameLocalPart());
    boolean caughtException = false;
    try {
        modifySingleValue(acct, "+" + ATTR_NAME, ATTR_VALUE);
    } catch (AccountServiceException e) {
        if (AccountServiceException.INVALID_ATTR_NAME.equals(e.getCode())) {
            caughtException = true;
        }
    } catch (ServiceException e) {
        if (InMemoryLdapServer.isOn()) {
            /*
                 * ubid InMemoryDirectoryServer returns OBJECT_CLASS_VIOLATION instead of 
                 * UNDEFINED_ATTRIBUTE_TYPE.  OBJECT_CLASS_VIOLATION 
                 * is mapped to FAILURE in LdapProvisioning
                 */
            if (AccountServiceException.FAILURE.equals(e.getCode())) {
                caughtException = true;
            }
        }
    }
    assertTrue(caughtException);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 34 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class TestLdapProvSignature method createSignatureAlreadyExists.

@Test
public void createSignatureAlreadyExists() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Signature signature = createSignature(acct, SIGNATURE_NAME);
    boolean caughtException = false;
    try {
        createSignatureRaw(acct, SIGNATURE_NAME);
    } catch (AccountServiceException e) {
        if (AccountServiceException.SIGNATURE_EXISTS.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    deleteSignature(acct, signature);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Signature(com.zimbra.cs.account.Signature) Test(org.junit.Test)

Example 35 with AccountServiceException

use of com.zimbra.cs.account.AccountServiceException in project zm-mailbox by Zimbra.

the class LdapProvisioning method createAlwaysOnCluster.

@Override
public AlwaysOnCluster createAlwaysOnCluster(String name, Map<String, Object> clusterAttrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(clusterAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_SERVER);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(clusterAttrs);
        Set<String> ocs = LdapObjectClass.getAlwaysOnClusterObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        String zimbraIdStr = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, zimbraIdStr);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_cn, name);
        String dn = mDIT.alwaysOnClusterNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        AlwaysOnCluster cluster = getAlwaysOnClusterById(zimbraIdStr, zlc, true);
        AttributeManager.getInstance().postModify(clusterAttrs, cluster, callbackContext);
        return cluster;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.ALWAYSONCLUSTER_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create akwaysOnCluster: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

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