Search in sources :

Example 1 with ACL

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");
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) List(java.util.List) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashSet(java.util.HashSet) ShareInfoData(com.zimbra.cs.account.ShareInfoData) ACL(com.zimbra.cs.mailbox.ACL) Date(java.util.Date) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 2 with ACL

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);
}
Also used : Ace(com.zimbra.cs.dav.property.Acl.Ace) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ACL(com.zimbra.cs.mailbox.ACL)

Example 3 with 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;
}
Also used : Grant(com.zimbra.cs.mailbox.ACL.Grant) Ace(com.zimbra.cs.dav.property.Acl.Ace) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ArrayList(java.util.ArrayList) ACL(com.zimbra.cs.mailbox.ACL) Folder(com.zimbra.cs.mailbox.Folder) Grant(com.zimbra.cs.mailbox.ACL.Grant)

Example 4 with ACL

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;
}
Also used : Element(org.dom4j.Element) ACL(com.zimbra.cs.mailbox.ACL) HashSet(java.util.HashSet)

Example 5 with ACL

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;
}
Also used : ACL(com.zimbra.cs.mailbox.ACL) MailItem(com.zimbra.cs.mailbox.MailItem) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Aggregations

ACL (com.zimbra.cs.mailbox.ACL)15 Mailbox (com.zimbra.cs.mailbox.Mailbox)9 ServiceException (com.zimbra.common.service.ServiceException)6 Folder (com.zimbra.cs.mailbox.Folder)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Element (com.zimbra.common.soap.Element)4 MailItem (com.zimbra.cs.mailbox.MailItem)4 ZMailbox (com.zimbra.client.ZMailbox)3 OperationContext (com.zimbra.cs.mailbox.OperationContext)3 Account (com.zimbra.cs.account.Account)2 NamedEntry (com.zimbra.cs.account.NamedEntry)2 Ace (com.zimbra.cs.dav.property.Acl.Ace)2 Grant (com.zimbra.cs.mailbox.ACL.Grant)2 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)2 ItemId (com.zimbra.cs.service.util.ItemId)2 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2