Search in sources :

Example 1 with RequestProp

use of com.zimbra.cs.dav.DavContext.RequestProp in project zm-mailbox by Zimbra.

the class AclReports method handleAclPrincipalPropSet.

/**
     * http://tools.ietf.org/html/rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
     * Postconditions:
     *     (DAV:number-of-matches-within-limits): The number of matching principals must fall within
     *     server-specific, predefined limits. For example, this condition might be triggered if a search
     *     specification would cause the return of an extremely large number of responses.
     */
private void handleAclPrincipalPropSet(DavContext ctxt, Element query) throws DavException, ServiceException {
    /* From rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
         *    This report is only defined when the Depth header has value "0"; other values result in a
         *    400 (Bad Request) error response.  Note that [RFC3253], Section 3.6, states that if the Depth header is
         *    not present, it defaults to a value of "0".
         */
    if (ctxt.getDepth() != Depth.zero) {
        throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
    }
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    // The response body for a successful request MUST be a DAV:multistatus XML element.  In the case where there
    // are no response elements, the returned multistatus XML element is empty.
    resp.getTop(DavElements.E_MULTISTATUS);
    for (DavResource rs : getAclPrincipals(ctxt)) resp.addResource(ctxt, rs, reqProp, false);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp)

Example 2 with RequestProp

use of com.zimbra.cs.dav.DavContext.RequestProp in project zm-mailbox by Zimbra.

the class AclReports method handlePrincipalPropertySearch.

/**
     * http://tools.ietf.org/html/rfc3744#section-9.4. DAV:principal-property-search REPORT
     * Preconditions:  None
     * Postconditions: DAV:number-of-matches-within-limits
     */
private void handlePrincipalPropertySearch(DavContext ctxt, Element query) throws DavException, ServiceException {
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    // http://tools.ietf.org/html/rfc3744#section-9.4
    // The response body for a successful request MUST be a DAV:multistatus XML element.  In the case where there
    // are no response elements, the returned multistatus XML element is empty.
    resp.getTop(DavElements.E_MULTISTATUS);
    for (DavResource rs : getMatchingResources(ctxt, query)) {
        resp.addResource(ctxt, rs, reqProp, false);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp)

Example 3 with RequestProp

use of com.zimbra.cs.dav.DavContext.RequestProp in project zm-mailbox by Zimbra.

the class PropFind method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    if (ctxt.hasRequestMessage()) {
        Document req = ctxt.getRequestMessage();
        Element top = req.getRootElement();
        if (!top.getName().equals(DavElements.P_PROPFIND)) {
            throw new DavException("msg " + top.getName() + " not allowed in PROPFIND", HttpServletResponse.SC_BAD_REQUEST, null);
        }
    }
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    if (ctxt.getDepth() == Depth.one) {
        resp.addResources(ctxt, ctxt.getAllRequestedResources(), reqProp);
    } else {
        DavResource resource = ctxt.getRequestedResource();
        resp.addResource(ctxt, resource, reqProp, false);
    }
    sendResponse(ctxt);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 4 with RequestProp

use of com.zimbra.cs.dav.DavContext.RequestProp in project zm-mailbox by Zimbra.

the class PropPatch method processSetsAndRemoves.

/**
     * @param setElems - list of elements under "set" in the request.  Must NOT be null
     * @param removeElems - list of elements under "remove" in the request.  Must NOT be null
     * @return Pair - first is list of elements representing properties to set.  second is names of
     *                properties to remove.
     */
public static Pair<List<Element>, List<QName>> processSetsAndRemoves(DavContext ctxt, DavResource resource, List<Element> setElems, List<Element> removeElems, boolean isCreate) throws DavException, IOException {
    List<Element> set = Lists.newArrayList();
    List<QName> remove = Lists.newArrayList();
    RequestProp rp = new RequestProp(true);
    ctxt.setResponseProp(rp);
    for (Element propElem : setElems) {
        QName propName = propElem.getQName();
        ResourceProperty prop = resource.getProperty(propName);
        if (prop == null || !prop.isProtected()) {
            set.add(propElem);
            rp.addProp(propElem);
        } else if (isCreate && prop.isAllowSetOnCreate()) {
            set.add(propElem);
        } else {
            rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName));
        }
    }
    for (Element propElem : removeElems) {
        QName propName = propElem.getQName();
        ResourceProperty prop = resource.getProperty(propName);
        if (prop == null || !prop.isProtected()) {
            remove.add(propName);
            rp.addProp(propElem);
        } else {
            rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName));
        }
    }
    return new Pair<List<Element>, List<QName>>(set, remove);
}
Also used : ResourceProperty(com.zimbra.cs.dav.property.ResourceProperty) DavException(com.zimbra.cs.dav.DavException) QName(org.dom4j.QName) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) Pair(com.zimbra.common.util.Pair)

Example 5 with RequestProp

use of com.zimbra.cs.dav.DavContext.RequestProp in project zm-mailbox by Zimbra.

the class AclReports method handlePrincipalMatch.

/**
     * http://tools.ietf.org/html/rfc3744#section-9.3. DAV:principal-match REPORT
     *     This report is only defined when the Depth header has value "0";
     *     other values result in a 400 (Bad Request) error response.
     */
private void handlePrincipalMatch(DavContext ctxt, Element query) throws DavException, ServiceException {
    if (ctxt.getDepth() != Depth.zero) {
        throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
    }
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    // The response body for a successful request MUST be a DAV:multistatus XML element.  In the case where there
    // are no response elements, the returned multistatus XML element is empty.
    resp.getTop(DavElements.E_MULTISTATUS);
    Element principalProp = query.element(DavElements.E_PRINCIPAL_PROPERTY);
    if (principalProp == null) {
        // request must be to the principals path
        String path = ctxt.getUri();
        if (path.startsWith(UrlNamespace.PRINCIPALS_PATH))
            ret.add(UrlNamespace.getPrincipal(ctxt, ctxt.getAuthAccount()));
    } else {
        // we know of only <owner/> element
        Element owner = principalProp.element(DavElements.E_OWNER);
        if (owner != null) {
            // return the all the members of the collection.
            DavResource rs = ctxt.getRequestedResource();
            if (rs.isCollection())
                ret.addAll(rs.getChildren(ctxt));
        }
    }
    for (DavResource rs : ret) resp.addResource(ctxt, rs, reqProp, false);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Aggregations

RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)9 DavResource (com.zimbra.cs.dav.resource.DavResource)8 DavResponse (com.zimbra.cs.dav.service.DavResponse)8 Element (org.dom4j.Element)7 DavException (com.zimbra.cs.dav.DavException)6 AddressObject (com.zimbra.cs.dav.resource.AddressObject)2 AddressbookCollection (com.zimbra.cs.dav.resource.AddressbookCollection)2 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)2 ArrayList (java.util.ArrayList)2 Pair (com.zimbra.common.util.Pair)1 TimeRange (com.zimbra.cs.dav.caldav.Range.TimeRange)1 Filter (com.zimbra.cs.dav.carddav.Filter)1 ResourceProperty (com.zimbra.cs.dav.property.ResourceProperty)1 URI (java.net.URI)1 Document (org.dom4j.Document)1 QName (org.dom4j.QName)1