NeedPrivileges.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * NeedPrivileges
  4. *
  5. * The 403-need privileges is thrown when a user didn't have the appropriate
  6. * permissions to perform an operation
  7. *
  8. * @package Sabre
  9. * @subpackage DAVACL
  10. * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
  11. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class Sabre_DAVACL_Exception_NeedPrivileges extends Sabre_DAV_Exception_Forbidden {
  15. /**
  16. * The relevant uri
  17. *
  18. * @var string
  19. */
  20. protected $uri;
  21. /**
  22. * The privileges the user didn't have.
  23. *
  24. * @var array
  25. */
  26. protected $privileges;
  27. /**
  28. * Constructor
  29. *
  30. * @param string $uri
  31. * @param array $privileges
  32. */
  33. public function __construct($uri,array $privileges) {
  34. $this->uri = $uri;
  35. $this->privileges = $privileges;
  36. parent::__construct('User did not have the required privileges (' . implode(',', $privileges) . ') for path "' . $uri . '"');
  37. }
  38. /**
  39. * Adds in extra information in the xml response.
  40. *
  41. * This method adds the {DAV:}need-privileges element as defined in rfc3744
  42. *
  43. * @param Sabre_DAV_Server $server
  44. * @param DOMElement $errorNode
  45. * @return void
  46. */
  47. public function serialize(Sabre_DAV_Server $server,DOMElement $errorNode) {
  48. $doc = $errorNode->ownerDocument;
  49. $np = $doc->createElementNS('DAV:','d:need-privileges');
  50. $errorNode->appendChild($np);
  51. foreach($this->privileges as $privilege) {
  52. $resource = $doc->createElementNS('DAV:','d:resource');
  53. $np->appendChild($resource);
  54. $resource->appendChild($doc->createElementNS('DAV:','d:href',$server->getBaseUri() . $this->uri));
  55. $priv = $doc->createElementNS('DAV:','d:privilege');
  56. $resource->appendChild($priv);
  57. preg_match('/^{([^}]*)}(.*)$/',$privilege,$privilegeParts);
  58. $priv->appendChild($doc->createElementNS($privilegeParts[1],'d:' . $privilegeParts[2]));
  59. }
  60. }
  61. }