use of com.zimbra.cs.mailbox.ACL in project zm-mailbox by Zimbra.
the class AclPushTask method doWork.
public static synchronized void doWork() {
if (!supported)
return;
ZimbraLog.misc.debug("Starting pending ACL push");
Multimap<Integer, List<Integer>> currentItemIdsProcessed = ArrayListMultimap.create();
try {
Date now = new Date();
Multimap<Integer, Integer> mboxIdToItemIds = DbPendingAclPush.getEntries(now);
for (int mboxId : mboxIdToItemIds.keySet()) {
Mailbox mbox;
List<Integer> itemsProcessed = new ArrayList<Integer>();
try {
mbox = MailboxManager.getInstance().getMailboxById(mboxId);
} catch (ServiceException e) {
ZimbraLog.misc.info("Exception occurred while getting mailbox for id %s during ACL push", mboxId, e);
continue;
}
Collection<Integer> itemIds = mboxIdToItemIds.get(mboxId);
MailItem[] items = null;
try {
items = mbox.getItemById(null, itemIds, MailItem.Type.UNKNOWN);
} catch (MailServiceException.NoSuchItemException e) {
// one or more folders no longer exist
if (itemIds.size() > 1) {
List<MailItem> itemList = new ArrayList<MailItem>();
for (int itemId : itemIds) {
try {
itemList.add(mbox.getItemById(null, itemId, MailItem.Type.UNKNOWN));
} catch (MailServiceException.NoSuchItemException ignored) {
}
}
items = itemList.toArray(new MailItem[itemList.size()]);
}
}
Account account = mbox.getAccount();
String[] existingSharedItems = account.getSharedItem();
Set<String> updatedSharedItems = new HashSet<String>();
for (String sharedItem : existingSharedItems) {
ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem);
if (!itemIds.contains(shareData.getItemId())) {
updatedSharedItems.add(sharedItem);
}
}
if (items != null) {
for (MailItem item : items) {
if (item == null) {
continue;
}
// for now push the Folder grants to LDAP
if (!(item instanceof Folder)) {
continue;
}
ACL acl = item.getACL();
if (acl == null) {
continue;
}
for (ACL.Grant grant : acl.getGrants()) {
updatedSharedItems.add(AclPushSerializer.serialize(item, grant));
}
itemsProcessed.add(item.getId());
currentItemIdsProcessed.put(mboxId, itemsProcessed);
}
}
account.setSharedItem(updatedSharedItems.toArray(new String[updatedSharedItems.size()]));
}
// for
DbPendingAclPush.deleteEntries(now);
} catch (ServiceException e) {
ZimbraLog.misc.warn("Error during ACL push task", e);
} catch (Throwable t) {
// don't let exceptions kill the timer
try {
// We ran into runtime exception, so we want to delete records from ACL
// table for processed records.
deleteDbAclEntryForProcessedItems(currentItemIdsProcessed);
} catch (ServiceException e) {
ZimbraLog.misc.warn("Error during ACL push task and deleting ACL push entry.");
}
ZimbraLog.misc.warn("Error during ACL push task", t);
}
ZimbraLog.misc.debug("Finished pending ACL push");
}
use of com.zimbra.cs.mailbox.ACL in project zm-mailbox by Zimbra.
the class MailItemResource method setAce.
public void setAce(DavContext ctxt, List<Ace> aceList) throws ServiceException, DavException {
ACL acl = new ACL();
for (Ace ace : aceList) {
if (ace.getRights() > 0)
acl.grantAccess(ace.getZimbraId(), ace.getGranteeType(), ace.getRights(), null);
}
Mailbox mbox = getMailbox(ctxt);
mbox.setPermissions(ctxt.getOperationContext(), getId(), acl);
}
use of com.zimbra.cs.mailbox.ACL in project zm-mailbox by Zimbra.
the class MailItemResource method getAce.
public List<Ace> getAce(DavContext ctxt) throws ServiceException, DavException {
ArrayList<Ace> aces = new ArrayList<Ace>();
Mailbox mbox = getMailbox(ctxt);
MailItem item = mbox.getItemById(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN);
Folder f = null;
if (item.getType() == MailItem.Type.FOLDER)
f = (Folder) item;
else
f = mbox.getFolderById(ctxt.getOperationContext(), item.getParentId());
ACL effectiveAcl = f.getEffectiveACL();
if (effectiveAcl == null) {
return aces;
}
List<Grant> grants = effectiveAcl.getGrants();
if (grants == null) {
return aces;
}
for (ACL.Grant g : grants) {
if (!g.hasGrantee())
continue;
aces.add(new Ace(g.getGranteeId(), g.getGrantedRights(), g.getGranteeType()));
}
return aces;
}
use of com.zimbra.cs.mailbox.ACL in project zm-mailbox by Zimbra.
the class Acl method getAclProperties.
public static Set<ResourceProperty> getAclProperties(DavResource rs, Folder folder) throws ServiceException, DavException {
HashSet<ResourceProperty> props = new HashSet<ResourceProperty>();
if (folder == null)
return props;
String owner = rs.getOwner();
ACL acl = folder.getEffectiveACL();
props.add(getSupportedPrivilegeSet());
if (folder != null) {
// calendar feeds are read-only.
if (folder.getDefaultView() != MailItem.Type.APPOINTMENT || folder.getUrl() == null || folder.getUrl().equals("")) {
props.add(getCurrentUserPrivilegeSet(acl, folder.getAccount()));
} else {
props.add(getCurrentUserPrivilegeSet(ACL.RIGHT_READ));
}
props.add(getPrincipalCollectionSet());
}
props.add(getAcl(acl, owner));
props.add(getAclRestrictions());
ResourceProperty p = new ResourceProperty(DavElements.E_OWNER);
p.setProtected(true);
Element href = p.addChild(DavElements.E_HREF);
href.setText(UrlNamespace.getPrincipalUrl(owner));
props.add(p);
// empty properties
p = new ResourceProperty(DavElements.E_GROUP);
p.setProtected(true);
props.add(p);
p = new ResourceProperty(DavElements.E_INHERITED_ACL_SET);
p.setProtected(true);
props.add(p);
return props;
}
use of com.zimbra.cs.mailbox.ACL in project zm-mailbox by Zimbra.
the class ExpireGrantsTask method call.
/**
* Computes a result, or throws an exception if unable to do so.
*
* @return returns the item for which this task was run if we may want to schedule another instance of this
* task (at the next grant expiry); o/w null
* @throws Exception if unable to compute a result
* @see ExpireGrantsTaskCallback
*/
public MailItem call() throws Exception {
int itemId = Integer.valueOf(getProperty(ITEM_ID_PROP_NAME));
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
MailItem item;
try {
item = mbox.getItemById(null, itemId, MailItem.Type.UNKNOWN);
} catch (MailServiceException.NoSuchItemException e) {
// item seems to have been deleted; no problem
return null;
}
ACL acl = item.getACL();
if (acl == null) {
return null;
}
ZMailbox zMbox = getZMailbox(mbox);
List<ACL.Grant> grants = acl.getGrants();
long now = System.currentTimeMillis();
boolean aGrantWithExpiryExists = false;
for (ACL.Grant grant : grants) {
long expiry = grant.getEffectiveExpiry(acl);
if (expiry == 0) {
continue;
}
aGrantWithExpiryExists = true;
if (now > expiry) {
String granteeId;
switch(grant.getGranteeType()) {
case ACL.GRANTEE_PUBLIC:
granteeId = GuestAccount.GUID_PUBLIC;
break;
case ACL.GRANTEE_AUTHUSER:
granteeId = GuestAccount.GUID_AUTHUSER;
break;
default:
granteeId = grant.getGranteeId();
}
try {
String address = getGranteeAddress(grant);
if (address != null) {
sendGrantExpiryNotification(zMbox, itemId, address);
}
} finally {
mbox.revokeAccess(null, true, itemId, granteeId);
}
}
}
return aGrantWithExpiryExists ? item : null;
}
Aggregations