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();
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations