/** * Return the ACL Ace returned from the PROPFIND call. * @param httpResponse Response Object for the request. * @param urlPath URL of the ACL * @return List of {@code AclProperty.Ace} * @throws CalDAV4JException on error retrieving them. */ public List<AclProperty.Ace> getAces(HttpResponse httpResponse, String urlPath) throws CalDAV4JException { if (succeeded(httpResponse)) { AclProperty acls = getAcl(httpResponse, urlPath); return acls.getValue(); } throw new CalDAV4JException("Error getting ACLs. PROPFIND status is: " + httpResponse.getStatusLine().getStatusCode()); }
/** * Return the AclProperty relative to a given url * * @param urlPath Location of the CalendarResource * @param httpResponse Response Object for the request. * @return AclProperty xml response or null if missing */ public AclProperty getAcl(HttpResponse httpResponse, String urlPath) { DavProperty p = getDavProperty(httpResponse, urlPath, CalDAVConstants.DNAME_ACL); if (p != null) { try { return AclProperty.createFromXml(p.toXml(DomUtil.createDocument())); } catch (DavException | ParserConfigurationException e) { log.warn("Unable to create AclProperty"); } } return null; }
/** * Build a new <code>AclProperty</code> object from the request body of the * ACL method call. * * @param aclElement * @return new <code>AclProperty</code> * @throws DavException */ public static AclProperty createFromXml(Element aclElement) throws DavException { if (!DomUtil.matches(aclElement, SecurityConstants.ACL.getName(), SecurityConstants.ACL.getNamespace())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body."); } List<Ace> aces = new ArrayList<Ace>(); ElementIterator it = DomUtil.getChildren(aclElement, Ace.XML_ACE, SecurityConstants.NAMESPACE); while (it.hasNext()) { Element aceElem = it.nextElement(); aces.add(Ace.createFromXml(aceElem)); } return new AclProperty(aces); }
/** * Build a new <code>AclProperty</code> object from the request body of the * ACL method call. * * @param aclElement * @return new <code>AclProperty</code> * @throws DavException */ public static AclProperty createFromXml(Element aclElement) throws DavException { if (!DomUtil.matches(aclElement, SecurityConstants.ACL.getName(), SecurityConstants.ACL.getNamespace())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body."); } List<Ace> aces = new ArrayList<Ace>(); ElementIterator it = DomUtil.getChildren(aclElement, Ace.XML_ACE, SecurityConstants.NAMESPACE); while (it.hasNext()) { Element aceElem = it.nextElement(); aces.add(Ace.createFromXml(aceElem)); } return new AclProperty(aces); }
/** * @see Report#init(DavResource, ReportInfo) */ public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map principalMap = new HashMap(); Iterator aceIt = ((List)((AclProperty)acl).getValue()).iterator(); while (aceIt.hasNext()) { AclProperty.Ace ace = (AclProperty.Ace) aceIt.next(); String href = ace.getPrincipal().getHref(); if (href == null && principalMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); principalMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = (MultiStatusResponse[]) principalMap.values().toArray(new MultiStatusResponse[principalMap.size()]); } }
/** * Build a new <code>AclProperty</code> object from the request body of the * ACL method call. * * @param aclElement * @return new <code>AclProperty</code> * @throws DavException */ public static AclProperty createFromXml(Element aclElement) throws DavException { if (!DomUtil.matches(aclElement, SecurityConstants.ACL.getName(), SecurityConstants.ACL.getNamespace())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body."); } List aces = new ArrayList(); ElementIterator it = DomUtil.getChildren(aclElement, Ace.XML_ACE, SecurityConstants.NAMESPACE); while (it.hasNext()) { Element aceElem = it.nextElement(); aces.add(Ace.createFromXml(aceElem)); } return new AclProperty(aces); }
/** * The ACL method * * @param request * @param response * @param resource * @throws DavException * @throws IOException */ protected void doAcl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { if (!(resource instanceof AclResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } Document doc = request.getRequestDocument(); if (doc == null) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body."); } AclProperty acl = AclProperty.createFromXml(doc.getDocumentElement()); ((AclResource)resource).alterAcl(acl); }
/** * @see Report#init(DavResource, ReportInfo) */ @Override public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>(); List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty)acl).getValue(); for (AclProperty.Ace ace : list) { String href = ace.getPrincipal().getHref(); if (href == null || respMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]); } }
/** * Used to Set the Aces at the given path. * @param client Client making the request. * @param aces Aces to set. * @param path Path to Resource * @throws CalDAV4JException on error. */ public void setAces(HttpClient client, AclProperty.Ace[] aces, String path) throws CalDAV4JException { HttpAclMethod method = null; try { method = methodFactory.createAclMethod(getCalendarCollectionRoot() + UrlUtils.defaultString(path, "") , new AclProperty(aces)); HttpResponse response = client.execute(getDefaultHttpHost(method.getURI()), method); int status = response.getStatusLine().getStatusCode(); switch (status) { case CalDAVStatus.SC_OK: break; case CalDAVStatus.SC_NOT_FOUND: throw new ResourceNotFoundException(ResourceNotFoundException.IdentifierType.PATH, method.getURI().toString()); case CalDAVStatus.SC_UNAUTHORIZED: default: throw new BadStatusException(status, method.getMethod(), getCalendarCollectionRoot()); } } catch (IOException e) { throw new CalDAV4JException("Error in ACL " + getCalendarCollectionRoot(), e); } finally { if(method != null) method.reset(); } }
/** * The ACL method * * @param request * @param response * @param resource * @throws DavException * @throws IOException */ protected void doAcl(WebdavRequest request, WebdavResponse response, DavResource resource) throws DavException, IOException { if (!(resource instanceof AclResource)) { response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED); return; } Document doc = request.getRequestDocument(); if (doc == null) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "ACL request requires a DAV:acl body."); } AclProperty acl = AclProperty.createFromXml(doc.getDocumentElement()); ((AclResource)resource).alterAcl(acl); }
/** * @see Report#init(DavResource, ReportInfo) */ @Override public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>(); List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty)acl).getValue(); for (AclProperty.Ace ace : list) { String href = ace.getPrincipal().getHref(); if (href == null || respMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]); } }