6 * The 403-need privileges is thrown when a user didn't have the appropriate
7 * permissions to perform an operation
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class Sabre_DAVACL_Exception_NeedPrivileges extends Sabre_DAV_Exception_Forbidden {
25 * The privileges the user didn't have.
29 protected $privileges;
35 * @param array $privileges
37 public function __construct($uri,array $privileges) {
40 $this->privileges = $privileges;
42 parent::__construct('User did not have the required privileges (' . implode(',', $privileges) . ') for path "' . $uri . '"');
47 * Adds in extra information in the xml response.
49 * This method adds the {DAV:}need-privileges element as defined in rfc3744
51 * @param Sabre_DAV_Server $server
52 * @param DOMElement $errorNode
55 public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
57 $doc = $errorNode->ownerDocument;
59 $np = $doc->createElementNS('DAV:','d:need-privileges');
60 $errorNode->appendChild($np);
62 foreach($this->privileges as $privilege) {
64 $resource = $doc->createElementNS('DAV:','d:resource');
65 $np->appendChild($resource);
67 $resource->appendChild($doc->createElementNS('DAV:','d:href',$server->getBaseUri() . $this->uri));
69 $priv = $doc->createElementNS('DAV:','d:privilege');
70 $resource->appendChild($priv);
72 preg_match('/^{([^}]*)}(.*)$/',$privilege,$privilegeParts);
73 $priv->appendChild($doc->createElementNS($privilegeParts[1],'d:' . $privilegeParts[2]));