Search in sources :

Example 1 with MailItemResource

use of com.zimbra.cs.dav.resource.MailItemResource in project zm-mailbox by Zimbra.

the class Acl method handle.

public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    DavResource rs = ctxt.getRequestedResource();
    if (!rs.isCollection() || !(rs instanceof MailItemResource))
        throw new DavException("acl not implemented for non-collection resource", HttpServletResponse.SC_NOT_IMPLEMENTED);
    if (!ctxt.hasRequestMessage())
        throw new DavException("empty request", HttpServletResponse.SC_BAD_REQUEST);
    Document reqMsg = ctxt.getRequestMessage();
    Element acl = reqMsg.getRootElement();
    if (!acl.getQName().equals(DavElements.E_ACL))
        throw new DavException("request does not start with acl element", HttpServletResponse.SC_BAD_REQUEST);
    List<Element> aceElements = acl.elements(DavElements.E_ACE);
    ArrayList<Ace> aceList = new ArrayList<Ace>();
    for (Element ace : aceElements) aceList.add(new Ace(ace));
    MailItemResource mir = (MailItemResource) rs;
    mir.setAce(ctxt, aceList);
}
Also used : Ace(com.zimbra.cs.dav.property.Acl.Ace) DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document)

Example 2 with MailItemResource

use of com.zimbra.cs.dav.resource.MailItemResource in project zm-mailbox by Zimbra.

the class AclReports method getAclPrincipals.

private ArrayList<DavResource> getAclPrincipals(DavContext ctxt) throws DavException, ServiceException {
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    DavResource res = ctxt.getRequestedResource();
    if (!(res instanceof MailItemResource))
        return ret;
    List<Ace> aces = ((MailItemResource) res).getAce(ctxt);
    Provisioning prov = Provisioning.getInstance();
    for (Ace ace : aces) {
        if (ace.hasHref()) {
            Account acct = prov.get(Key.AccountBy.id, ace.getZimbraId());
            if (acct != null)
                ret.add(UrlNamespace.getPrincipal(ctxt, acct));
        }
    }
    return ret;
}
Also used : Account(com.zimbra.cs.account.Account) Ace(com.zimbra.cs.dav.property.Acl.Ace) DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with MailItemResource

use of com.zimbra.cs.dav.resource.MailItemResource in project zm-mailbox by Zimbra.

the class Move method checkPrecondition.

@Override
public void checkPrecondition(DavContext ctxt) throws DavException, ServiceException {
    super.checkPrecondition(ctxt);
    DavResource rs = ctxt.getRequestedResource();
    if (!(rs instanceof MailItemResource))
        throw new DavException("cannot move", HttpServletResponse.SC_BAD_REQUEST, null);
    col = ctxt.getDestinationCollection();
    mir = (MailItemResource) rs;
    if (!mir.isCollection()) {
        Collection srcCollection = ctxt.getRequestedParentCollection();
        if (srcCollection.getDefaultView() != MailItem.Type.UNKNOWN && srcCollection.getDefaultView() != col.getDefaultView())
            throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
    } else {
        // allow moving of collections of type document or unknown only.
        if (!(((Collection) mir).getDefaultView() == MailItem.Type.DOCUMENT || ((Collection) mir).getDefaultView() == MailItem.Type.UNKNOWN))
            throw new DavException("cannot move non-document collection", HttpServletResponse.SC_FORBIDDEN, null);
        // do not allow moving of collection if destination type is not document or unknown.            
        if (!(col.getDefaultView() == MailItem.Type.UNKNOWN || col.getDefaultView() == MailItem.Type.DOCUMENT))
            throw new DavException("cannot move to incompatible collection", HttpServletResponse.SC_FORBIDDEN, null);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) DavException(com.zimbra.cs.dav.DavException) Collection(com.zimbra.cs.dav.resource.Collection)

Aggregations

DavResource (com.zimbra.cs.dav.resource.DavResource)3 MailItemResource (com.zimbra.cs.dav.resource.MailItemResource)3 DavException (com.zimbra.cs.dav.DavException)2 Ace (com.zimbra.cs.dav.property.Acl.Ace)2 ArrayList (java.util.ArrayList)2 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Collection (com.zimbra.cs.dav.resource.Collection)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1