use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestSoap method testGetFolders.
@Test
public void testGetFolders() throws Exception {
ZMailbox.Options options = new ZMailbox.Options();
options.setAccount(USER_NAME);
options.setAccountBy(AccountBy.name);
options.setPassword(TestUtil.DEFAULT_PASSWORD);
options.setUri(TestUtil.getSoapUrl());
options.setNoSession(true);
ZMailbox mbox = ZMailbox.getMailbox(options);
ZFolder inbox = mbox.getFolderByPath("/Inbox");
Assert.assertEquals("Inbox", inbox.getName());
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestCalDav method testMkcol4addressBook.
@Test
public void testMkcol4addressBook() throws Exception {
String xml = "<D:mkcol xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:carddav\">" + " <D:set>" + " <D:prop>" + " <D:resourcetype>" + " <D:collection/>" + " <C:addressbook/>" + " </D:resourcetype>" + " <D:displayname>OtherContacts</D:displayname>" + " <C:addressbook-description xml:lang=\"en\">Extra Contacts</C:addressbook-description>" + " </D:prop>" + " </D:set>" + "</D:mkcol>";
Account dav1 = users[1].create();
StringBuilder url = getLocalServerRoot();
url.append(DavServlet.DAV_PATH).append("/").append(dav1.getName()).append("/OtherContacts/");
MkColMethod method = new MkColMethod(url.toString());
addBasicAuthHeaderForUser(method, dav1);
HttpClient client = new HttpClient();
method.addRequestHeader("Content-Type", MimeConstants.CT_TEXT_XML);
method.setRequestEntity(new ByteArrayRequestEntity(xml.getBytes(), MimeConstants.CT_TEXT_XML));
HttpMethodExecutor.execute(client, method, HttpStatus.SC_MULTI_STATUS);
ZMailbox.Options options = new ZMailbox.Options();
options.setAccount(dav1.getName());
options.setAccountBy(AccountBy.name);
options.setPassword(TestUtil.DEFAULT_PASSWORD);
options.setUri(TestUtil.getSoapUrl());
options.setNoSession(true);
ZMailbox mbox = ZMailbox.getMailbox(options);
ZFolder folder = mbox.getFolderByPath("/OtherContacts");
assertEquals("OtherContacts", folder.getName());
assertEquals("OtherContacts default view", View.contact, folder.getDefaultView());
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestPurge method testFolderRetentionPolicy.
/**
* Tests the SOAP API for setting retention policy on a folder.
*/
@Test
public void testFolderRetentionPolicy() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + "-testFolderRetentionPolicy");
// Set user keep policy for folder.
FolderActionSelector action = new FolderActionSelector(folder.getId(), "retentionpolicy");
RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
action.setRetentionPolicy(rp);
FolderActionRequest req = new FolderActionRequest(action);
FolderActionResponse res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(folder.getId(), res.getAction().getId());
// Make sure that the retention policy is now set.
folder = mbox.getFolderById(folder.getId());
rp = folder.getRetentionPolicy();
Assert.assertEquals(1, rp.getKeepPolicy().size());
Assert.assertEquals(0, rp.getPurgePolicy().size());
Policy p = rp.getKeepPolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("30d", p.getLifetime());
// Turn off keep policy and set purge policy.
action = new FolderActionSelector(folder.getId(), "retentionpolicy");
rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
action.setRetentionPolicy(rp);
req = new FolderActionRequest(action);
res = mbox.invokeJaxb(req);
Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
Assert.assertEquals(folder.getId(), res.getAction().getId());
// Make sure that the retention policy is now set.
folder = mbox.getFolderById(folder.getId());
rp = folder.getRetentionPolicy();
Assert.assertEquals(0, rp.getKeepPolicy().size());
Assert.assertEquals(1, rp.getPurgePolicy().size());
p = rp.getPurgePolicy().get(0);
Assert.assertEquals(Policy.Type.USER, p.getType());
Assert.assertEquals("45d", p.getLifetime());
// Start a new session and make sure that the retention policy is still returned.
mbox = TestUtil.getZMailbox(USER_NAME);
folder = mbox.getFolderById(folder.getId());
Assert.assertTrue(folder.getRetentionPolicy().isSet());
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapHandler method doDELETEACL.
boolean doDELETEACL(String tag, ImapPath path, String principal) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
try {
// make sure the requester has sufficient permissions to make the request
if ((path.getFolderRights() & ACL.RIGHT_ADMIN) == 0) {
ZimbraLog.imap.info("DELETEACL failed: user does not have admin access: " + path);
sendNO(tag, "DELETEACL failed");
return true;
}
// figure out whose permissions are being revoked
String granteeId = null;
if (principal.equals("anyone")) {
granteeId = GuestAccount.GUID_AUTHUSER;
} else {
NamedEntry entry = Provisioning.getInstance().get(AccountBy.name, principal);
if (entry == null) {
entry = Provisioning.getInstance().get(Key.DistributionListBy.name, principal);
}
if (entry != null) {
granteeId = entry.getId();
}
}
if (granteeId == null) {
ZimbraLog.imap.info("DELETEACL failed: cannot resolve principal: %s", principal);
sendNO(tag, "DELETEACL failed");
return true;
}
// and revoke the permissions appropriately
Object mboxobj = path.getOwnerMailbox();
if (mboxobj instanceof Mailbox) {
Mailbox mbox = (Mailbox) mboxobj;
Folder folder = (Folder) path.getFolder();
if (folder.getEffectiveACL() != null) {
mbox.revokeAccess(getContext(), folder.getId(), granteeId);
if (granteeId == GuestAccount.GUID_AUTHUSER) {
mbox.revokeAccess(getContext(), folder.getId(), GuestAccount.GUID_PUBLIC);
}
}
} else {
ZMailbox zmbx = (ZMailbox) mboxobj;
ZFolder zfolder = (ZFolder) path.getFolder();
if (!zfolder.getGrants().isEmpty()) {
zmbx.modifyFolderRevokeGrant(zfolder.getId(), granteeId);
if (granteeId == GuestAccount.GUID_AUTHUSER) {
zmbx.modifyFolderRevokeGrant(zfolder.getId(), GuestAccount.GUID_PUBLIC);
}
}
}
} catch (ServiceException e) {
if (e.getCode().equals(ServiceException.PERM_DENIED)) {
ZimbraLog.imap.info("DELETEACL failed: permission denied on folder: %s", path);
} else if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("DELETEACL failed: no such folder: %s", path);
} else if (e.getCode().equals(AccountServiceException.NO_SUCH_ACCOUNT)) {
ZimbraLog.imap.info("DELETEACL failed: no such account: %s", principal);
} else {
ZimbraLog.imap.warn("DELETEACL failed", e);
}
sendNO(tag, "DELETEACL failed");
return true;
}
sendNotifications(true, false);
sendOK(tag, "DELETEACL completed");
return true;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapHandler method doSETACL.
boolean doSETACL(String tag, ImapPath path, String principal, String i4rights, StoreAction action) throws IOException {
if (!checkState(tag, State.AUTHENTICATED))
return true;
// RFC 4314 2: "If rights are tied in an implementation, the implementation must be
// conservative in granting rights in response to SETACL commands--unless
// all rights in a tied set are specified, none of that set should be
// included in the ACL entry for that identifier."
short rights = 0;
for (int i = 0; i < i4rights.length(); i++) {
char c = i4rights.charAt(i);
if (IMAP_READ_RIGHTS.indexOf(c) != -1) {
if (allRightsPresent(i4rights, IMAP_READ_RIGHTS))
rights |= ACL.RIGHT_READ;
} else if (IMAP_WRITE_RIGHTS.indexOf(c) != -1) {
if (allRightsPresent(i4rights, IMAP_WRITE_RIGHTS))
rights |= ACL.RIGHT_WRITE;
} else if (IMAP_INSERT_RIGHTS.indexOf(c) != -1) {
if (allRightsPresent(i4rights, IMAP_INSERT_RIGHTS))
rights |= ACL.RIGHT_INSERT;
} else if (IMAP_DELETE_RIGHTS.indexOf(c) != -1) {
if (allRightsPresent(i4rights, IMAP_DELETE_RIGHTS))
rights |= ACL.RIGHT_DELETE;
} else if (IMAP_ADMIN_RIGHTS.indexOf(c) != -1) {
if (allRightsPresent(i4rights, IMAP_ADMIN_RIGHTS))
rights |= ACL.RIGHT_ADMIN;
} else {
// RFC 4314 3.1: "Note that an unrecognized right MUST cause the command to return
// the BAD response. In particular, the server MUST NOT silently
// ignore unrecognized rights."
ZimbraLog.imap.info("SETACL failed: invalid rights string: %s", i4rights);
sendBAD(tag, "SETACL failed: invalid right");
return true;
}
}
try {
// make sure the requester has sufficient permissions to make the request
if ((path.getFolderRights() & ACL.RIGHT_ADMIN) == 0) {
ZimbraLog.imap.info("SETACL failed: user does not have admin access: %s", path);
sendNO(tag, "SETACL failed");
return true;
}
// detect a no-op early and short-circuit out here
if (action != StoreAction.REPLACE && rights == 0) {
sendNotifications(true, false);
sendOK(tag, "SETACL completed");
return true;
}
// figure out who's being granted permissions
String granteeId = null;
byte granteeType;
if (principal.equals("anyone")) {
granteeId = GuestAccount.GUID_AUTHUSER;
granteeType = ACL.GRANTEE_AUTHUSER;
} else {
granteeType = ACL.GRANTEE_USER;
NamedEntry entry = Provisioning.getInstance().get(AccountBy.name, principal);
if (entry == null) {
entry = Provisioning.getInstance().get(Key.DistributionListBy.name, principal);
granteeType = ACL.GRANTEE_GROUP;
}
if (entry != null) {
granteeId = entry.getId();
}
}
if (granteeId == null) {
ZimbraLog.imap.info("SETACL failed: cannot resolve principal: %s", principal);
sendNO(tag, "SETACL failed");
return true;
}
// figure out the rights already granted on the folder
short oldRights = 0, newRights;
Object folderobj = path.getFolder();
if (folderobj instanceof Folder) {
ACL acl = ((Folder) folderobj).getEffectiveACL();
if (acl != null) {
for (ACL.Grant grant : acl.getGrants()) {
if (granteeId.equalsIgnoreCase(grant.getGranteeId()) || (granteeType == ACL.GRANTEE_AUTHUSER && (grant.getGranteeType() == ACL.GRANTEE_AUTHUSER || grant.getGranteeType() == ACL.GRANTEE_PUBLIC))) {
oldRights |= grant.getGrantedRights();
}
}
}
} else {
for (ZGrant zgrant : ((ZFolder) folderobj).getGrants()) {
if (granteeId.equalsIgnoreCase(zgrant.getGranteeId()) || (granteeType == ACL.GRANTEE_AUTHUSER && (zgrant.getGranteeType() == ZGrant.GranteeType.all || zgrant.getGranteeType() == ZGrant.GranteeType.pub))) {
oldRights |= ACL.stringToRights(zgrant.getPermissions());
}
}
}
// calculate the new rights we want granted on the folder
if (action == StoreAction.REMOVE) {
newRights = (short) (oldRights & ~rights);
} else if (action == StoreAction.ADD) {
newRights = (short) (oldRights | rights);
} else {
newRights = rights;
}
// and update the folder appropriately, if necessary
if (newRights != oldRights) {
if (folderobj instanceof Folder) {
Mailbox mbox = (Mailbox) path.getOwnerMailbox();
mbox.grantAccess(getContext(), ((Folder) folderobj).getId(), granteeId, granteeType, newRights, null);
} else {
ZMailbox zmbx = (ZMailbox) path.getOwnerMailbox();
ZGrant.GranteeType type = (granteeType == ACL.GRANTEE_AUTHUSER ? ZGrant.GranteeType.all : ZGrant.GranteeType.usr);
zmbx.modifyFolderGrant(((ZFolder) folderobj).getId(), type, principal, ACL.rightsToString(newRights), null);
}
}
} catch (ServiceException e) {
if (e.getCode().equals(ServiceException.PERM_DENIED)) {
ZimbraLog.imap.info("SETACL failed: permission denied on folder: %s", path);
} else if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("SETACL failed: no such folder: %s", path);
} else if (e.getCode().equals(AccountServiceException.NO_SUCH_ACCOUNT)) {
ZimbraLog.imap.info("SETACL failed: no such account: %s", principal);
} else {
ZimbraLog.imap.warn("SETACL failed", e);
}
sendNO(tag, "SETACL failed");
return true;
}
sendNotifications(true, false);
sendOK(tag, "SETACL completed");
return true;
}
Aggregations