Search in sources :

Example 1 with DavResource

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

the class DavContext method getDestinationCollection.

public Collection getDestinationCollection() throws DavException {
    String destinationUrl = getDestinationUrl();
    if (!destinationUrl.endsWith("/")) {
        int slash = destinationUrl.lastIndexOf('/');
        destinationUrl = destinationUrl.substring(0, slash + 1);
    }
    try {
        destinationUrl = HttpUtil.urlUnescape(destinationUrl);
        destinationUrl = getInternalDestinationUrl(destinationUrl);
        DavResource r = UrlNamespace.getResourceAtUrl(this, destinationUrl);
        if (r instanceof Collection)
            return ((Collection) r);
        return UrlNamespace.getCollectionAtUrl(this, destinationUrl);
    } catch (Exception e) {
        throw new DavException("can't get destination collection", DavProtocol.STATUS_FAILED_DEPENDENCY);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) Collection(com.zimbra.cs.dav.resource.Collection) ZMountpoint(com.zimbra.client.ZMountpoint) ServiceException(com.zimbra.common.service.ServiceException) XmlParseException(com.zimbra.common.soap.XmlParseException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with DavResource

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

the class DavContext method getAllRequestedResources.

public java.util.Collection<DavResource> getAllRequestedResources() throws DavException, ServiceException {
    ArrayList<DavResource> rss = new ArrayList<DavResource>();
    if (mRequestType == RequestType.RESOURCE)
        rss = (ArrayList<DavResource>) UrlNamespace.getResources(this, mUser, mPath, getDepth() == Depth.one);
    else {
        DavResource rs = UrlNamespace.getPrincipalAtUrl(this, mUri);
        if (rs != null) {
            ZimbraLog.addToContext(ZimbraLog.C_NAME, rs.getOwner());
            rss.add(rs);
            if (getDepth() == Depth.one)
                rss.addAll(rs.getChildren(this));
        }
    }
    if (rss.isEmpty())
        throw new DavException("no DAV resource at " + mUri, HttpServletResponse.SC_NOT_FOUND, null);
    return rss;
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) ArrayList(java.util.ArrayList)

Example 3 with DavResource

use of com.zimbra.cs.dav.resource.DavResource 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 4 with DavResource

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

the class AclReports method getMatchingResources.

private ArrayList<DavResource> getMatchingResources(DavContext ctxt, Element query) throws DavException, ServiceException {
    // needs to be /principals/users, or apply-to-principal-collection-set is set.
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    boolean applyToPrincipalCollection = query.element(DavElements.E_APPLY_TO_PRINCIPAL_COLLECTION_SET) != null;
    String path = ctxt.getUri();
    if (!applyToPrincipalCollection && !path.startsWith(UrlNamespace.PRINCIPALS_PATH))
        return ret;
    // apple hack to do user / resource search
    GalSearchType type = GalSearchType.all;
    String queryType = query.attributeValue("type");
    if (queryType != null) {
        if (queryType.compareToIgnoreCase("INDIVIDUAL") == 0)
            type = GalSearchType.account;
        else if (queryType.compareToIgnoreCase("RESOURCE") == 0)
            type = GalSearchType.resource;
    }
    @SuppressWarnings("unchecked") List propSearch = query.elements(DavElements.E_PROPERTY_SEARCH);
    for (Object obj : propSearch) {
        if (!(obj instanceof Element))
            continue;
        Element ps = (Element) obj;
        Element prop = ps.element(DavElements.E_PROP);
        Element match = ps.element(DavElements.E_MATCH);
        if (prop != null && match != null) {
            Element e = (Element) prop.elements().get(0);
            ret.addAll(getMatchingPrincipals(ctxt, e.getQName(), match.getText(), type));
        }
    }
    return ret;
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 5 with DavResource

use of com.zimbra.cs.dav.resource.DavResource 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)

Aggregations

DavResource (com.zimbra.cs.dav.resource.DavResource)25 DavException (com.zimbra.cs.dav.DavException)15 Element (org.dom4j.Element)12 DavResponse (com.zimbra.cs.dav.service.DavResponse)9 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)8 ArrayList (java.util.ArrayList)7 ServiceException (com.zimbra.common.service.ServiceException)3 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)3 Collection (com.zimbra.cs.dav.resource.Collection)3 MailItemResource (com.zimbra.cs.dav.resource.MailItemResource)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Document (org.dom4j.Document)3 Account (com.zimbra.cs.account.Account)2 Provisioning (com.zimbra.cs.account.Provisioning)2 TimeRange (com.zimbra.cs.dav.caldav.Range.TimeRange)2 Ace (com.zimbra.cs.dav.property.Acl.Ace)2 AddressObject (com.zimbra.cs.dav.resource.AddressObject)2 AddressbookCollection (com.zimbra.cs.dav.resource.AddressbookCollection)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2