use of com.zimbra.soap.account.message.GetShareInfoRequest in project zm-mailbox by Zimbra.
the class TestAclPush method testAclPushAndDiscovery.
@Test
public void testAclPushAndDiscovery() throws Exception {
// create a folder in user1's mailbox
Mailbox mbox1 = MailboxManager.getInstance().getMailboxByAccount(acct1);
Folder.FolderOptions fopt = new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT);
Folder folder = mbox1.createFolder(null, "/folder1", fopt);
// grant access to the created folder to user2
Account acct2 = Provisioning.getInstance().getAccountByName(TestUtil.getAddress(USER2_NAME));
mbox1.grantAccess(null, folder.getId(), acct2.getId(), ACL.GRANTEE_USER, ACL.stringToRights("r"), null);
// Give some time for AclPushTask to run
Thread.sleep(100);
// invoke GetShareInfoRequest from user2 and check that the shared is discovered
ZMailbox zMailbox2 = TestUtil.getZMailbox(USER2_NAME);
GetShareInfoRequest req = new GetShareInfoRequest();
GetShareInfoResponse resp = zMailbox2.invokeJaxb(req);
List<ShareInfo> shares = resp.getShares();
ShareInfo share = getShare(shares, "/folder1");
assertNotNull(share);
assertEquals(acct2.getId(), share.getGranteeId());
assertEquals(ACL.typeToString(ACL.GRANTEE_USER), share.getGranteeType());
assertEquals(folder.getPath(), share.getFolderPath());
assertEquals(folder.getId(), share.getFolderId());
assertEquals(folder.getUuid(), share.getFolderUuid());
assertEquals(folder.getDefaultView().toString(), share.getDefaultView());
assertEquals("r", share.getRights());
assertEquals(acct1.getId(), share.getOwnerId());
// rename folder
mbox1.rename(null, folder.getId(), MailItem.Type.FOLDER, "/folder2");
Thread.sleep(100);
resp = zMailbox2.invokeJaxb(req);
shares = resp.getShares();
assertNotNull(getShare(shares, "/folder2"));
// create another folder and share with DL
Folder dlFolder = mbox1.createFolder(null, "/" + DL_NAME, fopt);
mbox1.grantAccess(null, dlFolder.getId(), dl.getId(), ACL.GRANTEE_GROUP, ACL.stringToRights("rwi"), null);
Thread.sleep(100);
resp = zMailbox2.invokeJaxb(req);
shares = resp.getShares();
ShareInfo dlShare = getShare(shares, "/" + DL_NAME);
assertNotNull(dlShare);
assertEquals(dl.getId(), dlShare.getGranteeId());
assertEquals(dlFolder.getPath(), dlShare.getFolderPath());
assertEquals(dlFolder.getDefaultView().toString(), dlShare.getDefaultView());
assertEquals("rwi", dlShare.getRights());
assertEquals(acct1.getId(), dlShare.getOwnerId());
// create another folder and share with "public"
Folder pubFolder = mbox1.createFolder(null, "/public", fopt);
mbox1.grantAccess(null, pubFolder.getId(), null, ACL.GRANTEE_PUBLIC, ACL.stringToRights("rw"), null);
Thread.sleep(100);
resp = zMailbox2.invokeJaxb(req);
shares = resp.getShares();
ShareInfo pubShare = getShare(shares, "/public");
assertNotNull(pubShare);
assertEquals(pubFolder.getPath(), pubShare.getFolderPath());
assertEquals(pubFolder.getDefaultView().toString(), pubShare.getDefaultView());
assertEquals("rw", pubShare.getRights());
assertEquals(acct1.getId(), pubShare.getOwnerId());
// revoke access for user2 on the first folder
mbox1.revokeAccess(null, folder.getId(), acct2.getId());
Thread.sleep(100);
resp = zMailbox2.invokeJaxb(req);
shares = resp.getShares();
assertNull(getShare(shares, "/folder2"));
assertNotNull(getShare(shares, "/" + DL_NAME));
assertNotNull(getShare(shares, "/public"));
// delete dlFolder and pubFolder
mbox1.delete(null, dlFolder.getId(), MailItem.Type.FOLDER);
mbox1.delete(null, pubFolder.getId(), MailItem.Type.FOLDER);
Thread.sleep(100);
resp = zMailbox2.invokeJaxb(req);
shares = resp.getShares();
assertNull(getShare(shares, "/" + DL_NAME));
assertNull(getShare(shares, "/public"));
}
use of com.zimbra.soap.account.message.GetShareInfoRequest in project zm-mailbox by Zimbra.
the class GetShareInfo method doGetShareInfo.
/**
* @param zsc
* @param targetAcct
* @param request
* @param response
*/
private void doGetShareInfo(ZimbraSoapContext zsc, Map<String, Object> context, Account targetAcct, Element request, GetShareInfoResponse response) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
GetShareInfoRequest req = JaxbUtil.elementToJaxb(request);
GranteeChooser granteeChooser = req.getGrantee();
byte granteeType = getGranteeType(granteeChooser);
String granteeId = granteeChooser == null ? null : granteeChooser.getId();
String granteeName = granteeChooser == null ? null : granteeChooser.getName();
Account owner = null;
AccountSelector ownerSelector = req.getOwner();
if (ownerSelector != null) {
owner = prov.get(ownerSelector);
// when an invalid user name/id is used.
if ((owner == null) || (owner.isAccountExternal())) {
return;
} else {
AccountStatus status = owner.getAccountStatus();
if (status != null && status.isClosed()) {
return;
}
}
}
OperationContext octxt = getOperationContext(zsc, context);
ShareInfo.MountedFolders mountedFolders = null;
if (!Boolean.TRUE.equals(req.getInternal())) {
// this (new ShareInfo.MountedFolders) should be executed on the requested
// account's home server.
// If we get here, we should be proxied to the right server naturally by the framework.
mountedFolders = new ShareInfo.MountedFolders(octxt, targetAcct);
}
ResultFilter resultFilter;
if (Boolean.FALSE.equals(req.getIncludeSelf())) {
resultFilter = new ResultFilterByTargetExcludeSelf(granteeId, granteeName, targetAcct);
} else {
resultFilter = new ResultFilterByTarget(granteeId, granteeName);
}
String filterDomain = null;
if (LC.PUBLIC_SHARE_VISIBILITY.samePrimaryDomain.equals(LC.getPublicShareAdvertisingScope())) {
filterDomain = targetAcct.getDomainName();
}
ResultFilter resultFilter2 = new ResultFilterForPublicShares(filterDomain);
ShareInfoVisitor visitor = new ShareInfoVisitor(prov, response, mountedFolders, resultFilter, resultFilter2);
if (owner == null) {
// retrieve from published share info
ShareInfo.Published.get(prov, targetAcct, granteeType, owner, visitor);
} else {
if (targetAcct.getId().equals(owner.getId()))
throw ServiceException.INVALID_REQUEST("cannot discover shares on self", null);
if (Provisioning.onLocalServer(owner))
ShareInfo.Discover.discover(octxt, prov, targetAcct, granteeType, owner, visitor);
else {
// issue an GetShareInfoRequest to the home server of the owner, and tell it *not*
// to proxy to the requesting account's mailbox server.
fetchRemoteShareInfo(context, request, owner.getId(), visitor);
}
}
visitor.finish();
}
Aggregations