@@ -24,54 +24,54 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class SupportedAddressData implements XmlSerializable |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * supported versions. |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $supportedData = []; |
|
| 27 | + /** |
|
| 28 | + * supported versions. |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $supportedData = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Creates the property. |
|
| 36 | - */ |
|
| 37 | - public function __construct(array $supportedData = null) |
|
| 38 | - { |
|
| 39 | - if (is_null($supportedData)) { |
|
| 40 | - $supportedData = [ |
|
| 41 | - ['contentType' => 'text/vcard', 'version' => '3.0'], |
|
| 42 | - ['contentType' => 'text/vcard', 'version' => '4.0'], |
|
| 43 | - ['contentType' => 'application/vcard+json', 'version' => '4.0'], |
|
| 44 | - ]; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * Creates the property. |
|
| 36 | + */ |
|
| 37 | + public function __construct(array $supportedData = null) |
|
| 38 | + { |
|
| 39 | + if (is_null($supportedData)) { |
|
| 40 | + $supportedData = [ |
|
| 41 | + ['contentType' => 'text/vcard', 'version' => '3.0'], |
|
| 42 | + ['contentType' => 'text/vcard', 'version' => '4.0'], |
|
| 43 | + ['contentType' => 'application/vcard+json', 'version' => '4.0'], |
|
| 44 | + ]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - $this->supportedData = $supportedData; |
|
| 48 | - } |
|
| 47 | + $this->supportedData = $supportedData; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The xmlSerialize method is called during xml writing. |
|
| 52 | - * |
|
| 53 | - * Use the $writer argument to write its own xml serialization. |
|
| 54 | - * |
|
| 55 | - * An important note: do _not_ create a parent element. Any element |
|
| 56 | - * implementing XmlSerializable should only ever write what's considered |
|
| 57 | - * its 'inner xml'. |
|
| 58 | - * |
|
| 59 | - * The parent of the current element is responsible for writing a |
|
| 60 | - * containing element. |
|
| 61 | - * |
|
| 62 | - * This allows serializers to be re-used for different element names. |
|
| 63 | - * |
|
| 64 | - * If you are opening new elements, you must also close them again. |
|
| 65 | - */ |
|
| 66 | - public function xmlSerialize(Writer $writer) |
|
| 67 | - { |
|
| 68 | - foreach ($this->supportedData as $supported) { |
|
| 69 | - $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); |
|
| 70 | - $writer->writeAttributes([ |
|
| 71 | - 'content-type' => $supported['contentType'], |
|
| 72 | - 'version' => $supported['version'], |
|
| 73 | - ]); |
|
| 74 | - $writer->endElement(); // address-data-type |
|
| 75 | - } |
|
| 76 | - } |
|
| 50 | + /** |
|
| 51 | + * The xmlSerialize method is called during xml writing. |
|
| 52 | + * |
|
| 53 | + * Use the $writer argument to write its own xml serialization. |
|
| 54 | + * |
|
| 55 | + * An important note: do _not_ create a parent element. Any element |
|
| 56 | + * implementing XmlSerializable should only ever write what's considered |
|
| 57 | + * its 'inner xml'. |
|
| 58 | + * |
|
| 59 | + * The parent of the current element is responsible for writing a |
|
| 60 | + * containing element. |
|
| 61 | + * |
|
| 62 | + * This allows serializers to be re-used for different element names. |
|
| 63 | + * |
|
| 64 | + * If you are opening new elements, you must also close them again. |
|
| 65 | + */ |
|
| 66 | + public function xmlSerialize(Writer $writer) |
|
| 67 | + { |
|
| 68 | + foreach ($this->supportedData as $supported) { |
|
| 69 | + $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); |
|
| 70 | + $writer->writeAttributes([ |
|
| 71 | + 'content-type' => $supported['contentType'], |
|
| 72 | + 'version' => $supported['version'], |
|
| 73 | + ]); |
|
| 74 | + $writer->endElement(); // address-data-type |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -19,26 +19,26 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class SupportedCollationSet implements XmlSerializable |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * The xmlSerialize method is called during xml writing. |
|
| 24 | - * |
|
| 25 | - * Use the $writer argument to write its own xml serialization. |
|
| 26 | - * |
|
| 27 | - * An important note: do _not_ create a parent element. Any element |
|
| 28 | - * implementing XmlSerializable should only ever write what's considered |
|
| 29 | - * its 'inner xml'. |
|
| 30 | - * |
|
| 31 | - * The parent of the current element is responsible for writing a |
|
| 32 | - * containing element. |
|
| 33 | - * |
|
| 34 | - * This allows serializers to be re-used for different element names. |
|
| 35 | - * |
|
| 36 | - * If you are opening new elements, you must also close them again. |
|
| 37 | - */ |
|
| 38 | - public function xmlSerialize(Writer $writer) |
|
| 39 | - { |
|
| 40 | - foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) { |
|
| 41 | - $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll); |
|
| 42 | - } |
|
| 43 | - } |
|
| 22 | + /** |
|
| 23 | + * The xmlSerialize method is called during xml writing. |
|
| 24 | + * |
|
| 25 | + * Use the $writer argument to write its own xml serialization. |
|
| 26 | + * |
|
| 27 | + * An important note: do _not_ create a parent element. Any element |
|
| 28 | + * implementing XmlSerializable should only ever write what's considered |
|
| 29 | + * its 'inner xml'. |
|
| 30 | + * |
|
| 31 | + * The parent of the current element is responsible for writing a |
|
| 32 | + * containing element. |
|
| 33 | + * |
|
| 34 | + * This allows serializers to be re-used for different element names. |
|
| 35 | + * |
|
| 36 | + * If you are opening new elements, you must also close them again. |
|
| 37 | + */ |
|
| 38 | + public function xmlSerialize(Writer $writer) |
|
| 39 | + { |
|
| 40 | + foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) { |
|
| 41 | + $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -16,187 +16,187 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Card extends DAV\File implements ICard, DAVACL\IACL |
| 18 | 18 | { |
| 19 | - use DAVACL\ACLTrait; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * CardDAV backend. |
|
| 23 | - * |
|
| 24 | - * @var Backend\BackendInterface |
|
| 25 | - */ |
|
| 26 | - protected $carddavBackend; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Array with information about this Card. |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $cardData; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Array with information about the containing addressbook. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $addressBookInfo; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Constructor. |
|
| 44 | - */ |
|
| 45 | - public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo, array $cardData) |
|
| 46 | - { |
|
| 47 | - $this->carddavBackend = $carddavBackend; |
|
| 48 | - $this->addressBookInfo = $addressBookInfo; |
|
| 49 | - $this->cardData = $cardData; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Returns the uri for this object. |
|
| 54 | - * |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function getName() |
|
| 58 | - { |
|
| 59 | - return $this->cardData['uri']; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Returns the VCard-formatted object. |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function get() |
|
| 68 | - { |
|
| 69 | - // Pre-populating 'carddata' is optional. If we don't yet have it |
|
| 70 | - // already, we fetch it from the backend. |
|
| 71 | - if (!isset($this->cardData['carddata'])) { |
|
| 72 | - $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $this->cardData['carddata']; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Updates the VCard-formatted object. |
|
| 80 | - * |
|
| 81 | - * @param string $cardData |
|
| 82 | - * |
|
| 83 | - * @return string|null |
|
| 84 | - */ |
|
| 85 | - public function put($cardData) |
|
| 86 | - { |
|
| 87 | - if (is_resource($cardData)) { |
|
| 88 | - $cardData = stream_get_contents($cardData); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Converting to UTF-8, if needed |
|
| 92 | - $cardData = DAV\StringUtil::ensureUTF8($cardData); |
|
| 93 | - |
|
| 94 | - $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); |
|
| 95 | - $this->cardData['carddata'] = $cardData; |
|
| 96 | - $this->cardData['etag'] = $etag; |
|
| 97 | - |
|
| 98 | - return $etag; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Deletes the card. |
|
| 103 | - */ |
|
| 104 | - public function delete() |
|
| 105 | - { |
|
| 106 | - $this->carddavBackend->deleteCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Returns the mime content-type. |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function getContentType() |
|
| 115 | - { |
|
| 116 | - return 'text/vcard; charset=utf-8'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Returns an ETag for this object. |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function getETag() |
|
| 125 | - { |
|
| 126 | - if (isset($this->cardData['etag'])) { |
|
| 127 | - return $this->cardData['etag']; |
|
| 128 | - } else { |
|
| 129 | - $data = $this->get(); |
|
| 130 | - if (is_string($data)) { |
|
| 131 | - return '"'.md5($data).'"'; |
|
| 132 | - } else { |
|
| 133 | - // We refuse to calculate the md5 if it's a stream. |
|
| 134 | - return null; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Returns the last modification date as a unix timestamp. |
|
| 141 | - * |
|
| 142 | - * @return int |
|
| 143 | - */ |
|
| 144 | - public function getLastModified() |
|
| 145 | - { |
|
| 146 | - return isset($this->cardData['lastmodified']) ? $this->cardData['lastmodified'] : null; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Returns the size of this object in bytes. |
|
| 151 | - * |
|
| 152 | - * @return int |
|
| 153 | - */ |
|
| 154 | - public function getSize() |
|
| 155 | - { |
|
| 156 | - if (array_key_exists('size', $this->cardData)) { |
|
| 157 | - return $this->cardData['size']; |
|
| 158 | - } else { |
|
| 159 | - return strlen($this->get()); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Returns the owner principal. |
|
| 165 | - * |
|
| 166 | - * This must be a url to a principal, or null if there's no owner |
|
| 167 | - * |
|
| 168 | - * @return string|null |
|
| 169 | - */ |
|
| 170 | - public function getOwner() |
|
| 171 | - { |
|
| 172 | - return $this->addressBookInfo['principaluri']; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Returns a list of ACE's for this node. |
|
| 177 | - * |
|
| 178 | - * Each ACE has the following properties: |
|
| 179 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 180 | - * currently the only supported privileges |
|
| 181 | - * * 'principal', a url to the principal who owns the node |
|
| 182 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 183 | - * be updated. |
|
| 184 | - * |
|
| 185 | - * @return array |
|
| 186 | - */ |
|
| 187 | - public function getACL() |
|
| 188 | - { |
|
| 189 | - // An alternative acl may be specified through the cardData array. |
|
| 190 | - if (isset($this->cardData['acl'])) { |
|
| 191 | - return $this->cardData['acl']; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return [ |
|
| 195 | - [ |
|
| 196 | - 'privilege' => '{DAV:}all', |
|
| 197 | - 'principal' => $this->addressBookInfo['principaluri'], |
|
| 198 | - 'protected' => true, |
|
| 199 | - ], |
|
| 200 | - ]; |
|
| 201 | - } |
|
| 19 | + use DAVACL\ACLTrait; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * CardDAV backend. |
|
| 23 | + * |
|
| 24 | + * @var Backend\BackendInterface |
|
| 25 | + */ |
|
| 26 | + protected $carddavBackend; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Array with information about this Card. |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $cardData; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Array with information about the containing addressbook. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $addressBookInfo; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Constructor. |
|
| 44 | + */ |
|
| 45 | + public function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo, array $cardData) |
|
| 46 | + { |
|
| 47 | + $this->carddavBackend = $carddavBackend; |
|
| 48 | + $this->addressBookInfo = $addressBookInfo; |
|
| 49 | + $this->cardData = $cardData; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Returns the uri for this object. |
|
| 54 | + * |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function getName() |
|
| 58 | + { |
|
| 59 | + return $this->cardData['uri']; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Returns the VCard-formatted object. |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function get() |
|
| 68 | + { |
|
| 69 | + // Pre-populating 'carddata' is optional. If we don't yet have it |
|
| 70 | + // already, we fetch it from the backend. |
|
| 71 | + if (!isset($this->cardData['carddata'])) { |
|
| 72 | + $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $this->cardData['carddata']; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Updates the VCard-formatted object. |
|
| 80 | + * |
|
| 81 | + * @param string $cardData |
|
| 82 | + * |
|
| 83 | + * @return string|null |
|
| 84 | + */ |
|
| 85 | + public function put($cardData) |
|
| 86 | + { |
|
| 87 | + if (is_resource($cardData)) { |
|
| 88 | + $cardData = stream_get_contents($cardData); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Converting to UTF-8, if needed |
|
| 92 | + $cardData = DAV\StringUtil::ensureUTF8($cardData); |
|
| 93 | + |
|
| 94 | + $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); |
|
| 95 | + $this->cardData['carddata'] = $cardData; |
|
| 96 | + $this->cardData['etag'] = $etag; |
|
| 97 | + |
|
| 98 | + return $etag; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Deletes the card. |
|
| 103 | + */ |
|
| 104 | + public function delete() |
|
| 105 | + { |
|
| 106 | + $this->carddavBackend->deleteCard($this->addressBookInfo['id'], $this->cardData['uri']); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Returns the mime content-type. |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function getContentType() |
|
| 115 | + { |
|
| 116 | + return 'text/vcard; charset=utf-8'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Returns an ETag for this object. |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function getETag() |
|
| 125 | + { |
|
| 126 | + if (isset($this->cardData['etag'])) { |
|
| 127 | + return $this->cardData['etag']; |
|
| 128 | + } else { |
|
| 129 | + $data = $this->get(); |
|
| 130 | + if (is_string($data)) { |
|
| 131 | + return '"'.md5($data).'"'; |
|
| 132 | + } else { |
|
| 133 | + // We refuse to calculate the md5 if it's a stream. |
|
| 134 | + return null; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Returns the last modification date as a unix timestamp. |
|
| 141 | + * |
|
| 142 | + * @return int |
|
| 143 | + */ |
|
| 144 | + public function getLastModified() |
|
| 145 | + { |
|
| 146 | + return isset($this->cardData['lastmodified']) ? $this->cardData['lastmodified'] : null; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Returns the size of this object in bytes. |
|
| 151 | + * |
|
| 152 | + * @return int |
|
| 153 | + */ |
|
| 154 | + public function getSize() |
|
| 155 | + { |
|
| 156 | + if (array_key_exists('size', $this->cardData)) { |
|
| 157 | + return $this->cardData['size']; |
|
| 158 | + } else { |
|
| 159 | + return strlen($this->get()); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Returns the owner principal. |
|
| 165 | + * |
|
| 166 | + * This must be a url to a principal, or null if there's no owner |
|
| 167 | + * |
|
| 168 | + * @return string|null |
|
| 169 | + */ |
|
| 170 | + public function getOwner() |
|
| 171 | + { |
|
| 172 | + return $this->addressBookInfo['principaluri']; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Returns a list of ACE's for this node. |
|
| 177 | + * |
|
| 178 | + * Each ACE has the following properties: |
|
| 179 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 180 | + * currently the only supported privileges |
|
| 181 | + * * 'principal', a url to the principal who owns the node |
|
| 182 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 183 | + * be updated. |
|
| 184 | + * |
|
| 185 | + * @return array |
|
| 186 | + */ |
|
| 187 | + public function getACL() |
|
| 188 | + { |
|
| 189 | + // An alternative acl may be specified through the cardData array. |
|
| 190 | + if (isset($this->cardData['acl'])) { |
|
| 191 | + return $this->cardData['acl']; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return [ |
|
| 195 | + [ |
|
| 196 | + 'privilege' => '{DAV:}all', |
|
| 197 | + 'principal' => $this->addressBookInfo['principaluri'], |
|
| 198 | + 'protected' => true, |
|
| 199 | + ], |
|
| 200 | + ]; |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -17,56 +17,56 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IACL extends DAV\INode |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Returns the owner principal. |
|
| 22 | - * |
|
| 23 | - * This must be a url to a principal, or null if there's no owner |
|
| 24 | - * |
|
| 25 | - * @return string|null |
|
| 26 | - */ |
|
| 27 | - public function getOwner(); |
|
| 20 | + /** |
|
| 21 | + * Returns the owner principal. |
|
| 22 | + * |
|
| 23 | + * This must be a url to a principal, or null if there's no owner |
|
| 24 | + * |
|
| 25 | + * @return string|null |
|
| 26 | + */ |
|
| 27 | + public function getOwner(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns a group principal. |
|
| 31 | - * |
|
| 32 | - * This must be a url to a principal, or null if there's no owner |
|
| 33 | - * |
|
| 34 | - * @return string|null |
|
| 35 | - */ |
|
| 36 | - public function getGroup(); |
|
| 29 | + /** |
|
| 30 | + * Returns a group principal. |
|
| 31 | + * |
|
| 32 | + * This must be a url to a principal, or null if there's no owner |
|
| 33 | + * |
|
| 34 | + * @return string|null |
|
| 35 | + */ |
|
| 36 | + public function getGroup(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Returns a list of ACE's for this node. |
|
| 40 | - * |
|
| 41 | - * Each ACE has the following properties: |
|
| 42 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 43 | - * currently the only supported privileges |
|
| 44 | - * * 'principal', a url to the principal who owns the node |
|
| 45 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 46 | - * be updated. |
|
| 47 | - * |
|
| 48 | - * @return array |
|
| 49 | - */ |
|
| 50 | - public function getACL(); |
|
| 38 | + /** |
|
| 39 | + * Returns a list of ACE's for this node. |
|
| 40 | + * |
|
| 41 | + * Each ACE has the following properties: |
|
| 42 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 43 | + * currently the only supported privileges |
|
| 44 | + * * 'principal', a url to the principal who owns the node |
|
| 45 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 46 | + * be updated. |
|
| 47 | + * |
|
| 48 | + * @return array |
|
| 49 | + */ |
|
| 50 | + public function getACL(); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Updates the ACL. |
|
| 54 | - * |
|
| 55 | - * This method will receive a list of new ACE's as an array argument. |
|
| 56 | - */ |
|
| 57 | - public function setACL(array $acl); |
|
| 52 | + /** |
|
| 53 | + * Updates the ACL. |
|
| 54 | + * |
|
| 55 | + * This method will receive a list of new ACE's as an array argument. |
|
| 56 | + */ |
|
| 57 | + public function setACL(array $acl); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns the list of supported privileges for this node. |
|
| 61 | - * |
|
| 62 | - * The returned data structure is a list of nested privileges. |
|
| 63 | - * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 64 | - * standard structure. |
|
| 65 | - * |
|
| 66 | - * If null is returned from this method, the default privilege set is used, |
|
| 67 | - * which is fine for most common usecases. |
|
| 68 | - * |
|
| 69 | - * @return array|null |
|
| 70 | - */ |
|
| 71 | - public function getSupportedPrivilegeSet(); |
|
| 59 | + /** |
|
| 60 | + * Returns the list of supported privileges for this node. |
|
| 61 | + * |
|
| 62 | + * The returned data structure is a list of nested privileges. |
|
| 63 | + * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 64 | + * standard structure. |
|
| 65 | + * |
|
| 66 | + * If null is returned from this method, the default privilege set is used, |
|
| 67 | + * which is fine for most common usecases. |
|
| 68 | + * |
|
| 69 | + * @return array|null |
|
| 70 | + */ |
|
| 71 | + public function getSupportedPrivilegeSet(); |
|
| 72 | 72 | } |
@@ -24,176 +24,176 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL |
| 26 | 26 | { |
| 27 | - use ACLTrait; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Struct with principal information. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $principalProperties; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Principal backend. |
|
| 38 | - * |
|
| 39 | - * @var PrincipalBackend\BackendInterface |
|
| 40 | - */ |
|
| 41 | - protected $principalBackend; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Creates the principal object. |
|
| 45 | - */ |
|
| 46 | - public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) |
|
| 47 | - { |
|
| 48 | - if (!isset($principalProperties['uri'])) { |
|
| 49 | - throw new DAV\Exception('The principal properties must at least contain the \'uri\' key'); |
|
| 50 | - } |
|
| 51 | - $this->principalBackend = $principalBackend; |
|
| 52 | - $this->principalProperties = $principalProperties; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Returns the full principal url. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getPrincipalUrl() |
|
| 61 | - { |
|
| 62 | - return $this->principalProperties['uri']; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Returns a list of alternative urls for a principal. |
|
| 67 | - * |
|
| 68 | - * This can for example be an email address, or ldap url. |
|
| 69 | - * |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function getAlternateUriSet() |
|
| 73 | - { |
|
| 74 | - $uris = []; |
|
| 75 | - if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { |
|
| 76 | - $uris = $this->principalProperties['{DAV:}alternate-URI-set']; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) { |
|
| 80 | - $uris[] = 'mailto:'.$this->principalProperties['{http://sabredav.org/ns}email-address']; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return array_unique($uris); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Returns the list of group members. |
|
| 88 | - * |
|
| 89 | - * If this principal is a group, this function should return |
|
| 90 | - * all member principal uri's for the group. |
|
| 91 | - * |
|
| 92 | - * @return array |
|
| 93 | - */ |
|
| 94 | - public function getGroupMemberSet() |
|
| 95 | - { |
|
| 96 | - return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns the list of groups this principal is member of. |
|
| 101 | - * |
|
| 102 | - * If this principal is a member of a (list of) groups, this function |
|
| 103 | - * should return a list of principal uri's for it's members. |
|
| 104 | - * |
|
| 105 | - * @return array |
|
| 106 | - */ |
|
| 107 | - public function getGroupMembership() |
|
| 108 | - { |
|
| 109 | - return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Sets a list of group members. |
|
| 114 | - * |
|
| 115 | - * If this principal is a group, this method sets all the group members. |
|
| 116 | - * The list of members is always overwritten, never appended to. |
|
| 117 | - * |
|
| 118 | - * This method should throw an exception if the members could not be set. |
|
| 119 | - */ |
|
| 120 | - public function setGroupMemberSet(array $groupMembers) |
|
| 121 | - { |
|
| 122 | - $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Returns this principals name. |
|
| 127 | - * |
|
| 128 | - * @return string |
|
| 129 | - */ |
|
| 130 | - public function getName() |
|
| 131 | - { |
|
| 132 | - $uri = $this->principalProperties['uri']; |
|
| 133 | - list(, $name) = Uri\split($uri); |
|
| 134 | - |
|
| 135 | - return $name; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Returns the name of the user. |
|
| 140 | - * |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function getDisplayName() |
|
| 144 | - { |
|
| 145 | - if (isset($this->principalProperties['{DAV:}displayname'])) { |
|
| 146 | - return $this->principalProperties['{DAV:}displayname']; |
|
| 147 | - } else { |
|
| 148 | - return $this->getName(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns a list of properties. |
|
| 154 | - * |
|
| 155 | - * @param array $requestedProperties |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public function getProperties($requestedProperties) |
|
| 160 | - { |
|
| 161 | - $newProperties = []; |
|
| 162 | - foreach ($requestedProperties as $propName) { |
|
| 163 | - if (isset($this->principalProperties[$propName])) { |
|
| 164 | - $newProperties[$propName] = $this->principalProperties[$propName]; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $newProperties; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Updates properties on this node. |
|
| 173 | - * |
|
| 174 | - * This method received a PropPatch object, which contains all the |
|
| 175 | - * information about the update. |
|
| 176 | - * |
|
| 177 | - * To update specific properties, call the 'handle' method on this object. |
|
| 178 | - * Read the PropPatch documentation for more information. |
|
| 179 | - */ |
|
| 180 | - public function propPatch(DAV\PropPatch $propPatch) |
|
| 181 | - { |
|
| 182 | - return $this->principalBackend->updatePrincipal( |
|
| 183 | - $this->principalProperties['uri'], |
|
| 184 | - $propPatch |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns the owner principal. |
|
| 190 | - * |
|
| 191 | - * This must be a url to a principal, or null if there's no owner |
|
| 192 | - * |
|
| 193 | - * @return string|null |
|
| 194 | - */ |
|
| 195 | - public function getOwner() |
|
| 196 | - { |
|
| 197 | - return $this->principalProperties['uri']; |
|
| 198 | - } |
|
| 27 | + use ACLTrait; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Struct with principal information. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $principalProperties; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Principal backend. |
|
| 38 | + * |
|
| 39 | + * @var PrincipalBackend\BackendInterface |
|
| 40 | + */ |
|
| 41 | + protected $principalBackend; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Creates the principal object. |
|
| 45 | + */ |
|
| 46 | + public function __construct(PrincipalBackend\BackendInterface $principalBackend, array $principalProperties = []) |
|
| 47 | + { |
|
| 48 | + if (!isset($principalProperties['uri'])) { |
|
| 49 | + throw new DAV\Exception('The principal properties must at least contain the \'uri\' key'); |
|
| 50 | + } |
|
| 51 | + $this->principalBackend = $principalBackend; |
|
| 52 | + $this->principalProperties = $principalProperties; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Returns the full principal url. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getPrincipalUrl() |
|
| 61 | + { |
|
| 62 | + return $this->principalProperties['uri']; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Returns a list of alternative urls for a principal. |
|
| 67 | + * |
|
| 68 | + * This can for example be an email address, or ldap url. |
|
| 69 | + * |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function getAlternateUriSet() |
|
| 73 | + { |
|
| 74 | + $uris = []; |
|
| 75 | + if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { |
|
| 76 | + $uris = $this->principalProperties['{DAV:}alternate-URI-set']; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) { |
|
| 80 | + $uris[] = 'mailto:'.$this->principalProperties['{http://sabredav.org/ns}email-address']; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return array_unique($uris); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Returns the list of group members. |
|
| 88 | + * |
|
| 89 | + * If this principal is a group, this function should return |
|
| 90 | + * all member principal uri's for the group. |
|
| 91 | + * |
|
| 92 | + * @return array |
|
| 93 | + */ |
|
| 94 | + public function getGroupMemberSet() |
|
| 95 | + { |
|
| 96 | + return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns the list of groups this principal is member of. |
|
| 101 | + * |
|
| 102 | + * If this principal is a member of a (list of) groups, this function |
|
| 103 | + * should return a list of principal uri's for it's members. |
|
| 104 | + * |
|
| 105 | + * @return array |
|
| 106 | + */ |
|
| 107 | + public function getGroupMembership() |
|
| 108 | + { |
|
| 109 | + return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Sets a list of group members. |
|
| 114 | + * |
|
| 115 | + * If this principal is a group, this method sets all the group members. |
|
| 116 | + * The list of members is always overwritten, never appended to. |
|
| 117 | + * |
|
| 118 | + * This method should throw an exception if the members could not be set. |
|
| 119 | + */ |
|
| 120 | + public function setGroupMemberSet(array $groupMembers) |
|
| 121 | + { |
|
| 122 | + $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Returns this principals name. |
|
| 127 | + * |
|
| 128 | + * @return string |
|
| 129 | + */ |
|
| 130 | + public function getName() |
|
| 131 | + { |
|
| 132 | + $uri = $this->principalProperties['uri']; |
|
| 133 | + list(, $name) = Uri\split($uri); |
|
| 134 | + |
|
| 135 | + return $name; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Returns the name of the user. |
|
| 140 | + * |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function getDisplayName() |
|
| 144 | + { |
|
| 145 | + if (isset($this->principalProperties['{DAV:}displayname'])) { |
|
| 146 | + return $this->principalProperties['{DAV:}displayname']; |
|
| 147 | + } else { |
|
| 148 | + return $this->getName(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns a list of properties. |
|
| 154 | + * |
|
| 155 | + * @param array $requestedProperties |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public function getProperties($requestedProperties) |
|
| 160 | + { |
|
| 161 | + $newProperties = []; |
|
| 162 | + foreach ($requestedProperties as $propName) { |
|
| 163 | + if (isset($this->principalProperties[$propName])) { |
|
| 164 | + $newProperties[$propName] = $this->principalProperties[$propName]; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $newProperties; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Updates properties on this node. |
|
| 173 | + * |
|
| 174 | + * This method received a PropPatch object, which contains all the |
|
| 175 | + * information about the update. |
|
| 176 | + * |
|
| 177 | + * To update specific properties, call the 'handle' method on this object. |
|
| 178 | + * Read the PropPatch documentation for more information. |
|
| 179 | + */ |
|
| 180 | + public function propPatch(DAV\PropPatch $propPatch) |
|
| 181 | + { |
|
| 182 | + return $this->principalBackend->updatePrincipal( |
|
| 183 | + $this->principalProperties['uri'], |
|
| 184 | + $propPatch |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns the owner principal. |
|
| 190 | + * |
|
| 191 | + * This must be a url to a principal, or null if there's no owner |
|
| 192 | + * |
|
| 193 | + * @return string|null |
|
| 194 | + */ |
|
| 195 | + public function getOwner() |
|
| 196 | + { |
|
| 197 | + return $this->principalProperties['uri']; |
|
| 198 | + } |
|
| 199 | 199 | } |
@@ -17,59 +17,59 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IPrincipal extends DAV\INode |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Returns a list of alternative urls for a principal. |
|
| 22 | - * |
|
| 23 | - * This can for example be an email address, or ldap url. |
|
| 24 | - * |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function getAlternateUriSet(); |
|
| 20 | + /** |
|
| 21 | + * Returns a list of alternative urls for a principal. |
|
| 22 | + * |
|
| 23 | + * This can for example be an email address, or ldap url. |
|
| 24 | + * |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function getAlternateUriSet(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns the full principal url. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function getPrincipalUrl(); |
|
| 29 | + /** |
|
| 30 | + * Returns the full principal url. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function getPrincipalUrl(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Returns the list of group members. |
|
| 38 | - * |
|
| 39 | - * If this principal is a group, this function should return |
|
| 40 | - * all member principal uri's for the group. |
|
| 41 | - * |
|
| 42 | - * @return array |
|
| 43 | - */ |
|
| 44 | - public function getGroupMemberSet(); |
|
| 36 | + /** |
|
| 37 | + * Returns the list of group members. |
|
| 38 | + * |
|
| 39 | + * If this principal is a group, this function should return |
|
| 40 | + * all member principal uri's for the group. |
|
| 41 | + * |
|
| 42 | + * @return array |
|
| 43 | + */ |
|
| 44 | + public function getGroupMemberSet(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Returns the list of groups this principal is member of. |
|
| 48 | - * |
|
| 49 | - * If this principal is a member of a (list of) groups, this function |
|
| 50 | - * should return a list of principal uri's for it's members. |
|
| 51 | - * |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 54 | - public function getGroupMembership(); |
|
| 46 | + /** |
|
| 47 | + * Returns the list of groups this principal is member of. |
|
| 48 | + * |
|
| 49 | + * If this principal is a member of a (list of) groups, this function |
|
| 50 | + * should return a list of principal uri's for it's members. |
|
| 51 | + * |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | + public function getGroupMembership(); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Sets a list of group members. |
|
| 58 | - * |
|
| 59 | - * If this principal is a group, this method sets all the group members. |
|
| 60 | - * The list of members is always overwritten, never appended to. |
|
| 61 | - * |
|
| 62 | - * This method should throw an exception if the members could not be set. |
|
| 63 | - */ |
|
| 64 | - public function setGroupMemberSet(array $principals); |
|
| 56 | + /** |
|
| 57 | + * Sets a list of group members. |
|
| 58 | + * |
|
| 59 | + * If this principal is a group, this method sets all the group members. |
|
| 60 | + * The list of members is always overwritten, never appended to. |
|
| 61 | + * |
|
| 62 | + * This method should throw an exception if the members could not be set. |
|
| 63 | + */ |
|
| 64 | + public function setGroupMemberSet(array $principals); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Returns the displayname. |
|
| 68 | - * |
|
| 69 | - * This should be a human readable name for the principal. |
|
| 70 | - * If none is available, return the nodename. |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getDisplayName(); |
|
| 66 | + /** |
|
| 67 | + * Returns the displayname. |
|
| 68 | + * |
|
| 69 | + * This should be a human readable name for the principal. |
|
| 70 | + * If none is available, return the nodename. |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getDisplayName(); |
|
| 75 | 75 | } |
@@ -32,1484 +32,1484 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class Plugin extends DAV\ServerPlugin |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * Recursion constants. |
|
| 37 | - * |
|
| 38 | - * This only checks the base node |
|
| 39 | - */ |
|
| 40 | - const R_PARENT = 1; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Recursion constants. |
|
| 44 | - * |
|
| 45 | - * This checks every node in the tree |
|
| 46 | - */ |
|
| 47 | - const R_RECURSIVE = 2; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Recursion constants. |
|
| 51 | - * |
|
| 52 | - * This checks every parentnode in the tree, but not leaf-nodes. |
|
| 53 | - */ |
|
| 54 | - const R_RECURSIVEPARENTS = 3; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Reference to server object. |
|
| 58 | - * |
|
| 59 | - * @var DAV\Server |
|
| 60 | - */ |
|
| 61 | - protected $server; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * List of urls containing principal collections. |
|
| 65 | - * Modify this if your principals are located elsewhere. |
|
| 66 | - * |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - public $principalCollectionSet = [ |
|
| 70 | - 'principals', |
|
| 71 | - ]; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * By default nodes that are inaccessible by the user, can still be seen |
|
| 75 | - * in directory listings (PROPFIND on parent with Depth: 1). |
|
| 76 | - * |
|
| 77 | - * In certain cases it's desirable to hide inaccessible nodes. Setting this |
|
| 78 | - * to true will cause these nodes to be hidden from directory listings. |
|
| 79 | - * |
|
| 80 | - * @var bool |
|
| 81 | - */ |
|
| 82 | - public $hideNodesFromListings = false; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * This list of properties are the properties a client can search on using |
|
| 86 | - * the {DAV:}principal-property-search report. |
|
| 87 | - * |
|
| 88 | - * The keys are the property names, values are descriptions. |
|
| 89 | - * |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 92 | - public $principalSearchPropertySet = [ |
|
| 93 | - '{DAV:}displayname' => 'Display name', |
|
| 94 | - '{http://sabredav.org/ns}email-address' => 'Email address', |
|
| 95 | - ]; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Any principal uri's added here, will automatically be added to the list |
|
| 99 | - * of ACL's. They will effectively receive {DAV:}all privileges, as a |
|
| 100 | - * protected privilege. |
|
| 101 | - * |
|
| 102 | - * @var array |
|
| 103 | - */ |
|
| 104 | - public $adminPrincipals = []; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * The ACL plugin allows privileges to be assigned to users that are not |
|
| 108 | - * logged in. To facilitate that, it modifies the auth plugin's behavior |
|
| 109 | - * to only require login when a privileged operation was denied. |
|
| 110 | - * |
|
| 111 | - * Unauthenticated access can be considered a security concern, so it's |
|
| 112 | - * possible to turn this feature off to harden the server's security. |
|
| 113 | - * |
|
| 114 | - * @var bool |
|
| 115 | - */ |
|
| 116 | - public $allowUnauthenticatedAccess = true; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Returns a list of features added by this plugin. |
|
| 120 | - * |
|
| 121 | - * This list is used in the response of a HTTP OPTIONS request. |
|
| 122 | - * |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function getFeatures() |
|
| 126 | - { |
|
| 127 | - return ['access-control', 'calendarserver-principal-property-search']; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Returns a list of available methods for a given url. |
|
| 132 | - * |
|
| 133 | - * @param string $uri |
|
| 134 | - * |
|
| 135 | - * @return array |
|
| 136 | - */ |
|
| 137 | - public function getMethods($uri) |
|
| 138 | - { |
|
| 139 | - return ['ACL']; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Returns a plugin name. |
|
| 144 | - * |
|
| 145 | - * Using this name other plugins will be able to access other plugins |
|
| 146 | - * using Sabre\DAV\Server::getPlugin |
|
| 147 | - * |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - public function getPluginName() |
|
| 151 | - { |
|
| 152 | - return 'acl'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Returns a list of reports this plugin supports. |
|
| 157 | - * |
|
| 158 | - * This will be used in the {DAV:}supported-report-set property. |
|
| 159 | - * Note that you still need to subscribe to the 'report' event to actually |
|
| 160 | - * implement them |
|
| 161 | - * |
|
| 162 | - * @param string $uri |
|
| 163 | - * |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - public function getSupportedReportSet($uri) |
|
| 167 | - { |
|
| 168 | - return [ |
|
| 169 | - '{DAV:}expand-property', |
|
| 170 | - '{DAV:}principal-match', |
|
| 171 | - '{DAV:}principal-property-search', |
|
| 172 | - '{DAV:}principal-search-property-set', |
|
| 173 | - ]; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Checks if the current user has the specified privilege(s). |
|
| 178 | - * |
|
| 179 | - * You can specify a single privilege, or a list of privileges. |
|
| 180 | - * This method will throw an exception if the privilege is not available |
|
| 181 | - * and return true otherwise. |
|
| 182 | - * |
|
| 183 | - * @param string $uri |
|
| 184 | - * @param array|string $privileges |
|
| 185 | - * @param int $recursion |
|
| 186 | - * @param bool $throwExceptions if set to false, this method won't throw exceptions |
|
| 187 | - * |
|
| 188 | - * @throws NeedPrivileges |
|
| 189 | - * @throws NotAuthenticated |
|
| 190 | - * |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) |
|
| 194 | - { |
|
| 195 | - if (!is_array($privileges)) { |
|
| 196 | - $privileges = [$privileges]; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $acl = $this->getCurrentUserPrivilegeSet($uri); |
|
| 200 | - |
|
| 201 | - $failed = []; |
|
| 202 | - foreach ($privileges as $priv) { |
|
| 203 | - if (!in_array($priv, $acl)) { |
|
| 204 | - $failed[] = $priv; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if ($failed) { |
|
| 209 | - if ($this->allowUnauthenticatedAccess && is_null($this->getCurrentUserPrincipal())) { |
|
| 210 | - // We are not authenticated. Kicking in the Auth plugin. |
|
| 211 | - $authPlugin = $this->server->getPlugin('auth'); |
|
| 212 | - $reasons = $authPlugin->getLoginFailedReasons(); |
|
| 213 | - $authPlugin->challenge( |
|
| 214 | - $this->server->httpRequest, |
|
| 215 | - $this->server->httpResponse |
|
| 216 | - ); |
|
| 217 | - throw new NotAuthenticated(implode(', ', $reasons).'. Login was needed for privilege: '.implode(', ', $failed).' on '.$uri); |
|
| 218 | - } |
|
| 219 | - if ($throwExceptions) { |
|
| 220 | - throw new NeedPrivileges($uri, $failed); |
|
| 221 | - } else { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - return true; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Returns the standard users' principal. |
|
| 231 | - * |
|
| 232 | - * This is one authoritative principal url for the current user. |
|
| 233 | - * This method will return null if the user wasn't logged in. |
|
| 234 | - * |
|
| 235 | - * @return string|null |
|
| 236 | - */ |
|
| 237 | - public function getCurrentUserPrincipal() |
|
| 238 | - { |
|
| 239 | - /** @var $authPlugin \Sabre\DAV\Auth\Plugin */ |
|
| 240 | - $authPlugin = $this->server->getPlugin('auth'); |
|
| 241 | - if (!$authPlugin) { |
|
| 242 | - return null; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $authPlugin->getCurrentPrincipal(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Returns a list of principals that's associated to the current |
|
| 250 | - * user, either directly or through group membership. |
|
| 251 | - * |
|
| 252 | - * @return array |
|
| 253 | - */ |
|
| 254 | - public function getCurrentUserPrincipals() |
|
| 255 | - { |
|
| 256 | - $currentUser = $this->getCurrentUserPrincipal(); |
|
| 257 | - |
|
| 258 | - if (is_null($currentUser)) { |
|
| 259 | - return []; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return array_merge( |
|
| 263 | - [$currentUser], |
|
| 264 | - $this->getPrincipalMembership($currentUser) |
|
| 265 | - ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Sets the default ACL rules. |
|
| 270 | - * |
|
| 271 | - * These rules are used for all nodes that don't implement the IACL interface. |
|
| 272 | - */ |
|
| 273 | - public function setDefaultAcl(array $acl) |
|
| 274 | - { |
|
| 275 | - $this->defaultAcl = $acl; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Returns the default ACL rules. |
|
| 280 | - * |
|
| 281 | - * These rules are used for all nodes that don't implement the IACL interface. |
|
| 282 | - * |
|
| 283 | - * @return array |
|
| 284 | - */ |
|
| 285 | - public function getDefaultAcl() |
|
| 286 | - { |
|
| 287 | - return $this->defaultAcl; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * The default ACL rules. |
|
| 292 | - * |
|
| 293 | - * These rules are used for nodes that don't implement IACL. These default |
|
| 294 | - * set of rules allow anyone to do anything, as long as they are |
|
| 295 | - * authenticated. |
|
| 296 | - * |
|
| 297 | - * @var array |
|
| 298 | - */ |
|
| 299 | - protected $defaultAcl = [ |
|
| 300 | - [ |
|
| 301 | - 'principal' => '{DAV:}authenticated', |
|
| 302 | - 'protected' => true, |
|
| 303 | - 'privilege' => '{DAV:}all', |
|
| 304 | - ], |
|
| 305 | - ]; |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * This array holds a cache for all the principals that are associated with |
|
| 309 | - * a single principal. |
|
| 310 | - * |
|
| 311 | - * @var array |
|
| 312 | - */ |
|
| 313 | - protected $principalMembershipCache = []; |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Returns all the principal groups the specified principal is a member of. |
|
| 317 | - * |
|
| 318 | - * @param string $mainPrincipal |
|
| 319 | - * |
|
| 320 | - * @return array |
|
| 321 | - */ |
|
| 322 | - public function getPrincipalMembership($mainPrincipal) |
|
| 323 | - { |
|
| 324 | - // First check our cache |
|
| 325 | - if (isset($this->principalMembershipCache[$mainPrincipal])) { |
|
| 326 | - return $this->principalMembershipCache[$mainPrincipal]; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - $check = [$mainPrincipal]; |
|
| 330 | - $principals = []; |
|
| 331 | - |
|
| 332 | - while (count($check)) { |
|
| 333 | - $principal = array_shift($check); |
|
| 334 | - |
|
| 335 | - $node = $this->server->tree->getNodeForPath($principal); |
|
| 336 | - if ($node instanceof IPrincipal) { |
|
| 337 | - foreach ($node->getGroupMembership() as $groupMember) { |
|
| 338 | - if (!in_array($groupMember, $principals)) { |
|
| 339 | - $check[] = $groupMember; |
|
| 340 | - $principals[] = $groupMember; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Store the result in the cache |
|
| 347 | - $this->principalMembershipCache[$mainPrincipal] = $principals; |
|
| 348 | - |
|
| 349 | - return $principals; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Find out of a principal equals another principal. |
|
| 354 | - * |
|
| 355 | - * This is a quick way to find out whether a principal URI is part of a |
|
| 356 | - * group, or any subgroups. |
|
| 357 | - * |
|
| 358 | - * The first argument is the principal URI you want to check against. For |
|
| 359 | - * example the principal group, and the second argument is the principal of |
|
| 360 | - * which you want to find out of it is the same as the first principal, or |
|
| 361 | - * in a member of the first principal's group or subgroups. |
|
| 362 | - * |
|
| 363 | - * So the arguments are not interchangeable. If principal A is in group B, |
|
| 364 | - * passing 'B', 'A' will yield true, but 'A', 'B' is false. |
|
| 365 | - * |
|
| 366 | - * If the second argument is not passed, we will use the current user |
|
| 367 | - * principal. |
|
| 368 | - * |
|
| 369 | - * @param string $checkPrincipal |
|
| 370 | - * @param string $currentPrincipal |
|
| 371 | - * |
|
| 372 | - * @return bool |
|
| 373 | - */ |
|
| 374 | - public function principalMatchesPrincipal($checkPrincipal, $currentPrincipal = null) |
|
| 375 | - { |
|
| 376 | - if (is_null($currentPrincipal)) { |
|
| 377 | - $currentPrincipal = $this->getCurrentUserPrincipal(); |
|
| 378 | - } |
|
| 379 | - if ($currentPrincipal === $checkPrincipal) { |
|
| 380 | - return true; |
|
| 381 | - } |
|
| 382 | - if (is_null($currentPrincipal)) { |
|
| 383 | - return false; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - return in_array( |
|
| 387 | - $checkPrincipal, |
|
| 388 | - $this->getPrincipalMembership($currentPrincipal) |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns a tree of supported privileges for a resource. |
|
| 394 | - * |
|
| 395 | - * The returned array structure should be in this form: |
|
| 396 | - * |
|
| 397 | - * [ |
|
| 398 | - * [ |
|
| 399 | - * 'privilege' => '{DAV:}read', |
|
| 400 | - * 'abstract' => false, |
|
| 401 | - * 'aggregates' => [] |
|
| 402 | - * ] |
|
| 403 | - * ] |
|
| 404 | - * |
|
| 405 | - * Privileges can be nested using "aggregates". Doing so means that |
|
| 406 | - * if you assign someone the aggregating privilege, all the |
|
| 407 | - * sub-privileges will automatically be granted. |
|
| 408 | - * |
|
| 409 | - * Marking a privilege as abstract means that the privilege cannot be |
|
| 410 | - * directly assigned, but must be assigned via the parent privilege. |
|
| 411 | - * |
|
| 412 | - * So a more complex version might look like this: |
|
| 413 | - * |
|
| 414 | - * [ |
|
| 415 | - * [ |
|
| 416 | - * 'privilege' => '{DAV:}read', |
|
| 417 | - * 'abstract' => false, |
|
| 418 | - * 'aggregates' => [ |
|
| 419 | - * [ |
|
| 420 | - * 'privilege' => '{DAV:}read-acl', |
|
| 421 | - * 'abstract' => false, |
|
| 422 | - * 'aggregates' => [], |
|
| 423 | - * ] |
|
| 424 | - * ] |
|
| 425 | - * ] |
|
| 426 | - * ] |
|
| 427 | - * |
|
| 428 | - * @param string|INode $node |
|
| 429 | - * |
|
| 430 | - * @return array |
|
| 431 | - */ |
|
| 432 | - public function getSupportedPrivilegeSet($node) |
|
| 433 | - { |
|
| 434 | - if (is_string($node)) { |
|
| 435 | - $node = $this->server->tree->getNodeForPath($node); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $supportedPrivileges = null; |
|
| 439 | - if ($node instanceof IACL) { |
|
| 440 | - $supportedPrivileges = $node->getSupportedPrivilegeSet(); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (is_null($supportedPrivileges)) { |
|
| 444 | - // Default |
|
| 445 | - $supportedPrivileges = [ |
|
| 446 | - '{DAV:}read' => [ |
|
| 447 | - 'abstract' => false, |
|
| 448 | - 'aggregates' => [ |
|
| 449 | - '{DAV:}read-acl' => [ |
|
| 450 | - 'abstract' => false, |
|
| 451 | - 'aggregates' => [], |
|
| 452 | - ], |
|
| 453 | - '{DAV:}read-current-user-privilege-set' => [ |
|
| 454 | - 'abstract' => false, |
|
| 455 | - 'aggregates' => [], |
|
| 456 | - ], |
|
| 457 | - ], |
|
| 458 | - ], |
|
| 459 | - '{DAV:}write' => [ |
|
| 460 | - 'abstract' => false, |
|
| 461 | - 'aggregates' => [ |
|
| 462 | - '{DAV:}write-properties' => [ |
|
| 463 | - 'abstract' => false, |
|
| 464 | - 'aggregates' => [], |
|
| 465 | - ], |
|
| 466 | - '{DAV:}write-content' => [ |
|
| 467 | - 'abstract' => false, |
|
| 468 | - 'aggregates' => [], |
|
| 469 | - ], |
|
| 470 | - '{DAV:}unlock' => [ |
|
| 471 | - 'abstract' => false, |
|
| 472 | - 'aggregates' => [], |
|
| 473 | - ], |
|
| 474 | - ], |
|
| 475 | - ], |
|
| 476 | - ]; |
|
| 477 | - if ($node instanceof DAV\ICollection) { |
|
| 478 | - $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}bind'] = [ |
|
| 479 | - 'abstract' => false, |
|
| 480 | - 'aggregates' => [], |
|
| 481 | - ]; |
|
| 482 | - $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}unbind'] = [ |
|
| 483 | - 'abstract' => false, |
|
| 484 | - 'aggregates' => [], |
|
| 485 | - ]; |
|
| 486 | - } |
|
| 487 | - if ($node instanceof IACL) { |
|
| 488 | - $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}write-acl'] = [ |
|
| 489 | - 'abstract' => false, |
|
| 490 | - 'aggregates' => [], |
|
| 491 | - ]; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $this->server->emit( |
|
| 496 | - 'getSupportedPrivilegeSet', |
|
| 497 | - [$node, &$supportedPrivileges] |
|
| 498 | - ); |
|
| 499 | - |
|
| 500 | - return $supportedPrivileges; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Returns the supported privilege set as a flat list. |
|
| 505 | - * |
|
| 506 | - * This is much easier to parse. |
|
| 507 | - * |
|
| 508 | - * The returned list will be index by privilege name. |
|
| 509 | - * The value is a struct containing the following properties: |
|
| 510 | - * - aggregates |
|
| 511 | - * - abstract |
|
| 512 | - * - concrete |
|
| 513 | - * |
|
| 514 | - * @param string|INode $node |
|
| 515 | - * |
|
| 516 | - * @return array |
|
| 517 | - */ |
|
| 518 | - final public function getFlatPrivilegeSet($node) |
|
| 519 | - { |
|
| 520 | - $privs = [ |
|
| 521 | - 'abstract' => false, |
|
| 522 | - 'aggregates' => $this->getSupportedPrivilegeSet($node), |
|
| 523 | - ]; |
|
| 524 | - |
|
| 525 | - $fpsTraverse = null; |
|
| 526 | - $fpsTraverse = function ($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { |
|
| 527 | - $myPriv = [ |
|
| 528 | - 'privilege' => $privName, |
|
| 529 | - 'abstract' => isset($privInfo['abstract']) && $privInfo['abstract'], |
|
| 530 | - 'aggregates' => [], |
|
| 531 | - 'concrete' => isset($privInfo['abstract']) && $privInfo['abstract'] ? $concrete : $privName, |
|
| 532 | - ]; |
|
| 533 | - |
|
| 534 | - if (isset($privInfo['aggregates'])) { |
|
| 535 | - foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { |
|
| 536 | - $myPriv['aggregates'][] = $subPrivName; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - $flat[$privName] = $myPriv; |
|
| 541 | - |
|
| 542 | - if (isset($privInfo['aggregates'])) { |
|
| 543 | - foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { |
|
| 544 | - $fpsTraverse($subPrivName, $subPrivInfo, $myPriv['concrete'], $flat); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - }; |
|
| 548 | - |
|
| 549 | - $flat = []; |
|
| 550 | - $fpsTraverse('{DAV:}all', $privs, null, $flat); |
|
| 551 | - |
|
| 552 | - return $flat; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Returns the full ACL list. |
|
| 557 | - * |
|
| 558 | - * Either a uri or a INode may be passed. |
|
| 559 | - * |
|
| 560 | - * null will be returned if the node doesn't support ACLs. |
|
| 561 | - * |
|
| 562 | - * @param string|DAV\INode $node |
|
| 563 | - * |
|
| 564 | - * @return array |
|
| 565 | - */ |
|
| 566 | - public function getAcl($node) |
|
| 567 | - { |
|
| 568 | - if (is_string($node)) { |
|
| 569 | - $node = $this->server->tree->getNodeForPath($node); |
|
| 570 | - } |
|
| 571 | - if (!$node instanceof IACL) { |
|
| 572 | - return $this->getDefaultAcl(); |
|
| 573 | - } |
|
| 574 | - $acl = $node->getACL(); |
|
| 575 | - foreach ($this->adminPrincipals as $adminPrincipal) { |
|
| 576 | - $acl[] = [ |
|
| 577 | - 'principal' => $adminPrincipal, |
|
| 578 | - 'privilege' => '{DAV:}all', |
|
| 579 | - 'protected' => true, |
|
| 580 | - ]; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - return $acl; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Returns a list of privileges the current user has |
|
| 588 | - * on a particular node. |
|
| 589 | - * |
|
| 590 | - * Either a uri or a DAV\INode may be passed. |
|
| 591 | - * |
|
| 592 | - * null will be returned if the node doesn't support ACLs. |
|
| 593 | - * |
|
| 594 | - * @param string|DAV\INode $node |
|
| 595 | - * |
|
| 596 | - * @return array |
|
| 597 | - */ |
|
| 598 | - public function getCurrentUserPrivilegeSet($node) |
|
| 599 | - { |
|
| 600 | - if (is_string($node)) { |
|
| 601 | - $node = $this->server->tree->getNodeForPath($node); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - $acl = $this->getACL($node); |
|
| 605 | - |
|
| 606 | - $collected = []; |
|
| 607 | - |
|
| 608 | - $isAuthenticated = null !== $this->getCurrentUserPrincipal(); |
|
| 609 | - |
|
| 610 | - foreach ($acl as $ace) { |
|
| 611 | - $principal = $ace['principal']; |
|
| 612 | - |
|
| 613 | - switch ($principal) { |
|
| 614 | - case '{DAV:}owner': |
|
| 615 | - $owner = $node->getOwner(); |
|
| 616 | - if ($owner && $this->principalMatchesPrincipal($owner)) { |
|
| 617 | - $collected[] = $ace; |
|
| 618 | - } |
|
| 619 | - break; |
|
| 620 | - |
|
| 621 | - // 'all' matches for every user |
|
| 622 | - case '{DAV:}all': |
|
| 623 | - $collected[] = $ace; |
|
| 624 | - break; |
|
| 625 | - |
|
| 626 | - case '{DAV:}authenticated': |
|
| 627 | - // Authenticated users only |
|
| 628 | - if ($isAuthenticated) { |
|
| 629 | - $collected[] = $ace; |
|
| 630 | - } |
|
| 631 | - break; |
|
| 632 | - |
|
| 633 | - case '{DAV:}unauthenticated': |
|
| 634 | - // Unauthenticated users only |
|
| 635 | - if (!$isAuthenticated) { |
|
| 636 | - $collected[] = $ace; |
|
| 637 | - } |
|
| 638 | - break; |
|
| 639 | - |
|
| 640 | - default: |
|
| 641 | - if ($this->principalMatchesPrincipal($ace['principal'])) { |
|
| 642 | - $collected[] = $ace; |
|
| 643 | - } |
|
| 644 | - break; |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // Now we deduct all aggregated privileges. |
|
| 649 | - $flat = $this->getFlatPrivilegeSet($node); |
|
| 650 | - |
|
| 651 | - $collected2 = []; |
|
| 652 | - while (count($collected)) { |
|
| 653 | - $current = array_pop($collected); |
|
| 654 | - $collected2[] = $current['privilege']; |
|
| 655 | - |
|
| 656 | - if (!isset($flat[$current['privilege']])) { |
|
| 657 | - // Ignoring privileges that are not in the supported-privileges list. |
|
| 658 | - $this->server->getLogger()->debug('A node has the "'.$current['privilege'].'" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.'); |
|
| 659 | - continue; |
|
| 660 | - } |
|
| 661 | - foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) { |
|
| 662 | - $collected2[] = $subPriv; |
|
| 663 | - $collected[] = $flat[$subPriv]; |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - return array_values(array_unique($collected2)); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Returns a principal based on its uri. |
|
| 672 | - * |
|
| 673 | - * Returns null if the principal could not be found. |
|
| 674 | - * |
|
| 675 | - * @param string $uri |
|
| 676 | - * |
|
| 677 | - * @return string|null |
|
| 678 | - */ |
|
| 679 | - public function getPrincipalByUri($uri) |
|
| 680 | - { |
|
| 681 | - $result = null; |
|
| 682 | - $collections = $this->principalCollectionSet; |
|
| 683 | - foreach ($collections as $collection) { |
|
| 684 | - try { |
|
| 685 | - $principalCollection = $this->server->tree->getNodeForPath($collection); |
|
| 686 | - } catch (NotFound $e) { |
|
| 687 | - // Ignore and move on |
|
| 688 | - continue; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - if (!$principalCollection instanceof IPrincipalCollection) { |
|
| 692 | - // Not a principal collection, we're simply going to ignore |
|
| 693 | - // this. |
|
| 694 | - continue; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $result = $principalCollection->findByUri($uri); |
|
| 698 | - if ($result) { |
|
| 699 | - return $result; |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Principal property search. |
|
| 706 | - * |
|
| 707 | - * This method can search for principals matching certain values in |
|
| 708 | - * properties. |
|
| 709 | - * |
|
| 710 | - * This method will return a list of properties for the matched properties. |
|
| 711 | - * |
|
| 712 | - * @param array $searchProperties The properties to search on. This is a |
|
| 713 | - * key-value list. The keys are property |
|
| 714 | - * names, and the values the strings to |
|
| 715 | - * match them on. |
|
| 716 | - * @param array $requestedProperties this is the list of properties to |
|
| 717 | - * return for every match |
|
| 718 | - * @param string $collectionUri the principal collection to search on. |
|
| 719 | - * If this is ommitted, the standard |
|
| 720 | - * principal collection-set will be used |
|
| 721 | - * @param string $test "allof" to use AND to search the |
|
| 722 | - * properties. 'anyof' for OR. |
|
| 723 | - * |
|
| 724 | - * @return array This method returns an array structure similar to |
|
| 725 | - * Sabre\DAV\Server::getPropertiesForPath. Returned |
|
| 726 | - * properties are index by a HTTP status code. |
|
| 727 | - */ |
|
| 728 | - public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') |
|
| 729 | - { |
|
| 730 | - if (!is_null($collectionUri)) { |
|
| 731 | - $uris = [$collectionUri]; |
|
| 732 | - } else { |
|
| 733 | - $uris = $this->principalCollectionSet; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - $lookupResults = []; |
|
| 737 | - foreach ($uris as $uri) { |
|
| 738 | - $principalCollection = $this->server->tree->getNodeForPath($uri); |
|
| 739 | - if (!$principalCollection instanceof IPrincipalCollection) { |
|
| 740 | - // Not a principal collection, we're simply going to ignore |
|
| 741 | - // this. |
|
| 742 | - continue; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $results = $principalCollection->searchPrincipals($searchProperties, $test); |
|
| 746 | - foreach ($results as $result) { |
|
| 747 | - $lookupResults[] = rtrim($uri, '/').'/'.$result; |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - $matches = []; |
|
| 752 | - |
|
| 753 | - foreach ($lookupResults as $lookupResult) { |
|
| 754 | - list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $matches; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Sets up the plugin. |
|
| 762 | - * |
|
| 763 | - * This method is automatically called by the server class. |
|
| 764 | - */ |
|
| 765 | - public function initialize(DAV\Server $server) |
|
| 766 | - { |
|
| 767 | - if ($this->allowUnauthenticatedAccess) { |
|
| 768 | - $authPlugin = $server->getPlugin('auth'); |
|
| 769 | - if (!$authPlugin) { |
|
| 770 | - throw new \Exception('The Auth plugin must be loaded before the ACL plugin if you want to allow unauthenticated access.'); |
|
| 771 | - } |
|
| 772 | - $authPlugin->autoRequireLogin = false; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - $this->server = $server; |
|
| 776 | - $server->on('propFind', [$this, 'propFind'], 20); |
|
| 777 | - $server->on('beforeMethod:*', [$this, 'beforeMethod'], 20); |
|
| 778 | - $server->on('beforeBind', [$this, 'beforeBind'], 20); |
|
| 779 | - $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20); |
|
| 780 | - $server->on('propPatch', [$this, 'propPatch']); |
|
| 781 | - $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20); |
|
| 782 | - $server->on('report', [$this, 'report']); |
|
| 783 | - $server->on('method:ACL', [$this, 'httpAcl']); |
|
| 784 | - $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); |
|
| 785 | - $server->on('getPrincipalByUri', function ($principal, &$uri) { |
|
| 786 | - $uri = $this->getPrincipalByUri($principal); |
|
| 787 | - |
|
| 788 | - // Break event chain |
|
| 789 | - if ($uri) { |
|
| 790 | - return false; |
|
| 791 | - } |
|
| 792 | - }); |
|
| 793 | - |
|
| 794 | - array_push($server->protectedProperties, |
|
| 795 | - '{DAV:}alternate-URI-set', |
|
| 796 | - '{DAV:}principal-URL', |
|
| 797 | - '{DAV:}group-membership', |
|
| 798 | - '{DAV:}principal-collection-set', |
|
| 799 | - '{DAV:}current-user-principal', |
|
| 800 | - '{DAV:}supported-privilege-set', |
|
| 801 | - '{DAV:}current-user-privilege-set', |
|
| 802 | - '{DAV:}acl', |
|
| 803 | - '{DAV:}acl-restrictions', |
|
| 804 | - '{DAV:}inherited-acl-set', |
|
| 805 | - '{DAV:}owner', |
|
| 806 | - '{DAV:}group' |
|
| 807 | - ); |
|
| 808 | - |
|
| 809 | - // Automatically mapping nodes implementing IPrincipal to the |
|
| 810 | - // {DAV:}principal resourcetype. |
|
| 811 | - $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal'; |
|
| 812 | - |
|
| 813 | - // Mapping the group-member-set property to the HrefList property |
|
| 814 | - // class. |
|
| 815 | - $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href'; |
|
| 816 | - $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl'; |
|
| 817 | - $server->xml->elementMap['{DAV:}acl-principal-prop-set'] = 'Sabre\\DAVACL\\Xml\\Request\\AclPrincipalPropSetReport'; |
|
| 818 | - $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport'; |
|
| 819 | - $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport'; |
|
| 820 | - $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport'; |
|
| 821 | - $server->xml->elementMap['{DAV:}principal-match'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalMatchReport'; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - /* {{{ Event handlers */ |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Triggered before any method is handled. |
|
| 828 | - */ |
|
| 829 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) |
|
| 830 | - { |
|
| 831 | - $method = $request->getMethod(); |
|
| 832 | - $path = $request->getPath(); |
|
| 833 | - |
|
| 834 | - $exists = $this->server->tree->nodeExists($path); |
|
| 835 | - |
|
| 836 | - // If the node doesn't exists, none of these checks apply |
|
| 837 | - if (!$exists) { |
|
| 838 | - return; |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - switch ($method) { |
|
| 842 | - case 'GET': |
|
| 843 | - case 'HEAD': |
|
| 844 | - case 'OPTIONS': |
|
| 845 | - // For these 3 we only need to know if the node is readable. |
|
| 846 | - $this->checkPrivileges($path, '{DAV:}read'); |
|
| 847 | - break; |
|
| 848 | - |
|
| 849 | - case 'PUT': |
|
| 850 | - case 'LOCK': |
|
| 851 | - // This method requires the write-content priv if the node |
|
| 852 | - // already exists, and bind on the parent if the node is being |
|
| 853 | - // created. |
|
| 854 | - // The bind privilege is handled in the beforeBind event. |
|
| 855 | - $this->checkPrivileges($path, '{DAV:}write-content'); |
|
| 856 | - break; |
|
| 857 | - |
|
| 858 | - case 'UNLOCK': |
|
| 859 | - // Unlock is always allowed at the moment. |
|
| 860 | - break; |
|
| 861 | - |
|
| 862 | - case 'PROPPATCH': |
|
| 863 | - $this->checkPrivileges($path, '{DAV:}write-properties'); |
|
| 864 | - break; |
|
| 865 | - |
|
| 866 | - case 'ACL': |
|
| 867 | - $this->checkPrivileges($path, '{DAV:}write-acl'); |
|
| 868 | - break; |
|
| 869 | - |
|
| 870 | - case 'COPY': |
|
| 871 | - case 'MOVE': |
|
| 872 | - // Copy requires read privileges on the entire source tree. |
|
| 873 | - // If the target exists write-content normally needs to be |
|
| 874 | - // checked, however, we're deleting the node beforehand and |
|
| 875 | - // creating a new one after, so this is handled by the |
|
| 876 | - // beforeUnbind event. |
|
| 877 | - // |
|
| 878 | - // The creation of the new node is handled by the beforeBind |
|
| 879 | - // event. |
|
| 880 | - // |
|
| 881 | - // If MOVE is used beforeUnbind will also be used to check if |
|
| 882 | - // the sourcenode can be deleted. |
|
| 883 | - $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE); |
|
| 884 | - break; |
|
| 885 | - } |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * Triggered before a new node is created. |
|
| 890 | - * |
|
| 891 | - * This allows us to check permissions for any operation that creates a |
|
| 892 | - * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE. |
|
| 893 | - * |
|
| 894 | - * @param string $uri |
|
| 895 | - */ |
|
| 896 | - public function beforeBind($uri) |
|
| 897 | - { |
|
| 898 | - list($parentUri) = Uri\split($uri); |
|
| 899 | - $this->checkPrivileges($parentUri, '{DAV:}bind'); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * Triggered before a node is deleted. |
|
| 904 | - * |
|
| 905 | - * This allows us to check permissions for any operation that will delete |
|
| 906 | - * an existing node. |
|
| 907 | - * |
|
| 908 | - * @param string $uri |
|
| 909 | - */ |
|
| 910 | - public function beforeUnbind($uri) |
|
| 911 | - { |
|
| 912 | - list($parentUri) = Uri\split($uri); |
|
| 913 | - $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS); |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * Triggered before a node is unlocked. |
|
| 918 | - * |
|
| 919 | - * @param string $uri |
|
| 920 | - * @TODO: not yet implemented |
|
| 921 | - */ |
|
| 922 | - public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) |
|
| 923 | - { |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Triggered before properties are looked up in specific nodes. |
|
| 928 | - * |
|
| 929 | - * @TODO really should be broken into multiple methods, or even a class. |
|
| 930 | - */ |
|
| 931 | - public function propFind(DAV\PropFind $propFind, DAV\INode $node) |
|
| 932 | - { |
|
| 933 | - $path = $propFind->getPath(); |
|
| 934 | - |
|
| 935 | - // Checking the read permission |
|
| 936 | - if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) { |
|
| 937 | - // User is not allowed to read properties |
|
| 938 | - |
|
| 939 | - // Returning false causes the property-fetching system to pretend |
|
| 940 | - // that the node does not exist, and will cause it to be hidden |
|
| 941 | - // from listings such as PROPFIND or the browser plugin. |
|
| 942 | - if ($this->hideNodesFromListings) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - // Otherwise we simply mark every property as 403. |
|
| 947 | - foreach ($propFind->getRequestedProperties() as $requestedProperty) { |
|
| 948 | - $propFind->set($requestedProperty, null, 403); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - /* Adding principal properties */ |
|
| 955 | - if ($node instanceof IPrincipal) { |
|
| 956 | - $propFind->handle('{DAV:}alternate-URI-set', function () use ($node) { |
|
| 957 | - return new Href($node->getAlternateUriSet()); |
|
| 958 | - }); |
|
| 959 | - $propFind->handle('{DAV:}principal-URL', function () use ($node) { |
|
| 960 | - return new Href($node->getPrincipalUrl().'/'); |
|
| 961 | - }); |
|
| 962 | - $propFind->handle('{DAV:}group-member-set', function () use ($node) { |
|
| 963 | - $members = $node->getGroupMemberSet(); |
|
| 964 | - foreach ($members as $k => $member) { |
|
| 965 | - $members[$k] = rtrim($member, '/').'/'; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return new Href($members); |
|
| 969 | - }); |
|
| 970 | - $propFind->handle('{DAV:}group-membership', function () use ($node) { |
|
| 971 | - $members = $node->getGroupMembership(); |
|
| 972 | - foreach ($members as $k => $member) { |
|
| 973 | - $members[$k] = rtrim($member, '/').'/'; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - return new Href($members); |
|
| 977 | - }); |
|
| 978 | - $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - $propFind->handle('{DAV:}principal-collection-set', function () { |
|
| 982 | - $val = $this->principalCollectionSet; |
|
| 983 | - // Ensuring all collections end with a slash |
|
| 984 | - foreach ($val as $k => $v) { |
|
| 985 | - $val[$k] = $v.'/'; |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - return new Href($val); |
|
| 989 | - }); |
|
| 990 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 991 | - if ($url = $this->getCurrentUserPrincipal()) { |
|
| 992 | - return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url.'/'); |
|
| 993 | - } else { |
|
| 994 | - return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED); |
|
| 995 | - } |
|
| 996 | - }); |
|
| 997 | - $propFind->handle('{DAV:}supported-privilege-set', function () use ($node) { |
|
| 998 | - return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node)); |
|
| 999 | - }); |
|
| 1000 | - $propFind->handle('{DAV:}current-user-privilege-set', function () use ($node, $propFind, $path) { |
|
| 1001 | - if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) { |
|
| 1002 | - $propFind->set('{DAV:}current-user-privilege-set', null, 403); |
|
| 1003 | - } else { |
|
| 1004 | - $val = $this->getCurrentUserPrivilegeSet($node); |
|
| 1005 | - |
|
| 1006 | - return new Xml\Property\CurrentUserPrivilegeSet($val); |
|
| 1007 | - } |
|
| 1008 | - }); |
|
| 1009 | - $propFind->handle('{DAV:}acl', function () use ($node, $propFind, $path) { |
|
| 1010 | - /* The ACL property contains all the permissions */ |
|
| 1011 | - if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) { |
|
| 1012 | - $propFind->set('{DAV:}acl', null, 403); |
|
| 1013 | - } else { |
|
| 1014 | - $acl = $this->getACL($node); |
|
| 1015 | - |
|
| 1016 | - return new Xml\Property\Acl($this->getACL($node)); |
|
| 1017 | - } |
|
| 1018 | - }); |
|
| 1019 | - $propFind->handle('{DAV:}acl-restrictions', function () { |
|
| 1020 | - return new Xml\Property\AclRestrictions(); |
|
| 1021 | - }); |
|
| 1022 | - |
|
| 1023 | - /* Adding ACL properties */ |
|
| 1024 | - if ($node instanceof IACL) { |
|
| 1025 | - $propFind->handle('{DAV:}owner', function () use ($node) { |
|
| 1026 | - return new Href($node->getOwner().'/'); |
|
| 1027 | - }); |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * This method intercepts PROPPATCH methods and make sure the |
|
| 1033 | - * group-member-set is updated correctly. |
|
| 1034 | - * |
|
| 1035 | - * @param string $path |
|
| 1036 | - */ |
|
| 1037 | - public function propPatch($path, DAV\PropPatch $propPatch) |
|
| 1038 | - { |
|
| 1039 | - $propPatch->handle('{DAV:}group-member-set', function ($value) use ($path) { |
|
| 1040 | - if (is_null($value)) { |
|
| 1041 | - $memberSet = []; |
|
| 1042 | - } elseif ($value instanceof Href) { |
|
| 1043 | - $memberSet = array_map( |
|
| 1044 | - [$this->server, 'calculateUri'], |
|
| 1045 | - $value->getHrefs() |
|
| 1046 | - ); |
|
| 1047 | - } else { |
|
| 1048 | - throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null'); |
|
| 1049 | - } |
|
| 1050 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 1051 | - if (!($node instanceof IPrincipal)) { |
|
| 1052 | - // Fail |
|
| 1053 | - return false; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - $node->setGroupMemberSet($memberSet); |
|
| 1057 | - // We must also clear our cache, just in case |
|
| 1058 | - |
|
| 1059 | - $this->principalMembershipCache = []; |
|
| 1060 | - |
|
| 1061 | - return true; |
|
| 1062 | - }); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * This method handles HTTP REPORT requests. |
|
| 1067 | - * |
|
| 1068 | - * @param string $reportName |
|
| 1069 | - * @param mixed $report |
|
| 1070 | - * @param mixed $path |
|
| 1071 | - */ |
|
| 1072 | - public function report($reportName, $report, $path) |
|
| 1073 | - { |
|
| 1074 | - switch ($reportName) { |
|
| 1075 | - case '{DAV:}principal-property-search': |
|
| 1076 | - $this->server->transactionType = 'report-principal-property-search'; |
|
| 1077 | - $this->principalPropertySearchReport($path, $report); |
|
| 1078 | - |
|
| 1079 | - return false; |
|
| 1080 | - case '{DAV:}principal-search-property-set': |
|
| 1081 | - $this->server->transactionType = 'report-principal-search-property-set'; |
|
| 1082 | - $this->principalSearchPropertySetReport($path, $report); |
|
| 1083 | - |
|
| 1084 | - return false; |
|
| 1085 | - case '{DAV:}expand-property': |
|
| 1086 | - $this->server->transactionType = 'report-expand-property'; |
|
| 1087 | - $this->expandPropertyReport($path, $report); |
|
| 1088 | - |
|
| 1089 | - return false; |
|
| 1090 | - case '{DAV:}principal-match': |
|
| 1091 | - $this->server->transactionType = 'report-principal-match'; |
|
| 1092 | - $this->principalMatchReport($path, $report); |
|
| 1093 | - |
|
| 1094 | - return false; |
|
| 1095 | - case '{DAV:}acl-principal-prop-set': |
|
| 1096 | - $this->server->transactionType = 'acl-principal-prop-set'; |
|
| 1097 | - $this->aclPrincipalPropSetReport($path, $report); |
|
| 1098 | - |
|
| 1099 | - return false; |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * This method is responsible for handling the 'ACL' event. |
|
| 1105 | - * |
|
| 1106 | - * @return bool |
|
| 1107 | - */ |
|
| 1108 | - public function httpAcl(RequestInterface $request, ResponseInterface $response) |
|
| 1109 | - { |
|
| 1110 | - $path = $request->getPath(); |
|
| 1111 | - $body = $request->getBodyAsString(); |
|
| 1112 | - |
|
| 1113 | - if (!$body) { |
|
| 1114 | - throw new DAV\Exception\BadRequest('XML body expected in ACL request'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - $acl = $this->server->xml->expect('{DAV:}acl', $body); |
|
| 1118 | - $newAcl = $acl->getPrivileges(); |
|
| 1119 | - |
|
| 1120 | - // Normalizing urls |
|
| 1121 | - foreach ($newAcl as $k => $newAce) { |
|
| 1122 | - $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']); |
|
| 1123 | - } |
|
| 1124 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 1125 | - |
|
| 1126 | - if (!$node instanceof IACL) { |
|
| 1127 | - throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method'); |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - $oldAcl = $this->getACL($node); |
|
| 1131 | - |
|
| 1132 | - $supportedPrivileges = $this->getFlatPrivilegeSet($node); |
|
| 1133 | - |
|
| 1134 | - /* Checking if protected principals from the existing principal set are |
|
| 35 | + /** |
|
| 36 | + * Recursion constants. |
|
| 37 | + * |
|
| 38 | + * This only checks the base node |
|
| 39 | + */ |
|
| 40 | + const R_PARENT = 1; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Recursion constants. |
|
| 44 | + * |
|
| 45 | + * This checks every node in the tree |
|
| 46 | + */ |
|
| 47 | + const R_RECURSIVE = 2; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Recursion constants. |
|
| 51 | + * |
|
| 52 | + * This checks every parentnode in the tree, but not leaf-nodes. |
|
| 53 | + */ |
|
| 54 | + const R_RECURSIVEPARENTS = 3; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Reference to server object. |
|
| 58 | + * |
|
| 59 | + * @var DAV\Server |
|
| 60 | + */ |
|
| 61 | + protected $server; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * List of urls containing principal collections. |
|
| 65 | + * Modify this if your principals are located elsewhere. |
|
| 66 | + * |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + public $principalCollectionSet = [ |
|
| 70 | + 'principals', |
|
| 71 | + ]; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * By default nodes that are inaccessible by the user, can still be seen |
|
| 75 | + * in directory listings (PROPFIND on parent with Depth: 1). |
|
| 76 | + * |
|
| 77 | + * In certain cases it's desirable to hide inaccessible nodes. Setting this |
|
| 78 | + * to true will cause these nodes to be hidden from directory listings. |
|
| 79 | + * |
|
| 80 | + * @var bool |
|
| 81 | + */ |
|
| 82 | + public $hideNodesFromListings = false; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * This list of properties are the properties a client can search on using |
|
| 86 | + * the {DAV:}principal-property-search report. |
|
| 87 | + * |
|
| 88 | + * The keys are the property names, values are descriptions. |
|
| 89 | + * |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | + public $principalSearchPropertySet = [ |
|
| 93 | + '{DAV:}displayname' => 'Display name', |
|
| 94 | + '{http://sabredav.org/ns}email-address' => 'Email address', |
|
| 95 | + ]; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Any principal uri's added here, will automatically be added to the list |
|
| 99 | + * of ACL's. They will effectively receive {DAV:}all privileges, as a |
|
| 100 | + * protected privilege. |
|
| 101 | + * |
|
| 102 | + * @var array |
|
| 103 | + */ |
|
| 104 | + public $adminPrincipals = []; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * The ACL plugin allows privileges to be assigned to users that are not |
|
| 108 | + * logged in. To facilitate that, it modifies the auth plugin's behavior |
|
| 109 | + * to only require login when a privileged operation was denied. |
|
| 110 | + * |
|
| 111 | + * Unauthenticated access can be considered a security concern, so it's |
|
| 112 | + * possible to turn this feature off to harden the server's security. |
|
| 113 | + * |
|
| 114 | + * @var bool |
|
| 115 | + */ |
|
| 116 | + public $allowUnauthenticatedAccess = true; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Returns a list of features added by this plugin. |
|
| 120 | + * |
|
| 121 | + * This list is used in the response of a HTTP OPTIONS request. |
|
| 122 | + * |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function getFeatures() |
|
| 126 | + { |
|
| 127 | + return ['access-control', 'calendarserver-principal-property-search']; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Returns a list of available methods for a given url. |
|
| 132 | + * |
|
| 133 | + * @param string $uri |
|
| 134 | + * |
|
| 135 | + * @return array |
|
| 136 | + */ |
|
| 137 | + public function getMethods($uri) |
|
| 138 | + { |
|
| 139 | + return ['ACL']; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Returns a plugin name. |
|
| 144 | + * |
|
| 145 | + * Using this name other plugins will be able to access other plugins |
|
| 146 | + * using Sabre\DAV\Server::getPlugin |
|
| 147 | + * |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + public function getPluginName() |
|
| 151 | + { |
|
| 152 | + return 'acl'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Returns a list of reports this plugin supports. |
|
| 157 | + * |
|
| 158 | + * This will be used in the {DAV:}supported-report-set property. |
|
| 159 | + * Note that you still need to subscribe to the 'report' event to actually |
|
| 160 | + * implement them |
|
| 161 | + * |
|
| 162 | + * @param string $uri |
|
| 163 | + * |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + public function getSupportedReportSet($uri) |
|
| 167 | + { |
|
| 168 | + return [ |
|
| 169 | + '{DAV:}expand-property', |
|
| 170 | + '{DAV:}principal-match', |
|
| 171 | + '{DAV:}principal-property-search', |
|
| 172 | + '{DAV:}principal-search-property-set', |
|
| 173 | + ]; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Checks if the current user has the specified privilege(s). |
|
| 178 | + * |
|
| 179 | + * You can specify a single privilege, or a list of privileges. |
|
| 180 | + * This method will throw an exception if the privilege is not available |
|
| 181 | + * and return true otherwise. |
|
| 182 | + * |
|
| 183 | + * @param string $uri |
|
| 184 | + * @param array|string $privileges |
|
| 185 | + * @param int $recursion |
|
| 186 | + * @param bool $throwExceptions if set to false, this method won't throw exceptions |
|
| 187 | + * |
|
| 188 | + * @throws NeedPrivileges |
|
| 189 | + * @throws NotAuthenticated |
|
| 190 | + * |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) |
|
| 194 | + { |
|
| 195 | + if (!is_array($privileges)) { |
|
| 196 | + $privileges = [$privileges]; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $acl = $this->getCurrentUserPrivilegeSet($uri); |
|
| 200 | + |
|
| 201 | + $failed = []; |
|
| 202 | + foreach ($privileges as $priv) { |
|
| 203 | + if (!in_array($priv, $acl)) { |
|
| 204 | + $failed[] = $priv; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if ($failed) { |
|
| 209 | + if ($this->allowUnauthenticatedAccess && is_null($this->getCurrentUserPrincipal())) { |
|
| 210 | + // We are not authenticated. Kicking in the Auth plugin. |
|
| 211 | + $authPlugin = $this->server->getPlugin('auth'); |
|
| 212 | + $reasons = $authPlugin->getLoginFailedReasons(); |
|
| 213 | + $authPlugin->challenge( |
|
| 214 | + $this->server->httpRequest, |
|
| 215 | + $this->server->httpResponse |
|
| 216 | + ); |
|
| 217 | + throw new NotAuthenticated(implode(', ', $reasons).'. Login was needed for privilege: '.implode(', ', $failed).' on '.$uri); |
|
| 218 | + } |
|
| 219 | + if ($throwExceptions) { |
|
| 220 | + throw new NeedPrivileges($uri, $failed); |
|
| 221 | + } else { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Returns the standard users' principal. |
|
| 231 | + * |
|
| 232 | + * This is one authoritative principal url for the current user. |
|
| 233 | + * This method will return null if the user wasn't logged in. |
|
| 234 | + * |
|
| 235 | + * @return string|null |
|
| 236 | + */ |
|
| 237 | + public function getCurrentUserPrincipal() |
|
| 238 | + { |
|
| 239 | + /** @var $authPlugin \Sabre\DAV\Auth\Plugin */ |
|
| 240 | + $authPlugin = $this->server->getPlugin('auth'); |
|
| 241 | + if (!$authPlugin) { |
|
| 242 | + return null; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $authPlugin->getCurrentPrincipal(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Returns a list of principals that's associated to the current |
|
| 250 | + * user, either directly or through group membership. |
|
| 251 | + * |
|
| 252 | + * @return array |
|
| 253 | + */ |
|
| 254 | + public function getCurrentUserPrincipals() |
|
| 255 | + { |
|
| 256 | + $currentUser = $this->getCurrentUserPrincipal(); |
|
| 257 | + |
|
| 258 | + if (is_null($currentUser)) { |
|
| 259 | + return []; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return array_merge( |
|
| 263 | + [$currentUser], |
|
| 264 | + $this->getPrincipalMembership($currentUser) |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Sets the default ACL rules. |
|
| 270 | + * |
|
| 271 | + * These rules are used for all nodes that don't implement the IACL interface. |
|
| 272 | + */ |
|
| 273 | + public function setDefaultAcl(array $acl) |
|
| 274 | + { |
|
| 275 | + $this->defaultAcl = $acl; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Returns the default ACL rules. |
|
| 280 | + * |
|
| 281 | + * These rules are used for all nodes that don't implement the IACL interface. |
|
| 282 | + * |
|
| 283 | + * @return array |
|
| 284 | + */ |
|
| 285 | + public function getDefaultAcl() |
|
| 286 | + { |
|
| 287 | + return $this->defaultAcl; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * The default ACL rules. |
|
| 292 | + * |
|
| 293 | + * These rules are used for nodes that don't implement IACL. These default |
|
| 294 | + * set of rules allow anyone to do anything, as long as they are |
|
| 295 | + * authenticated. |
|
| 296 | + * |
|
| 297 | + * @var array |
|
| 298 | + */ |
|
| 299 | + protected $defaultAcl = [ |
|
| 300 | + [ |
|
| 301 | + 'principal' => '{DAV:}authenticated', |
|
| 302 | + 'protected' => true, |
|
| 303 | + 'privilege' => '{DAV:}all', |
|
| 304 | + ], |
|
| 305 | + ]; |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * This array holds a cache for all the principals that are associated with |
|
| 309 | + * a single principal. |
|
| 310 | + * |
|
| 311 | + * @var array |
|
| 312 | + */ |
|
| 313 | + protected $principalMembershipCache = []; |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Returns all the principal groups the specified principal is a member of. |
|
| 317 | + * |
|
| 318 | + * @param string $mainPrincipal |
|
| 319 | + * |
|
| 320 | + * @return array |
|
| 321 | + */ |
|
| 322 | + public function getPrincipalMembership($mainPrincipal) |
|
| 323 | + { |
|
| 324 | + // First check our cache |
|
| 325 | + if (isset($this->principalMembershipCache[$mainPrincipal])) { |
|
| 326 | + return $this->principalMembershipCache[$mainPrincipal]; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + $check = [$mainPrincipal]; |
|
| 330 | + $principals = []; |
|
| 331 | + |
|
| 332 | + while (count($check)) { |
|
| 333 | + $principal = array_shift($check); |
|
| 334 | + |
|
| 335 | + $node = $this->server->tree->getNodeForPath($principal); |
|
| 336 | + if ($node instanceof IPrincipal) { |
|
| 337 | + foreach ($node->getGroupMembership() as $groupMember) { |
|
| 338 | + if (!in_array($groupMember, $principals)) { |
|
| 339 | + $check[] = $groupMember; |
|
| 340 | + $principals[] = $groupMember; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Store the result in the cache |
|
| 347 | + $this->principalMembershipCache[$mainPrincipal] = $principals; |
|
| 348 | + |
|
| 349 | + return $principals; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Find out of a principal equals another principal. |
|
| 354 | + * |
|
| 355 | + * This is a quick way to find out whether a principal URI is part of a |
|
| 356 | + * group, or any subgroups. |
|
| 357 | + * |
|
| 358 | + * The first argument is the principal URI you want to check against. For |
|
| 359 | + * example the principal group, and the second argument is the principal of |
|
| 360 | + * which you want to find out of it is the same as the first principal, or |
|
| 361 | + * in a member of the first principal's group or subgroups. |
|
| 362 | + * |
|
| 363 | + * So the arguments are not interchangeable. If principal A is in group B, |
|
| 364 | + * passing 'B', 'A' will yield true, but 'A', 'B' is false. |
|
| 365 | + * |
|
| 366 | + * If the second argument is not passed, we will use the current user |
|
| 367 | + * principal. |
|
| 368 | + * |
|
| 369 | + * @param string $checkPrincipal |
|
| 370 | + * @param string $currentPrincipal |
|
| 371 | + * |
|
| 372 | + * @return bool |
|
| 373 | + */ |
|
| 374 | + public function principalMatchesPrincipal($checkPrincipal, $currentPrincipal = null) |
|
| 375 | + { |
|
| 376 | + if (is_null($currentPrincipal)) { |
|
| 377 | + $currentPrincipal = $this->getCurrentUserPrincipal(); |
|
| 378 | + } |
|
| 379 | + if ($currentPrincipal === $checkPrincipal) { |
|
| 380 | + return true; |
|
| 381 | + } |
|
| 382 | + if (is_null($currentPrincipal)) { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + return in_array( |
|
| 387 | + $checkPrincipal, |
|
| 388 | + $this->getPrincipalMembership($currentPrincipal) |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns a tree of supported privileges for a resource. |
|
| 394 | + * |
|
| 395 | + * The returned array structure should be in this form: |
|
| 396 | + * |
|
| 397 | + * [ |
|
| 398 | + * [ |
|
| 399 | + * 'privilege' => '{DAV:}read', |
|
| 400 | + * 'abstract' => false, |
|
| 401 | + * 'aggregates' => [] |
|
| 402 | + * ] |
|
| 403 | + * ] |
|
| 404 | + * |
|
| 405 | + * Privileges can be nested using "aggregates". Doing so means that |
|
| 406 | + * if you assign someone the aggregating privilege, all the |
|
| 407 | + * sub-privileges will automatically be granted. |
|
| 408 | + * |
|
| 409 | + * Marking a privilege as abstract means that the privilege cannot be |
|
| 410 | + * directly assigned, but must be assigned via the parent privilege. |
|
| 411 | + * |
|
| 412 | + * So a more complex version might look like this: |
|
| 413 | + * |
|
| 414 | + * [ |
|
| 415 | + * [ |
|
| 416 | + * 'privilege' => '{DAV:}read', |
|
| 417 | + * 'abstract' => false, |
|
| 418 | + * 'aggregates' => [ |
|
| 419 | + * [ |
|
| 420 | + * 'privilege' => '{DAV:}read-acl', |
|
| 421 | + * 'abstract' => false, |
|
| 422 | + * 'aggregates' => [], |
|
| 423 | + * ] |
|
| 424 | + * ] |
|
| 425 | + * ] |
|
| 426 | + * ] |
|
| 427 | + * |
|
| 428 | + * @param string|INode $node |
|
| 429 | + * |
|
| 430 | + * @return array |
|
| 431 | + */ |
|
| 432 | + public function getSupportedPrivilegeSet($node) |
|
| 433 | + { |
|
| 434 | + if (is_string($node)) { |
|
| 435 | + $node = $this->server->tree->getNodeForPath($node); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $supportedPrivileges = null; |
|
| 439 | + if ($node instanceof IACL) { |
|
| 440 | + $supportedPrivileges = $node->getSupportedPrivilegeSet(); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (is_null($supportedPrivileges)) { |
|
| 444 | + // Default |
|
| 445 | + $supportedPrivileges = [ |
|
| 446 | + '{DAV:}read' => [ |
|
| 447 | + 'abstract' => false, |
|
| 448 | + 'aggregates' => [ |
|
| 449 | + '{DAV:}read-acl' => [ |
|
| 450 | + 'abstract' => false, |
|
| 451 | + 'aggregates' => [], |
|
| 452 | + ], |
|
| 453 | + '{DAV:}read-current-user-privilege-set' => [ |
|
| 454 | + 'abstract' => false, |
|
| 455 | + 'aggregates' => [], |
|
| 456 | + ], |
|
| 457 | + ], |
|
| 458 | + ], |
|
| 459 | + '{DAV:}write' => [ |
|
| 460 | + 'abstract' => false, |
|
| 461 | + 'aggregates' => [ |
|
| 462 | + '{DAV:}write-properties' => [ |
|
| 463 | + 'abstract' => false, |
|
| 464 | + 'aggregates' => [], |
|
| 465 | + ], |
|
| 466 | + '{DAV:}write-content' => [ |
|
| 467 | + 'abstract' => false, |
|
| 468 | + 'aggregates' => [], |
|
| 469 | + ], |
|
| 470 | + '{DAV:}unlock' => [ |
|
| 471 | + 'abstract' => false, |
|
| 472 | + 'aggregates' => [], |
|
| 473 | + ], |
|
| 474 | + ], |
|
| 475 | + ], |
|
| 476 | + ]; |
|
| 477 | + if ($node instanceof DAV\ICollection) { |
|
| 478 | + $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}bind'] = [ |
|
| 479 | + 'abstract' => false, |
|
| 480 | + 'aggregates' => [], |
|
| 481 | + ]; |
|
| 482 | + $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}unbind'] = [ |
|
| 483 | + 'abstract' => false, |
|
| 484 | + 'aggregates' => [], |
|
| 485 | + ]; |
|
| 486 | + } |
|
| 487 | + if ($node instanceof IACL) { |
|
| 488 | + $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}write-acl'] = [ |
|
| 489 | + 'abstract' => false, |
|
| 490 | + 'aggregates' => [], |
|
| 491 | + ]; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $this->server->emit( |
|
| 496 | + 'getSupportedPrivilegeSet', |
|
| 497 | + [$node, &$supportedPrivileges] |
|
| 498 | + ); |
|
| 499 | + |
|
| 500 | + return $supportedPrivileges; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Returns the supported privilege set as a flat list. |
|
| 505 | + * |
|
| 506 | + * This is much easier to parse. |
|
| 507 | + * |
|
| 508 | + * The returned list will be index by privilege name. |
|
| 509 | + * The value is a struct containing the following properties: |
|
| 510 | + * - aggregates |
|
| 511 | + * - abstract |
|
| 512 | + * - concrete |
|
| 513 | + * |
|
| 514 | + * @param string|INode $node |
|
| 515 | + * |
|
| 516 | + * @return array |
|
| 517 | + */ |
|
| 518 | + final public function getFlatPrivilegeSet($node) |
|
| 519 | + { |
|
| 520 | + $privs = [ |
|
| 521 | + 'abstract' => false, |
|
| 522 | + 'aggregates' => $this->getSupportedPrivilegeSet($node), |
|
| 523 | + ]; |
|
| 524 | + |
|
| 525 | + $fpsTraverse = null; |
|
| 526 | + $fpsTraverse = function ($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { |
|
| 527 | + $myPriv = [ |
|
| 528 | + 'privilege' => $privName, |
|
| 529 | + 'abstract' => isset($privInfo['abstract']) && $privInfo['abstract'], |
|
| 530 | + 'aggregates' => [], |
|
| 531 | + 'concrete' => isset($privInfo['abstract']) && $privInfo['abstract'] ? $concrete : $privName, |
|
| 532 | + ]; |
|
| 533 | + |
|
| 534 | + if (isset($privInfo['aggregates'])) { |
|
| 535 | + foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { |
|
| 536 | + $myPriv['aggregates'][] = $subPrivName; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + $flat[$privName] = $myPriv; |
|
| 541 | + |
|
| 542 | + if (isset($privInfo['aggregates'])) { |
|
| 543 | + foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { |
|
| 544 | + $fpsTraverse($subPrivName, $subPrivInfo, $myPriv['concrete'], $flat); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + }; |
|
| 548 | + |
|
| 549 | + $flat = []; |
|
| 550 | + $fpsTraverse('{DAV:}all', $privs, null, $flat); |
|
| 551 | + |
|
| 552 | + return $flat; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Returns the full ACL list. |
|
| 557 | + * |
|
| 558 | + * Either a uri or a INode may be passed. |
|
| 559 | + * |
|
| 560 | + * null will be returned if the node doesn't support ACLs. |
|
| 561 | + * |
|
| 562 | + * @param string|DAV\INode $node |
|
| 563 | + * |
|
| 564 | + * @return array |
|
| 565 | + */ |
|
| 566 | + public function getAcl($node) |
|
| 567 | + { |
|
| 568 | + if (is_string($node)) { |
|
| 569 | + $node = $this->server->tree->getNodeForPath($node); |
|
| 570 | + } |
|
| 571 | + if (!$node instanceof IACL) { |
|
| 572 | + return $this->getDefaultAcl(); |
|
| 573 | + } |
|
| 574 | + $acl = $node->getACL(); |
|
| 575 | + foreach ($this->adminPrincipals as $adminPrincipal) { |
|
| 576 | + $acl[] = [ |
|
| 577 | + 'principal' => $adminPrincipal, |
|
| 578 | + 'privilege' => '{DAV:}all', |
|
| 579 | + 'protected' => true, |
|
| 580 | + ]; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + return $acl; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Returns a list of privileges the current user has |
|
| 588 | + * on a particular node. |
|
| 589 | + * |
|
| 590 | + * Either a uri or a DAV\INode may be passed. |
|
| 591 | + * |
|
| 592 | + * null will be returned if the node doesn't support ACLs. |
|
| 593 | + * |
|
| 594 | + * @param string|DAV\INode $node |
|
| 595 | + * |
|
| 596 | + * @return array |
|
| 597 | + */ |
|
| 598 | + public function getCurrentUserPrivilegeSet($node) |
|
| 599 | + { |
|
| 600 | + if (is_string($node)) { |
|
| 601 | + $node = $this->server->tree->getNodeForPath($node); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + $acl = $this->getACL($node); |
|
| 605 | + |
|
| 606 | + $collected = []; |
|
| 607 | + |
|
| 608 | + $isAuthenticated = null !== $this->getCurrentUserPrincipal(); |
|
| 609 | + |
|
| 610 | + foreach ($acl as $ace) { |
|
| 611 | + $principal = $ace['principal']; |
|
| 612 | + |
|
| 613 | + switch ($principal) { |
|
| 614 | + case '{DAV:}owner': |
|
| 615 | + $owner = $node->getOwner(); |
|
| 616 | + if ($owner && $this->principalMatchesPrincipal($owner)) { |
|
| 617 | + $collected[] = $ace; |
|
| 618 | + } |
|
| 619 | + break; |
|
| 620 | + |
|
| 621 | + // 'all' matches for every user |
|
| 622 | + case '{DAV:}all': |
|
| 623 | + $collected[] = $ace; |
|
| 624 | + break; |
|
| 625 | + |
|
| 626 | + case '{DAV:}authenticated': |
|
| 627 | + // Authenticated users only |
|
| 628 | + if ($isAuthenticated) { |
|
| 629 | + $collected[] = $ace; |
|
| 630 | + } |
|
| 631 | + break; |
|
| 632 | + |
|
| 633 | + case '{DAV:}unauthenticated': |
|
| 634 | + // Unauthenticated users only |
|
| 635 | + if (!$isAuthenticated) { |
|
| 636 | + $collected[] = $ace; |
|
| 637 | + } |
|
| 638 | + break; |
|
| 639 | + |
|
| 640 | + default: |
|
| 641 | + if ($this->principalMatchesPrincipal($ace['principal'])) { |
|
| 642 | + $collected[] = $ace; |
|
| 643 | + } |
|
| 644 | + break; |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + // Now we deduct all aggregated privileges. |
|
| 649 | + $flat = $this->getFlatPrivilegeSet($node); |
|
| 650 | + |
|
| 651 | + $collected2 = []; |
|
| 652 | + while (count($collected)) { |
|
| 653 | + $current = array_pop($collected); |
|
| 654 | + $collected2[] = $current['privilege']; |
|
| 655 | + |
|
| 656 | + if (!isset($flat[$current['privilege']])) { |
|
| 657 | + // Ignoring privileges that are not in the supported-privileges list. |
|
| 658 | + $this->server->getLogger()->debug('A node has the "'.$current['privilege'].'" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.'); |
|
| 659 | + continue; |
|
| 660 | + } |
|
| 661 | + foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) { |
|
| 662 | + $collected2[] = $subPriv; |
|
| 663 | + $collected[] = $flat[$subPriv]; |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + return array_values(array_unique($collected2)); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Returns a principal based on its uri. |
|
| 672 | + * |
|
| 673 | + * Returns null if the principal could not be found. |
|
| 674 | + * |
|
| 675 | + * @param string $uri |
|
| 676 | + * |
|
| 677 | + * @return string|null |
|
| 678 | + */ |
|
| 679 | + public function getPrincipalByUri($uri) |
|
| 680 | + { |
|
| 681 | + $result = null; |
|
| 682 | + $collections = $this->principalCollectionSet; |
|
| 683 | + foreach ($collections as $collection) { |
|
| 684 | + try { |
|
| 685 | + $principalCollection = $this->server->tree->getNodeForPath($collection); |
|
| 686 | + } catch (NotFound $e) { |
|
| 687 | + // Ignore and move on |
|
| 688 | + continue; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + if (!$principalCollection instanceof IPrincipalCollection) { |
|
| 692 | + // Not a principal collection, we're simply going to ignore |
|
| 693 | + // this. |
|
| 694 | + continue; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $result = $principalCollection->findByUri($uri); |
|
| 698 | + if ($result) { |
|
| 699 | + return $result; |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Principal property search. |
|
| 706 | + * |
|
| 707 | + * This method can search for principals matching certain values in |
|
| 708 | + * properties. |
|
| 709 | + * |
|
| 710 | + * This method will return a list of properties for the matched properties. |
|
| 711 | + * |
|
| 712 | + * @param array $searchProperties The properties to search on. This is a |
|
| 713 | + * key-value list. The keys are property |
|
| 714 | + * names, and the values the strings to |
|
| 715 | + * match them on. |
|
| 716 | + * @param array $requestedProperties this is the list of properties to |
|
| 717 | + * return for every match |
|
| 718 | + * @param string $collectionUri the principal collection to search on. |
|
| 719 | + * If this is ommitted, the standard |
|
| 720 | + * principal collection-set will be used |
|
| 721 | + * @param string $test "allof" to use AND to search the |
|
| 722 | + * properties. 'anyof' for OR. |
|
| 723 | + * |
|
| 724 | + * @return array This method returns an array structure similar to |
|
| 725 | + * Sabre\DAV\Server::getPropertiesForPath. Returned |
|
| 726 | + * properties are index by a HTTP status code. |
|
| 727 | + */ |
|
| 728 | + public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') |
|
| 729 | + { |
|
| 730 | + if (!is_null($collectionUri)) { |
|
| 731 | + $uris = [$collectionUri]; |
|
| 732 | + } else { |
|
| 733 | + $uris = $this->principalCollectionSet; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + $lookupResults = []; |
|
| 737 | + foreach ($uris as $uri) { |
|
| 738 | + $principalCollection = $this->server->tree->getNodeForPath($uri); |
|
| 739 | + if (!$principalCollection instanceof IPrincipalCollection) { |
|
| 740 | + // Not a principal collection, we're simply going to ignore |
|
| 741 | + // this. |
|
| 742 | + continue; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $results = $principalCollection->searchPrincipals($searchProperties, $test); |
|
| 746 | + foreach ($results as $result) { |
|
| 747 | + $lookupResults[] = rtrim($uri, '/').'/'.$result; |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + $matches = []; |
|
| 752 | + |
|
| 753 | + foreach ($lookupResults as $lookupResult) { |
|
| 754 | + list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $matches; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Sets up the plugin. |
|
| 762 | + * |
|
| 763 | + * This method is automatically called by the server class. |
|
| 764 | + */ |
|
| 765 | + public function initialize(DAV\Server $server) |
|
| 766 | + { |
|
| 767 | + if ($this->allowUnauthenticatedAccess) { |
|
| 768 | + $authPlugin = $server->getPlugin('auth'); |
|
| 769 | + if (!$authPlugin) { |
|
| 770 | + throw new \Exception('The Auth plugin must be loaded before the ACL plugin if you want to allow unauthenticated access.'); |
|
| 771 | + } |
|
| 772 | + $authPlugin->autoRequireLogin = false; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + $this->server = $server; |
|
| 776 | + $server->on('propFind', [$this, 'propFind'], 20); |
|
| 777 | + $server->on('beforeMethod:*', [$this, 'beforeMethod'], 20); |
|
| 778 | + $server->on('beforeBind', [$this, 'beforeBind'], 20); |
|
| 779 | + $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20); |
|
| 780 | + $server->on('propPatch', [$this, 'propPatch']); |
|
| 781 | + $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20); |
|
| 782 | + $server->on('report', [$this, 'report']); |
|
| 783 | + $server->on('method:ACL', [$this, 'httpAcl']); |
|
| 784 | + $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); |
|
| 785 | + $server->on('getPrincipalByUri', function ($principal, &$uri) { |
|
| 786 | + $uri = $this->getPrincipalByUri($principal); |
|
| 787 | + |
|
| 788 | + // Break event chain |
|
| 789 | + if ($uri) { |
|
| 790 | + return false; |
|
| 791 | + } |
|
| 792 | + }); |
|
| 793 | + |
|
| 794 | + array_push($server->protectedProperties, |
|
| 795 | + '{DAV:}alternate-URI-set', |
|
| 796 | + '{DAV:}principal-URL', |
|
| 797 | + '{DAV:}group-membership', |
|
| 798 | + '{DAV:}principal-collection-set', |
|
| 799 | + '{DAV:}current-user-principal', |
|
| 800 | + '{DAV:}supported-privilege-set', |
|
| 801 | + '{DAV:}current-user-privilege-set', |
|
| 802 | + '{DAV:}acl', |
|
| 803 | + '{DAV:}acl-restrictions', |
|
| 804 | + '{DAV:}inherited-acl-set', |
|
| 805 | + '{DAV:}owner', |
|
| 806 | + '{DAV:}group' |
|
| 807 | + ); |
|
| 808 | + |
|
| 809 | + // Automatically mapping nodes implementing IPrincipal to the |
|
| 810 | + // {DAV:}principal resourcetype. |
|
| 811 | + $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal'; |
|
| 812 | + |
|
| 813 | + // Mapping the group-member-set property to the HrefList property |
|
| 814 | + // class. |
|
| 815 | + $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href'; |
|
| 816 | + $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl'; |
|
| 817 | + $server->xml->elementMap['{DAV:}acl-principal-prop-set'] = 'Sabre\\DAVACL\\Xml\\Request\\AclPrincipalPropSetReport'; |
|
| 818 | + $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport'; |
|
| 819 | + $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport'; |
|
| 820 | + $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport'; |
|
| 821 | + $server->xml->elementMap['{DAV:}principal-match'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalMatchReport'; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + /* {{{ Event handlers */ |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Triggered before any method is handled. |
|
| 828 | + */ |
|
| 829 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) |
|
| 830 | + { |
|
| 831 | + $method = $request->getMethod(); |
|
| 832 | + $path = $request->getPath(); |
|
| 833 | + |
|
| 834 | + $exists = $this->server->tree->nodeExists($path); |
|
| 835 | + |
|
| 836 | + // If the node doesn't exists, none of these checks apply |
|
| 837 | + if (!$exists) { |
|
| 838 | + return; |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + switch ($method) { |
|
| 842 | + case 'GET': |
|
| 843 | + case 'HEAD': |
|
| 844 | + case 'OPTIONS': |
|
| 845 | + // For these 3 we only need to know if the node is readable. |
|
| 846 | + $this->checkPrivileges($path, '{DAV:}read'); |
|
| 847 | + break; |
|
| 848 | + |
|
| 849 | + case 'PUT': |
|
| 850 | + case 'LOCK': |
|
| 851 | + // This method requires the write-content priv if the node |
|
| 852 | + // already exists, and bind on the parent if the node is being |
|
| 853 | + // created. |
|
| 854 | + // The bind privilege is handled in the beforeBind event. |
|
| 855 | + $this->checkPrivileges($path, '{DAV:}write-content'); |
|
| 856 | + break; |
|
| 857 | + |
|
| 858 | + case 'UNLOCK': |
|
| 859 | + // Unlock is always allowed at the moment. |
|
| 860 | + break; |
|
| 861 | + |
|
| 862 | + case 'PROPPATCH': |
|
| 863 | + $this->checkPrivileges($path, '{DAV:}write-properties'); |
|
| 864 | + break; |
|
| 865 | + |
|
| 866 | + case 'ACL': |
|
| 867 | + $this->checkPrivileges($path, '{DAV:}write-acl'); |
|
| 868 | + break; |
|
| 869 | + |
|
| 870 | + case 'COPY': |
|
| 871 | + case 'MOVE': |
|
| 872 | + // Copy requires read privileges on the entire source tree. |
|
| 873 | + // If the target exists write-content normally needs to be |
|
| 874 | + // checked, however, we're deleting the node beforehand and |
|
| 875 | + // creating a new one after, so this is handled by the |
|
| 876 | + // beforeUnbind event. |
|
| 877 | + // |
|
| 878 | + // The creation of the new node is handled by the beforeBind |
|
| 879 | + // event. |
|
| 880 | + // |
|
| 881 | + // If MOVE is used beforeUnbind will also be used to check if |
|
| 882 | + // the sourcenode can be deleted. |
|
| 883 | + $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE); |
|
| 884 | + break; |
|
| 885 | + } |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * Triggered before a new node is created. |
|
| 890 | + * |
|
| 891 | + * This allows us to check permissions for any operation that creates a |
|
| 892 | + * new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE. |
|
| 893 | + * |
|
| 894 | + * @param string $uri |
|
| 895 | + */ |
|
| 896 | + public function beforeBind($uri) |
|
| 897 | + { |
|
| 898 | + list($parentUri) = Uri\split($uri); |
|
| 899 | + $this->checkPrivileges($parentUri, '{DAV:}bind'); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * Triggered before a node is deleted. |
|
| 904 | + * |
|
| 905 | + * This allows us to check permissions for any operation that will delete |
|
| 906 | + * an existing node. |
|
| 907 | + * |
|
| 908 | + * @param string $uri |
|
| 909 | + */ |
|
| 910 | + public function beforeUnbind($uri) |
|
| 911 | + { |
|
| 912 | + list($parentUri) = Uri\split($uri); |
|
| 913 | + $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS); |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * Triggered before a node is unlocked. |
|
| 918 | + * |
|
| 919 | + * @param string $uri |
|
| 920 | + * @TODO: not yet implemented |
|
| 921 | + */ |
|
| 922 | + public function beforeUnlock($uri, DAV\Locks\LockInfo $lock) |
|
| 923 | + { |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Triggered before properties are looked up in specific nodes. |
|
| 928 | + * |
|
| 929 | + * @TODO really should be broken into multiple methods, or even a class. |
|
| 930 | + */ |
|
| 931 | + public function propFind(DAV\PropFind $propFind, DAV\INode $node) |
|
| 932 | + { |
|
| 933 | + $path = $propFind->getPath(); |
|
| 934 | + |
|
| 935 | + // Checking the read permission |
|
| 936 | + if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) { |
|
| 937 | + // User is not allowed to read properties |
|
| 938 | + |
|
| 939 | + // Returning false causes the property-fetching system to pretend |
|
| 940 | + // that the node does not exist, and will cause it to be hidden |
|
| 941 | + // from listings such as PROPFIND or the browser plugin. |
|
| 942 | + if ($this->hideNodesFromListings) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + // Otherwise we simply mark every property as 403. |
|
| 947 | + foreach ($propFind->getRequestedProperties() as $requestedProperty) { |
|
| 948 | + $propFind->set($requestedProperty, null, 403); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + /* Adding principal properties */ |
|
| 955 | + if ($node instanceof IPrincipal) { |
|
| 956 | + $propFind->handle('{DAV:}alternate-URI-set', function () use ($node) { |
|
| 957 | + return new Href($node->getAlternateUriSet()); |
|
| 958 | + }); |
|
| 959 | + $propFind->handle('{DAV:}principal-URL', function () use ($node) { |
|
| 960 | + return new Href($node->getPrincipalUrl().'/'); |
|
| 961 | + }); |
|
| 962 | + $propFind->handle('{DAV:}group-member-set', function () use ($node) { |
|
| 963 | + $members = $node->getGroupMemberSet(); |
|
| 964 | + foreach ($members as $k => $member) { |
|
| 965 | + $members[$k] = rtrim($member, '/').'/'; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return new Href($members); |
|
| 969 | + }); |
|
| 970 | + $propFind->handle('{DAV:}group-membership', function () use ($node) { |
|
| 971 | + $members = $node->getGroupMembership(); |
|
| 972 | + foreach ($members as $k => $member) { |
|
| 973 | + $members[$k] = rtrim($member, '/').'/'; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + return new Href($members); |
|
| 977 | + }); |
|
| 978 | + $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + $propFind->handle('{DAV:}principal-collection-set', function () { |
|
| 982 | + $val = $this->principalCollectionSet; |
|
| 983 | + // Ensuring all collections end with a slash |
|
| 984 | + foreach ($val as $k => $v) { |
|
| 985 | + $val[$k] = $v.'/'; |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + return new Href($val); |
|
| 989 | + }); |
|
| 990 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 991 | + if ($url = $this->getCurrentUserPrincipal()) { |
|
| 992 | + return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url.'/'); |
|
| 993 | + } else { |
|
| 994 | + return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED); |
|
| 995 | + } |
|
| 996 | + }); |
|
| 997 | + $propFind->handle('{DAV:}supported-privilege-set', function () use ($node) { |
|
| 998 | + return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node)); |
|
| 999 | + }); |
|
| 1000 | + $propFind->handle('{DAV:}current-user-privilege-set', function () use ($node, $propFind, $path) { |
|
| 1001 | + if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) { |
|
| 1002 | + $propFind->set('{DAV:}current-user-privilege-set', null, 403); |
|
| 1003 | + } else { |
|
| 1004 | + $val = $this->getCurrentUserPrivilegeSet($node); |
|
| 1005 | + |
|
| 1006 | + return new Xml\Property\CurrentUserPrivilegeSet($val); |
|
| 1007 | + } |
|
| 1008 | + }); |
|
| 1009 | + $propFind->handle('{DAV:}acl', function () use ($node, $propFind, $path) { |
|
| 1010 | + /* The ACL property contains all the permissions */ |
|
| 1011 | + if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) { |
|
| 1012 | + $propFind->set('{DAV:}acl', null, 403); |
|
| 1013 | + } else { |
|
| 1014 | + $acl = $this->getACL($node); |
|
| 1015 | + |
|
| 1016 | + return new Xml\Property\Acl($this->getACL($node)); |
|
| 1017 | + } |
|
| 1018 | + }); |
|
| 1019 | + $propFind->handle('{DAV:}acl-restrictions', function () { |
|
| 1020 | + return new Xml\Property\AclRestrictions(); |
|
| 1021 | + }); |
|
| 1022 | + |
|
| 1023 | + /* Adding ACL properties */ |
|
| 1024 | + if ($node instanceof IACL) { |
|
| 1025 | + $propFind->handle('{DAV:}owner', function () use ($node) { |
|
| 1026 | + return new Href($node->getOwner().'/'); |
|
| 1027 | + }); |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * This method intercepts PROPPATCH methods and make sure the |
|
| 1033 | + * group-member-set is updated correctly. |
|
| 1034 | + * |
|
| 1035 | + * @param string $path |
|
| 1036 | + */ |
|
| 1037 | + public function propPatch($path, DAV\PropPatch $propPatch) |
|
| 1038 | + { |
|
| 1039 | + $propPatch->handle('{DAV:}group-member-set', function ($value) use ($path) { |
|
| 1040 | + if (is_null($value)) { |
|
| 1041 | + $memberSet = []; |
|
| 1042 | + } elseif ($value instanceof Href) { |
|
| 1043 | + $memberSet = array_map( |
|
| 1044 | + [$this->server, 'calculateUri'], |
|
| 1045 | + $value->getHrefs() |
|
| 1046 | + ); |
|
| 1047 | + } else { |
|
| 1048 | + throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null'); |
|
| 1049 | + } |
|
| 1050 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 1051 | + if (!($node instanceof IPrincipal)) { |
|
| 1052 | + // Fail |
|
| 1053 | + return false; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + $node->setGroupMemberSet($memberSet); |
|
| 1057 | + // We must also clear our cache, just in case |
|
| 1058 | + |
|
| 1059 | + $this->principalMembershipCache = []; |
|
| 1060 | + |
|
| 1061 | + return true; |
|
| 1062 | + }); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * This method handles HTTP REPORT requests. |
|
| 1067 | + * |
|
| 1068 | + * @param string $reportName |
|
| 1069 | + * @param mixed $report |
|
| 1070 | + * @param mixed $path |
|
| 1071 | + */ |
|
| 1072 | + public function report($reportName, $report, $path) |
|
| 1073 | + { |
|
| 1074 | + switch ($reportName) { |
|
| 1075 | + case '{DAV:}principal-property-search': |
|
| 1076 | + $this->server->transactionType = 'report-principal-property-search'; |
|
| 1077 | + $this->principalPropertySearchReport($path, $report); |
|
| 1078 | + |
|
| 1079 | + return false; |
|
| 1080 | + case '{DAV:}principal-search-property-set': |
|
| 1081 | + $this->server->transactionType = 'report-principal-search-property-set'; |
|
| 1082 | + $this->principalSearchPropertySetReport($path, $report); |
|
| 1083 | + |
|
| 1084 | + return false; |
|
| 1085 | + case '{DAV:}expand-property': |
|
| 1086 | + $this->server->transactionType = 'report-expand-property'; |
|
| 1087 | + $this->expandPropertyReport($path, $report); |
|
| 1088 | + |
|
| 1089 | + return false; |
|
| 1090 | + case '{DAV:}principal-match': |
|
| 1091 | + $this->server->transactionType = 'report-principal-match'; |
|
| 1092 | + $this->principalMatchReport($path, $report); |
|
| 1093 | + |
|
| 1094 | + return false; |
|
| 1095 | + case '{DAV:}acl-principal-prop-set': |
|
| 1096 | + $this->server->transactionType = 'acl-principal-prop-set'; |
|
| 1097 | + $this->aclPrincipalPropSetReport($path, $report); |
|
| 1098 | + |
|
| 1099 | + return false; |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * This method is responsible for handling the 'ACL' event. |
|
| 1105 | + * |
|
| 1106 | + * @return bool |
|
| 1107 | + */ |
|
| 1108 | + public function httpAcl(RequestInterface $request, ResponseInterface $response) |
|
| 1109 | + { |
|
| 1110 | + $path = $request->getPath(); |
|
| 1111 | + $body = $request->getBodyAsString(); |
|
| 1112 | + |
|
| 1113 | + if (!$body) { |
|
| 1114 | + throw new DAV\Exception\BadRequest('XML body expected in ACL request'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + $acl = $this->server->xml->expect('{DAV:}acl', $body); |
|
| 1118 | + $newAcl = $acl->getPrivileges(); |
|
| 1119 | + |
|
| 1120 | + // Normalizing urls |
|
| 1121 | + foreach ($newAcl as $k => $newAce) { |
|
| 1122 | + $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']); |
|
| 1123 | + } |
|
| 1124 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 1125 | + |
|
| 1126 | + if (!$node instanceof IACL) { |
|
| 1127 | + throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method'); |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + $oldAcl = $this->getACL($node); |
|
| 1131 | + |
|
| 1132 | + $supportedPrivileges = $this->getFlatPrivilegeSet($node); |
|
| 1133 | + |
|
| 1134 | + /* Checking if protected principals from the existing principal set are |
|
| 1135 | 1135 | not overwritten. */ |
| 1136 | - foreach ($oldAcl as $oldAce) { |
|
| 1137 | - if (!isset($oldAce['protected']) || !$oldAce['protected']) { |
|
| 1138 | - continue; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - $found = false; |
|
| 1142 | - foreach ($newAcl as $newAce) { |
|
| 1143 | - if ( |
|
| 1144 | - $newAce['privilege'] === $oldAce['privilege'] && |
|
| 1145 | - $newAce['principal'] === $oldAce['principal'] && |
|
| 1146 | - $newAce['protected'] |
|
| 1147 | - ) { |
|
| 1148 | - $found = true; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - if (!$found) { |
|
| 1153 | - throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request'); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - foreach ($newAcl as $newAce) { |
|
| 1158 | - // Do we recognize the privilege |
|
| 1159 | - if (!isset($supportedPrivileges[$newAce['privilege']])) { |
|
| 1160 | - throw new Exception\NotSupportedPrivilege('The privilege you specified ('.$newAce['privilege'].') is not recognized by this server'); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - if ($supportedPrivileges[$newAce['privilege']]['abstract']) { |
|
| 1164 | - throw new Exception\NoAbstract('The privilege you specified ('.$newAce['privilege'].') is an abstract privilege'); |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - // Looking up the principal |
|
| 1168 | - try { |
|
| 1169 | - $principal = $this->server->tree->getNodeForPath($newAce['principal']); |
|
| 1170 | - } catch (NotFound $e) { |
|
| 1171 | - throw new Exception\NotRecognizedPrincipal('The specified principal ('.$newAce['principal'].') does not exist'); |
|
| 1172 | - } |
|
| 1173 | - if (!($principal instanceof IPrincipal)) { |
|
| 1174 | - throw new Exception\NotRecognizedPrincipal('The specified uri ('.$newAce['principal'].') is not a principal'); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - $node->setACL($newAcl); |
|
| 1178 | - |
|
| 1179 | - $response->setStatus(200); |
|
| 1180 | - |
|
| 1181 | - // Breaking the event chain, because we handled this method. |
|
| 1182 | - return false; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - /* }}} */ |
|
| 1186 | - |
|
| 1187 | - /* Reports {{{ */ |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * The principal-match report is defined in RFC3744, section 9.3. |
|
| 1191 | - * |
|
| 1192 | - * This report allows a client to figure out based on the current user, |
|
| 1193 | - * or a principal URL, the principal URL and principal URLs of groups that |
|
| 1194 | - * principal belongs to. |
|
| 1195 | - * |
|
| 1196 | - * @param string $path |
|
| 1197 | - */ |
|
| 1198 | - protected function principalMatchReport($path, Xml\Request\PrincipalMatchReport $report) |
|
| 1199 | - { |
|
| 1200 | - $depth = $this->server->getHTTPDepth(0); |
|
| 1201 | - if (0 !== $depth) { |
|
| 1202 | - throw new BadRequest('The principal-match report is only defined on Depth: 0'); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - $currentPrincipals = $this->getCurrentUserPrincipals(); |
|
| 1206 | - |
|
| 1207 | - $result = []; |
|
| 1208 | - |
|
| 1209 | - if (Xml\Request\PrincipalMatchReport::SELF === $report->type) { |
|
| 1210 | - // Finding all principals under the request uri that match the |
|
| 1211 | - // current principal. |
|
| 1212 | - foreach ($currentPrincipals as $currentPrincipal) { |
|
| 1213 | - if ($currentPrincipal === $path || 0 === strpos($currentPrincipal, $path.'/')) { |
|
| 1214 | - $result[] = $currentPrincipal; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - } else { |
|
| 1218 | - // We need to find all resources that have a property that matches |
|
| 1219 | - // one of the current principals. |
|
| 1220 | - $candidates = $this->server->getPropertiesForPath( |
|
| 1221 | - $path, |
|
| 1222 | - [$report->principalProperty], |
|
| 1223 | - 1 |
|
| 1224 | - ); |
|
| 1225 | - |
|
| 1226 | - foreach ($candidates as $candidate) { |
|
| 1227 | - if (!isset($candidate[200][$report->principalProperty])) { |
|
| 1228 | - continue; |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - $hrefs = $candidate[200][$report->principalProperty]; |
|
| 1232 | - |
|
| 1233 | - if (!$hrefs instanceof Href) { |
|
| 1234 | - continue; |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - foreach ($hrefs->getHrefs() as $href) { |
|
| 1238 | - if (in_array(trim($href, '/'), $currentPrincipals)) { |
|
| 1239 | - $result[] = $candidate['href']; |
|
| 1240 | - continue 2; |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - } |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - $responses = []; |
|
| 1247 | - |
|
| 1248 | - foreach ($result as $item) { |
|
| 1249 | - $properties = []; |
|
| 1250 | - |
|
| 1251 | - if ($report->properties) { |
|
| 1252 | - $foo = $this->server->getPropertiesForPath($item, $report->properties); |
|
| 1253 | - $foo = $foo[0]; |
|
| 1254 | - $item = $foo['href']; |
|
| 1255 | - unset($foo['href']); |
|
| 1256 | - $properties = $foo; |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - $responses[] = new DAV\Xml\Element\Response( |
|
| 1260 | - $item, |
|
| 1261 | - $properties, |
|
| 1262 | - '200' |
|
| 1263 | - ); |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1267 | - $this->server->httpResponse->setStatus(207); |
|
| 1268 | - $this->server->httpResponse->setBody( |
|
| 1269 | - $this->server->xml->write( |
|
| 1270 | - '{DAV:}multistatus', |
|
| 1271 | - $responses, |
|
| 1272 | - $this->server->getBaseUri() |
|
| 1273 | - ) |
|
| 1274 | - ); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * The expand-property report is defined in RFC3253 section 3.8. |
|
| 1279 | - * |
|
| 1280 | - * This report is very similar to a standard PROPFIND. The difference is |
|
| 1281 | - * that it has the additional ability to look at properties containing a |
|
| 1282 | - * {DAV:}href element, follow that property and grab additional elements |
|
| 1283 | - * there. |
|
| 1284 | - * |
|
| 1285 | - * Other rfc's, such as ACL rely on this report, so it made sense to put |
|
| 1286 | - * it in this plugin. |
|
| 1287 | - * |
|
| 1288 | - * @param string $path |
|
| 1289 | - * @param Xml\Request\ExpandPropertyReport $report |
|
| 1290 | - */ |
|
| 1291 | - protected function expandPropertyReport($path, $report) |
|
| 1292 | - { |
|
| 1293 | - $depth = $this->server->getHTTPDepth(0); |
|
| 1294 | - |
|
| 1295 | - $result = $this->expandProperties($path, $report->properties, $depth); |
|
| 1296 | - |
|
| 1297 | - $xml = $this->server->xml->write( |
|
| 1298 | - '{DAV:}multistatus', |
|
| 1299 | - new DAV\Xml\Response\MultiStatus($result), |
|
| 1300 | - $this->server->getBaseUri() |
|
| 1301 | - ); |
|
| 1302 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1303 | - $this->server->httpResponse->setStatus(207); |
|
| 1304 | - $this->server->httpResponse->setBody($xml); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * This method expands all the properties and returns |
|
| 1309 | - * a list with property values. |
|
| 1310 | - * |
|
| 1311 | - * @param array $path |
|
| 1312 | - * @param array $requestedProperties the list of required properties |
|
| 1313 | - * @param int $depth |
|
| 1314 | - * |
|
| 1315 | - * @return array |
|
| 1316 | - */ |
|
| 1317 | - protected function expandProperties($path, array $requestedProperties, $depth) |
|
| 1318 | - { |
|
| 1319 | - $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth); |
|
| 1320 | - |
|
| 1321 | - $result = []; |
|
| 1322 | - |
|
| 1323 | - foreach ($foundProperties as $node) { |
|
| 1324 | - foreach ($requestedProperties as $propertyName => $childRequestedProperties) { |
|
| 1325 | - // We're only traversing if sub-properties were requested |
|
| 1326 | - if (!is_array($childRequestedProperties) || 0 === count($childRequestedProperties)) { |
|
| 1327 | - continue; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - // We only have to do the expansion if the property was found |
|
| 1331 | - // and it contains an href element. |
|
| 1332 | - if (!array_key_exists($propertyName, $node[200])) { |
|
| 1333 | - continue; |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) { |
|
| 1337 | - continue; |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - $childHrefs = $node[200][$propertyName]->getHrefs(); |
|
| 1341 | - $childProps = []; |
|
| 1342 | - |
|
| 1343 | - foreach ($childHrefs as $href) { |
|
| 1344 | - // Gathering the result of the children |
|
| 1345 | - $childProps[] = [ |
|
| 1346 | - 'name' => '{DAV:}response', |
|
| 1347 | - 'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0], |
|
| 1348 | - ]; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - // Replacing the property with its expanded form. |
|
| 1352 | - $node[200][$propertyName] = $childProps; |
|
| 1353 | - } |
|
| 1354 | - $result[] = new DAV\Xml\Element\Response($node['href'], $node); |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - return $result; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - /** |
|
| 1361 | - * principalSearchPropertySetReport. |
|
| 1362 | - * |
|
| 1363 | - * This method responsible for handing the |
|
| 1364 | - * {DAV:}principal-search-property-set report. This report returns a list |
|
| 1365 | - * of properties the client may search on, using the |
|
| 1366 | - * {DAV:}principal-property-search report. |
|
| 1367 | - * |
|
| 1368 | - * @param string $path |
|
| 1369 | - * @param Xml\Request\PrincipalSearchPropertySetReport $report |
|
| 1370 | - */ |
|
| 1371 | - protected function principalSearchPropertySetReport($path, $report) |
|
| 1372 | - { |
|
| 1373 | - $httpDepth = $this->server->getHTTPDepth(0); |
|
| 1374 | - if (0 !== $httpDepth) { |
|
| 1375 | - throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0'); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - $writer = $this->server->xml->getWriter(); |
|
| 1379 | - $writer->openMemory(); |
|
| 1380 | - $writer->startDocument(); |
|
| 1381 | - |
|
| 1382 | - $writer->startElement('{DAV:}principal-search-property-set'); |
|
| 1383 | - |
|
| 1384 | - foreach ($this->principalSearchPropertySet as $propertyName => $description) { |
|
| 1385 | - $writer->startElement('{DAV:}principal-search-property'); |
|
| 1386 | - $writer->startElement('{DAV:}prop'); |
|
| 1387 | - |
|
| 1388 | - $writer->writeElement($propertyName); |
|
| 1389 | - |
|
| 1390 | - $writer->endElement(); // prop |
|
| 1391 | - |
|
| 1392 | - if ($description) { |
|
| 1393 | - $writer->write([[ |
|
| 1394 | - 'name' => '{DAV:}description', |
|
| 1395 | - 'value' => $description, |
|
| 1396 | - 'attributes' => ['xml:lang' => 'en'], |
|
| 1397 | - ]]); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - $writer->endElement(); // principal-search-property |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - $writer->endElement(); // principal-search-property-set |
|
| 1404 | - |
|
| 1405 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1406 | - $this->server->httpResponse->setStatus(200); |
|
| 1407 | - $this->server->httpResponse->setBody($writer->outputMemory()); |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - /** |
|
| 1411 | - * principalPropertySearchReport. |
|
| 1412 | - * |
|
| 1413 | - * This method is responsible for handing the |
|
| 1414 | - * {DAV:}principal-property-search report. This report can be used for |
|
| 1415 | - * clients to search for groups of principals, based on the value of one |
|
| 1416 | - * or more properties. |
|
| 1417 | - * |
|
| 1418 | - * @param string $path |
|
| 1419 | - */ |
|
| 1420 | - protected function principalPropertySearchReport($path, Xml\Request\PrincipalPropertySearchReport $report) |
|
| 1421 | - { |
|
| 1422 | - if ($report->applyToPrincipalCollectionSet) { |
|
| 1423 | - $path = null; |
|
| 1424 | - } |
|
| 1425 | - if (0 !== $this->server->getHttpDepth('0')) { |
|
| 1426 | - throw new BadRequest('Depth must be 0'); |
|
| 1427 | - } |
|
| 1428 | - $result = $this->principalSearch( |
|
| 1429 | - $report->searchProperties, |
|
| 1430 | - $report->properties, |
|
| 1431 | - $path, |
|
| 1432 | - $report->test |
|
| 1433 | - ); |
|
| 1434 | - |
|
| 1435 | - $prefer = $this->server->getHTTPPrefer(); |
|
| 1436 | - |
|
| 1437 | - $this->server->httpResponse->setStatus(207); |
|
| 1438 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1439 | - $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
| 1440 | - $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return'])); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * aclPrincipalPropSet REPORT. |
|
| 1445 | - * |
|
| 1446 | - * This method is responsible for handling the {DAV:}acl-principal-prop-set |
|
| 1447 | - * REPORT, as defined in: |
|
| 1448 | - * |
|
| 1449 | - * https://tools.ietf.org/html/rfc3744#section-9.2 |
|
| 1450 | - * |
|
| 1451 | - * This REPORT allows a user to quickly fetch information about all |
|
| 1452 | - * principals specified in the access control list. Most commonly this |
|
| 1453 | - * is used to for example generate a UI with ACL rules, allowing you |
|
| 1454 | - * to show names for principals for every entry. |
|
| 1455 | - * |
|
| 1456 | - * @param string $path |
|
| 1457 | - */ |
|
| 1458 | - protected function aclPrincipalPropSetReport($path, Xml\Request\AclPrincipalPropSetReport $report) |
|
| 1459 | - { |
|
| 1460 | - if (0 !== $this->server->getHTTPDepth(0)) { |
|
| 1461 | - throw new BadRequest('The {DAV:}acl-principal-prop-set REPORT only supports Depth 0'); |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - // Fetching ACL rules for the given path. We're using the property |
|
| 1465 | - // API and not the local getACL, because it will ensure that all |
|
| 1466 | - // business rules and restrictions are applied. |
|
| 1467 | - $acl = $this->server->getProperties($path, '{DAV:}acl'); |
|
| 1468 | - |
|
| 1469 | - if (!$acl || !isset($acl['{DAV:}acl'])) { |
|
| 1470 | - throw new Forbidden('Could not fetch ACL rules for this path'); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - $principals = []; |
|
| 1474 | - foreach ($acl['{DAV:}acl']->getPrivileges() as $ace) { |
|
| 1475 | - if ('{' === $ace['principal'][0]) { |
|
| 1476 | - // It's not a principal, it's one of the special rules such as {DAV:}authenticated |
|
| 1477 | - continue; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - $principals[] = $ace['principal']; |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $properties = $this->server->getPropertiesForMultiplePaths( |
|
| 1484 | - $principals, |
|
| 1485 | - $report->properties |
|
| 1486 | - ); |
|
| 1487 | - |
|
| 1488 | - $this->server->httpResponse->setStatus(207); |
|
| 1489 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1490 | - $this->server->httpResponse->setBody( |
|
| 1491 | - $this->server->generateMultiStatus($properties) |
|
| 1492 | - ); |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - /* }}} */ |
|
| 1496 | - |
|
| 1497 | - /** |
|
| 1498 | - * This method is used to generate HTML output for the |
|
| 1499 | - * DAV\Browser\Plugin. This allows us to generate an interface users |
|
| 1500 | - * can use to create new calendars. |
|
| 1501 | - * |
|
| 1502 | - * @param string $output |
|
| 1503 | - * |
|
| 1504 | - * @return bool |
|
| 1505 | - */ |
|
| 1506 | - public function htmlActionsPanel(DAV\INode $node, &$output) |
|
| 1507 | - { |
|
| 1508 | - if (!$node instanceof PrincipalCollection) { |
|
| 1509 | - return; |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - $output .= '<tr><td colspan="2"><form method="post" action=""> |
|
| 1136 | + foreach ($oldAcl as $oldAce) { |
|
| 1137 | + if (!isset($oldAce['protected']) || !$oldAce['protected']) { |
|
| 1138 | + continue; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + $found = false; |
|
| 1142 | + foreach ($newAcl as $newAce) { |
|
| 1143 | + if ( |
|
| 1144 | + $newAce['privilege'] === $oldAce['privilege'] && |
|
| 1145 | + $newAce['principal'] === $oldAce['principal'] && |
|
| 1146 | + $newAce['protected'] |
|
| 1147 | + ) { |
|
| 1148 | + $found = true; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + if (!$found) { |
|
| 1153 | + throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request'); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + foreach ($newAcl as $newAce) { |
|
| 1158 | + // Do we recognize the privilege |
|
| 1159 | + if (!isset($supportedPrivileges[$newAce['privilege']])) { |
|
| 1160 | + throw new Exception\NotSupportedPrivilege('The privilege you specified ('.$newAce['privilege'].') is not recognized by this server'); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + if ($supportedPrivileges[$newAce['privilege']]['abstract']) { |
|
| 1164 | + throw new Exception\NoAbstract('The privilege you specified ('.$newAce['privilege'].') is an abstract privilege'); |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + // Looking up the principal |
|
| 1168 | + try { |
|
| 1169 | + $principal = $this->server->tree->getNodeForPath($newAce['principal']); |
|
| 1170 | + } catch (NotFound $e) { |
|
| 1171 | + throw new Exception\NotRecognizedPrincipal('The specified principal ('.$newAce['principal'].') does not exist'); |
|
| 1172 | + } |
|
| 1173 | + if (!($principal instanceof IPrincipal)) { |
|
| 1174 | + throw new Exception\NotRecognizedPrincipal('The specified uri ('.$newAce['principal'].') is not a principal'); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + $node->setACL($newAcl); |
|
| 1178 | + |
|
| 1179 | + $response->setStatus(200); |
|
| 1180 | + |
|
| 1181 | + // Breaking the event chain, because we handled this method. |
|
| 1182 | + return false; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + /* }}} */ |
|
| 1186 | + |
|
| 1187 | + /* Reports {{{ */ |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * The principal-match report is defined in RFC3744, section 9.3. |
|
| 1191 | + * |
|
| 1192 | + * This report allows a client to figure out based on the current user, |
|
| 1193 | + * or a principal URL, the principal URL and principal URLs of groups that |
|
| 1194 | + * principal belongs to. |
|
| 1195 | + * |
|
| 1196 | + * @param string $path |
|
| 1197 | + */ |
|
| 1198 | + protected function principalMatchReport($path, Xml\Request\PrincipalMatchReport $report) |
|
| 1199 | + { |
|
| 1200 | + $depth = $this->server->getHTTPDepth(0); |
|
| 1201 | + if (0 !== $depth) { |
|
| 1202 | + throw new BadRequest('The principal-match report is only defined on Depth: 0'); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + $currentPrincipals = $this->getCurrentUserPrincipals(); |
|
| 1206 | + |
|
| 1207 | + $result = []; |
|
| 1208 | + |
|
| 1209 | + if (Xml\Request\PrincipalMatchReport::SELF === $report->type) { |
|
| 1210 | + // Finding all principals under the request uri that match the |
|
| 1211 | + // current principal. |
|
| 1212 | + foreach ($currentPrincipals as $currentPrincipal) { |
|
| 1213 | + if ($currentPrincipal === $path || 0 === strpos($currentPrincipal, $path.'/')) { |
|
| 1214 | + $result[] = $currentPrincipal; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + } else { |
|
| 1218 | + // We need to find all resources that have a property that matches |
|
| 1219 | + // one of the current principals. |
|
| 1220 | + $candidates = $this->server->getPropertiesForPath( |
|
| 1221 | + $path, |
|
| 1222 | + [$report->principalProperty], |
|
| 1223 | + 1 |
|
| 1224 | + ); |
|
| 1225 | + |
|
| 1226 | + foreach ($candidates as $candidate) { |
|
| 1227 | + if (!isset($candidate[200][$report->principalProperty])) { |
|
| 1228 | + continue; |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + $hrefs = $candidate[200][$report->principalProperty]; |
|
| 1232 | + |
|
| 1233 | + if (!$hrefs instanceof Href) { |
|
| 1234 | + continue; |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + foreach ($hrefs->getHrefs() as $href) { |
|
| 1238 | + if (in_array(trim($href, '/'), $currentPrincipals)) { |
|
| 1239 | + $result[] = $candidate['href']; |
|
| 1240 | + continue 2; |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + } |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + $responses = []; |
|
| 1247 | + |
|
| 1248 | + foreach ($result as $item) { |
|
| 1249 | + $properties = []; |
|
| 1250 | + |
|
| 1251 | + if ($report->properties) { |
|
| 1252 | + $foo = $this->server->getPropertiesForPath($item, $report->properties); |
|
| 1253 | + $foo = $foo[0]; |
|
| 1254 | + $item = $foo['href']; |
|
| 1255 | + unset($foo['href']); |
|
| 1256 | + $properties = $foo; |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + $responses[] = new DAV\Xml\Element\Response( |
|
| 1260 | + $item, |
|
| 1261 | + $properties, |
|
| 1262 | + '200' |
|
| 1263 | + ); |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1267 | + $this->server->httpResponse->setStatus(207); |
|
| 1268 | + $this->server->httpResponse->setBody( |
|
| 1269 | + $this->server->xml->write( |
|
| 1270 | + '{DAV:}multistatus', |
|
| 1271 | + $responses, |
|
| 1272 | + $this->server->getBaseUri() |
|
| 1273 | + ) |
|
| 1274 | + ); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * The expand-property report is defined in RFC3253 section 3.8. |
|
| 1279 | + * |
|
| 1280 | + * This report is very similar to a standard PROPFIND. The difference is |
|
| 1281 | + * that it has the additional ability to look at properties containing a |
|
| 1282 | + * {DAV:}href element, follow that property and grab additional elements |
|
| 1283 | + * there. |
|
| 1284 | + * |
|
| 1285 | + * Other rfc's, such as ACL rely on this report, so it made sense to put |
|
| 1286 | + * it in this plugin. |
|
| 1287 | + * |
|
| 1288 | + * @param string $path |
|
| 1289 | + * @param Xml\Request\ExpandPropertyReport $report |
|
| 1290 | + */ |
|
| 1291 | + protected function expandPropertyReport($path, $report) |
|
| 1292 | + { |
|
| 1293 | + $depth = $this->server->getHTTPDepth(0); |
|
| 1294 | + |
|
| 1295 | + $result = $this->expandProperties($path, $report->properties, $depth); |
|
| 1296 | + |
|
| 1297 | + $xml = $this->server->xml->write( |
|
| 1298 | + '{DAV:}multistatus', |
|
| 1299 | + new DAV\Xml\Response\MultiStatus($result), |
|
| 1300 | + $this->server->getBaseUri() |
|
| 1301 | + ); |
|
| 1302 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1303 | + $this->server->httpResponse->setStatus(207); |
|
| 1304 | + $this->server->httpResponse->setBody($xml); |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * This method expands all the properties and returns |
|
| 1309 | + * a list with property values. |
|
| 1310 | + * |
|
| 1311 | + * @param array $path |
|
| 1312 | + * @param array $requestedProperties the list of required properties |
|
| 1313 | + * @param int $depth |
|
| 1314 | + * |
|
| 1315 | + * @return array |
|
| 1316 | + */ |
|
| 1317 | + protected function expandProperties($path, array $requestedProperties, $depth) |
|
| 1318 | + { |
|
| 1319 | + $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth); |
|
| 1320 | + |
|
| 1321 | + $result = []; |
|
| 1322 | + |
|
| 1323 | + foreach ($foundProperties as $node) { |
|
| 1324 | + foreach ($requestedProperties as $propertyName => $childRequestedProperties) { |
|
| 1325 | + // We're only traversing if sub-properties were requested |
|
| 1326 | + if (!is_array($childRequestedProperties) || 0 === count($childRequestedProperties)) { |
|
| 1327 | + continue; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + // We only have to do the expansion if the property was found |
|
| 1331 | + // and it contains an href element. |
|
| 1332 | + if (!array_key_exists($propertyName, $node[200])) { |
|
| 1333 | + continue; |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) { |
|
| 1337 | + continue; |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + $childHrefs = $node[200][$propertyName]->getHrefs(); |
|
| 1341 | + $childProps = []; |
|
| 1342 | + |
|
| 1343 | + foreach ($childHrefs as $href) { |
|
| 1344 | + // Gathering the result of the children |
|
| 1345 | + $childProps[] = [ |
|
| 1346 | + 'name' => '{DAV:}response', |
|
| 1347 | + 'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0], |
|
| 1348 | + ]; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + // Replacing the property with its expanded form. |
|
| 1352 | + $node[200][$propertyName] = $childProps; |
|
| 1353 | + } |
|
| 1354 | + $result[] = new DAV\Xml\Element\Response($node['href'], $node); |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + return $result; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + /** |
|
| 1361 | + * principalSearchPropertySetReport. |
|
| 1362 | + * |
|
| 1363 | + * This method responsible for handing the |
|
| 1364 | + * {DAV:}principal-search-property-set report. This report returns a list |
|
| 1365 | + * of properties the client may search on, using the |
|
| 1366 | + * {DAV:}principal-property-search report. |
|
| 1367 | + * |
|
| 1368 | + * @param string $path |
|
| 1369 | + * @param Xml\Request\PrincipalSearchPropertySetReport $report |
|
| 1370 | + */ |
|
| 1371 | + protected function principalSearchPropertySetReport($path, $report) |
|
| 1372 | + { |
|
| 1373 | + $httpDepth = $this->server->getHTTPDepth(0); |
|
| 1374 | + if (0 !== $httpDepth) { |
|
| 1375 | + throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0'); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + $writer = $this->server->xml->getWriter(); |
|
| 1379 | + $writer->openMemory(); |
|
| 1380 | + $writer->startDocument(); |
|
| 1381 | + |
|
| 1382 | + $writer->startElement('{DAV:}principal-search-property-set'); |
|
| 1383 | + |
|
| 1384 | + foreach ($this->principalSearchPropertySet as $propertyName => $description) { |
|
| 1385 | + $writer->startElement('{DAV:}principal-search-property'); |
|
| 1386 | + $writer->startElement('{DAV:}prop'); |
|
| 1387 | + |
|
| 1388 | + $writer->writeElement($propertyName); |
|
| 1389 | + |
|
| 1390 | + $writer->endElement(); // prop |
|
| 1391 | + |
|
| 1392 | + if ($description) { |
|
| 1393 | + $writer->write([[ |
|
| 1394 | + 'name' => '{DAV:}description', |
|
| 1395 | + 'value' => $description, |
|
| 1396 | + 'attributes' => ['xml:lang' => 'en'], |
|
| 1397 | + ]]); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + $writer->endElement(); // principal-search-property |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + $writer->endElement(); // principal-search-property-set |
|
| 1404 | + |
|
| 1405 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1406 | + $this->server->httpResponse->setStatus(200); |
|
| 1407 | + $this->server->httpResponse->setBody($writer->outputMemory()); |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + /** |
|
| 1411 | + * principalPropertySearchReport. |
|
| 1412 | + * |
|
| 1413 | + * This method is responsible for handing the |
|
| 1414 | + * {DAV:}principal-property-search report. This report can be used for |
|
| 1415 | + * clients to search for groups of principals, based on the value of one |
|
| 1416 | + * or more properties. |
|
| 1417 | + * |
|
| 1418 | + * @param string $path |
|
| 1419 | + */ |
|
| 1420 | + protected function principalPropertySearchReport($path, Xml\Request\PrincipalPropertySearchReport $report) |
|
| 1421 | + { |
|
| 1422 | + if ($report->applyToPrincipalCollectionSet) { |
|
| 1423 | + $path = null; |
|
| 1424 | + } |
|
| 1425 | + if (0 !== $this->server->getHttpDepth('0')) { |
|
| 1426 | + throw new BadRequest('Depth must be 0'); |
|
| 1427 | + } |
|
| 1428 | + $result = $this->principalSearch( |
|
| 1429 | + $report->searchProperties, |
|
| 1430 | + $report->properties, |
|
| 1431 | + $path, |
|
| 1432 | + $report->test |
|
| 1433 | + ); |
|
| 1434 | + |
|
| 1435 | + $prefer = $this->server->getHTTPPrefer(); |
|
| 1436 | + |
|
| 1437 | + $this->server->httpResponse->setStatus(207); |
|
| 1438 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1439 | + $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
| 1440 | + $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return'])); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * aclPrincipalPropSet REPORT. |
|
| 1445 | + * |
|
| 1446 | + * This method is responsible for handling the {DAV:}acl-principal-prop-set |
|
| 1447 | + * REPORT, as defined in: |
|
| 1448 | + * |
|
| 1449 | + * https://tools.ietf.org/html/rfc3744#section-9.2 |
|
| 1450 | + * |
|
| 1451 | + * This REPORT allows a user to quickly fetch information about all |
|
| 1452 | + * principals specified in the access control list. Most commonly this |
|
| 1453 | + * is used to for example generate a UI with ACL rules, allowing you |
|
| 1454 | + * to show names for principals for every entry. |
|
| 1455 | + * |
|
| 1456 | + * @param string $path |
|
| 1457 | + */ |
|
| 1458 | + protected function aclPrincipalPropSetReport($path, Xml\Request\AclPrincipalPropSetReport $report) |
|
| 1459 | + { |
|
| 1460 | + if (0 !== $this->server->getHTTPDepth(0)) { |
|
| 1461 | + throw new BadRequest('The {DAV:}acl-principal-prop-set REPORT only supports Depth 0'); |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + // Fetching ACL rules for the given path. We're using the property |
|
| 1465 | + // API and not the local getACL, because it will ensure that all |
|
| 1466 | + // business rules and restrictions are applied. |
|
| 1467 | + $acl = $this->server->getProperties($path, '{DAV:}acl'); |
|
| 1468 | + |
|
| 1469 | + if (!$acl || !isset($acl['{DAV:}acl'])) { |
|
| 1470 | + throw new Forbidden('Could not fetch ACL rules for this path'); |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + $principals = []; |
|
| 1474 | + foreach ($acl['{DAV:}acl']->getPrivileges() as $ace) { |
|
| 1475 | + if ('{' === $ace['principal'][0]) { |
|
| 1476 | + // It's not a principal, it's one of the special rules such as {DAV:}authenticated |
|
| 1477 | + continue; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + $principals[] = $ace['principal']; |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $properties = $this->server->getPropertiesForMultiplePaths( |
|
| 1484 | + $principals, |
|
| 1485 | + $report->properties |
|
| 1486 | + ); |
|
| 1487 | + |
|
| 1488 | + $this->server->httpResponse->setStatus(207); |
|
| 1489 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
| 1490 | + $this->server->httpResponse->setBody( |
|
| 1491 | + $this->server->generateMultiStatus($properties) |
|
| 1492 | + ); |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + /* }}} */ |
|
| 1496 | + |
|
| 1497 | + /** |
|
| 1498 | + * This method is used to generate HTML output for the |
|
| 1499 | + * DAV\Browser\Plugin. This allows us to generate an interface users |
|
| 1500 | + * can use to create new calendars. |
|
| 1501 | + * |
|
| 1502 | + * @param string $output |
|
| 1503 | + * |
|
| 1504 | + * @return bool |
|
| 1505 | + */ |
|
| 1506 | + public function htmlActionsPanel(DAV\INode $node, &$output) |
|
| 1507 | + { |
|
| 1508 | + if (!$node instanceof PrincipalCollection) { |
|
| 1509 | + return; |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + $output .= '<tr><td colspan="2"><form method="post" action=""> |
|
| 1513 | 1513 | <h3>Create new principal</h3> |
| 1514 | 1514 | <input type="hidden" name="sabreAction" value="mkcol" /> |
| 1515 | 1515 | <input type="hidden" name="resourceType" value="{DAV:}principal" /> |
@@ -1520,26 +1520,26 @@ discard block |
||
| 1520 | 1520 | </form> |
| 1521 | 1521 | </td></tr>'; |
| 1522 | 1522 | |
| 1523 | - return false; |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - /** |
|
| 1527 | - * Returns a bunch of meta-data about the plugin. |
|
| 1528 | - * |
|
| 1529 | - * Providing this information is optional, and is mainly displayed by the |
|
| 1530 | - * Browser plugin. |
|
| 1531 | - * |
|
| 1532 | - * The description key in the returned array may contain html and will not |
|
| 1533 | - * be sanitized. |
|
| 1534 | - * |
|
| 1535 | - * @return array |
|
| 1536 | - */ |
|
| 1537 | - public function getPluginInfo() |
|
| 1538 | - { |
|
| 1539 | - return [ |
|
| 1540 | - 'name' => $this->getPluginName(), |
|
| 1541 | - 'description' => 'Adds support for WebDAV ACL (rfc3744)', |
|
| 1542 | - 'link' => 'http://sabre.io/dav/acl/', |
|
| 1543 | - ]; |
|
| 1544 | - } |
|
| 1523 | + return false; |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + /** |
|
| 1527 | + * Returns a bunch of meta-data about the plugin. |
|
| 1528 | + * |
|
| 1529 | + * Providing this information is optional, and is mainly displayed by the |
|
| 1530 | + * Browser plugin. |
|
| 1531 | + * |
|
| 1532 | + * The description key in the returned array may contain html and will not |
|
| 1533 | + * be sanitized. |
|
| 1534 | + * |
|
| 1535 | + * @return array |
|
| 1536 | + */ |
|
| 1537 | + public function getPluginInfo() |
|
| 1538 | + { |
|
| 1539 | + return [ |
|
| 1540 | + 'name' => $this->getPluginName(), |
|
| 1541 | + 'description' => 'Adds support for WebDAV ACL (rfc3744)', |
|
| 1542 | + 'link' => 'http://sabre.io/dav/acl/', |
|
| 1543 | + ]; |
|
| 1544 | + } |
|
| 1545 | 1545 | } |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | ]; |
| 524 | 524 | |
| 525 | 525 | $fpsTraverse = null; |
| 526 | - $fpsTraverse = function ($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { |
|
| 526 | + $fpsTraverse = function($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { |
|
| 527 | 527 | $myPriv = [ |
| 528 | 528 | 'privilege' => $privName, |
| 529 | 529 | 'abstract' => isset($privInfo['abstract']) && $privInfo['abstract'], |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | $server->on('report', [$this, 'report']); |
| 783 | 783 | $server->on('method:ACL', [$this, 'httpAcl']); |
| 784 | 784 | $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); |
| 785 | - $server->on('getPrincipalByUri', function ($principal, &$uri) { |
|
| 785 | + $server->on('getPrincipalByUri', function($principal, &$uri) { |
|
| 786 | 786 | $uri = $this->getPrincipalByUri($principal); |
| 787 | 787 | |
| 788 | 788 | // Break event chain |
@@ -953,13 +953,13 @@ discard block |
||
| 953 | 953 | |
| 954 | 954 | /* Adding principal properties */ |
| 955 | 955 | if ($node instanceof IPrincipal) { |
| 956 | - $propFind->handle('{DAV:}alternate-URI-set', function () use ($node) { |
|
| 956 | + $propFind->handle('{DAV:}alternate-URI-set', function() use ($node) { |
|
| 957 | 957 | return new Href($node->getAlternateUriSet()); |
| 958 | 958 | }); |
| 959 | - $propFind->handle('{DAV:}principal-URL', function () use ($node) { |
|
| 959 | + $propFind->handle('{DAV:}principal-URL', function() use ($node) { |
|
| 960 | 960 | return new Href($node->getPrincipalUrl().'/'); |
| 961 | 961 | }); |
| 962 | - $propFind->handle('{DAV:}group-member-set', function () use ($node) { |
|
| 962 | + $propFind->handle('{DAV:}group-member-set', function() use ($node) { |
|
| 963 | 963 | $members = $node->getGroupMemberSet(); |
| 964 | 964 | foreach ($members as $k => $member) { |
| 965 | 965 | $members[$k] = rtrim($member, '/').'/'; |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | |
| 968 | 968 | return new Href($members); |
| 969 | 969 | }); |
| 970 | - $propFind->handle('{DAV:}group-membership', function () use ($node) { |
|
| 970 | + $propFind->handle('{DAV:}group-membership', function() use ($node) { |
|
| 971 | 971 | $members = $node->getGroupMembership(); |
| 972 | 972 | foreach ($members as $k => $member) { |
| 973 | 973 | $members[$k] = rtrim($member, '/').'/'; |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']); |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | - $propFind->handle('{DAV:}principal-collection-set', function () { |
|
| 981 | + $propFind->handle('{DAV:}principal-collection-set', function() { |
|
| 982 | 982 | $val = $this->principalCollectionSet; |
| 983 | 983 | // Ensuring all collections end with a slash |
| 984 | 984 | foreach ($val as $k => $v) { |
@@ -987,17 +987,17 @@ discard block |
||
| 987 | 987 | |
| 988 | 988 | return new Href($val); |
| 989 | 989 | }); |
| 990 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
| 990 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
| 991 | 991 | if ($url = $this->getCurrentUserPrincipal()) { |
| 992 | 992 | return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url.'/'); |
| 993 | 993 | } else { |
| 994 | 994 | return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED); |
| 995 | 995 | } |
| 996 | 996 | }); |
| 997 | - $propFind->handle('{DAV:}supported-privilege-set', function () use ($node) { |
|
| 997 | + $propFind->handle('{DAV:}supported-privilege-set', function() use ($node) { |
|
| 998 | 998 | return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node)); |
| 999 | 999 | }); |
| 1000 | - $propFind->handle('{DAV:}current-user-privilege-set', function () use ($node, $propFind, $path) { |
|
| 1000 | + $propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) { |
|
| 1001 | 1001 | if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) { |
| 1002 | 1002 | $propFind->set('{DAV:}current-user-privilege-set', null, 403); |
| 1003 | 1003 | } else { |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | return new Xml\Property\CurrentUserPrivilegeSet($val); |
| 1007 | 1007 | } |
| 1008 | 1008 | }); |
| 1009 | - $propFind->handle('{DAV:}acl', function () use ($node, $propFind, $path) { |
|
| 1009 | + $propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) { |
|
| 1010 | 1010 | /* The ACL property contains all the permissions */ |
| 1011 | 1011 | if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) { |
| 1012 | 1012 | $propFind->set('{DAV:}acl', null, 403); |
@@ -1016,13 +1016,13 @@ discard block |
||
| 1016 | 1016 | return new Xml\Property\Acl($this->getACL($node)); |
| 1017 | 1017 | } |
| 1018 | 1018 | }); |
| 1019 | - $propFind->handle('{DAV:}acl-restrictions', function () { |
|
| 1019 | + $propFind->handle('{DAV:}acl-restrictions', function() { |
|
| 1020 | 1020 | return new Xml\Property\AclRestrictions(); |
| 1021 | 1021 | }); |
| 1022 | 1022 | |
| 1023 | 1023 | /* Adding ACL properties */ |
| 1024 | 1024 | if ($node instanceof IACL) { |
| 1025 | - $propFind->handle('{DAV:}owner', function () use ($node) { |
|
| 1025 | + $propFind->handle('{DAV:}owner', function() use ($node) { |
|
| 1026 | 1026 | return new Href($node->getOwner().'/'); |
| 1027 | 1027 | }); |
| 1028 | 1028 | } |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | */ |
| 1037 | 1037 | public function propPatch($path, DAV\PropPatch $propPatch) |
| 1038 | 1038 | { |
| 1039 | - $propPatch->handle('{DAV:}group-member-set', function ($value) use ($path) { |
|
| 1039 | + $propPatch->handle('{DAV:}group-member-set', function($value) use ($path) { |
|
| 1040 | 1040 | if (is_null($value)) { |
| 1041 | 1041 | $memberSet = []; |
| 1042 | 1042 | } elseif ($value instanceof Href) { |
@@ -17,62 +17,62 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class File extends BaseFile implements IACL |
| 19 | 19 | { |
| 20 | - use ACLTrait; |
|
| 20 | + use ACLTrait; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * A list of ACL rules. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $acl; |
|
| 22 | + /** |
|
| 23 | + * A list of ACL rules. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $acl; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Owner uri, or null for no owner. |
|
| 31 | - * |
|
| 32 | - * @var string|null |
|
| 33 | - */ |
|
| 34 | - protected $owner; |
|
| 29 | + /** |
|
| 30 | + * Owner uri, or null for no owner. |
|
| 31 | + * |
|
| 32 | + * @var string|null |
|
| 33 | + */ |
|
| 34 | + protected $owner; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor. |
|
| 38 | - * |
|
| 39 | - * @param string $path on-disk path |
|
| 40 | - * @param array $acl ACL rules |
|
| 41 | - * @param string|null $owner principal owner string |
|
| 42 | - */ |
|
| 43 | - public function __construct($path, array $acl, $owner = null) |
|
| 44 | - { |
|
| 45 | - parent::__construct($path); |
|
| 46 | - $this->acl = $acl; |
|
| 47 | - $this->owner = $owner; |
|
| 48 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor. |
|
| 38 | + * |
|
| 39 | + * @param string $path on-disk path |
|
| 40 | + * @param array $acl ACL rules |
|
| 41 | + * @param string|null $owner principal owner string |
|
| 42 | + */ |
|
| 43 | + public function __construct($path, array $acl, $owner = null) |
|
| 44 | + { |
|
| 45 | + parent::__construct($path); |
|
| 46 | + $this->acl = $acl; |
|
| 47 | + $this->owner = $owner; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Returns the owner principal. |
|
| 52 | - * |
|
| 53 | - * This must be a url to a principal, or null if there's no owner |
|
| 54 | - * |
|
| 55 | - * @return string|null |
|
| 56 | - */ |
|
| 57 | - public function getOwner() |
|
| 58 | - { |
|
| 59 | - return $this->owner; |
|
| 60 | - } |
|
| 50 | + /** |
|
| 51 | + * Returns the owner principal. |
|
| 52 | + * |
|
| 53 | + * This must be a url to a principal, or null if there's no owner |
|
| 54 | + * |
|
| 55 | + * @return string|null |
|
| 56 | + */ |
|
| 57 | + public function getOwner() |
|
| 58 | + { |
|
| 59 | + return $this->owner; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Returns a list of ACE's for this node. |
|
| 64 | - * |
|
| 65 | - * Each ACE has the following properties: |
|
| 66 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 67 | - * currently the only supported privileges |
|
| 68 | - * * 'principal', a url to the principal who owns the node |
|
| 69 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 70 | - * be updated. |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function getACL() |
|
| 75 | - { |
|
| 76 | - return $this->acl; |
|
| 77 | - } |
|
| 62 | + /** |
|
| 63 | + * Returns a list of ACE's for this node. |
|
| 64 | + * |
|
| 65 | + * Each ACE has the following properties: |
|
| 66 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 67 | + * currently the only supported privileges |
|
| 68 | + * * 'principal', a url to the principal who owns the node |
|
| 69 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 70 | + * be updated. |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function getACL() |
|
| 75 | + { |
|
| 76 | + return $this->acl; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -19,91 +19,91 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Collection extends BaseCollection implements IACL |
| 21 | 21 | { |
| 22 | - use ACLTrait; |
|
| 22 | + use ACLTrait; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A list of ACL rules. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $acl; |
|
| 24 | + /** |
|
| 25 | + * A list of ACL rules. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $acl; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Owner uri, or null for no owner. |
|
| 33 | - * |
|
| 34 | - * @var string|null |
|
| 35 | - */ |
|
| 36 | - protected $owner; |
|
| 31 | + /** |
|
| 32 | + * Owner uri, or null for no owner. |
|
| 33 | + * |
|
| 34 | + * @var string|null |
|
| 35 | + */ |
|
| 36 | + protected $owner; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor. |
|
| 40 | - * |
|
| 41 | - * @param string $path on-disk path |
|
| 42 | - * @param array $acl ACL rules |
|
| 43 | - * @param string|null $owner principal owner string |
|
| 44 | - */ |
|
| 45 | - public function __construct($path, array $acl, $owner = null) |
|
| 46 | - { |
|
| 47 | - parent::__construct($path); |
|
| 48 | - $this->acl = $acl; |
|
| 49 | - $this->owner = $owner; |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor. |
|
| 40 | + * |
|
| 41 | + * @param string $path on-disk path |
|
| 42 | + * @param array $acl ACL rules |
|
| 43 | + * @param string|null $owner principal owner string |
|
| 44 | + */ |
|
| 45 | + public function __construct($path, array $acl, $owner = null) |
|
| 46 | + { |
|
| 47 | + parent::__construct($path); |
|
| 48 | + $this->acl = $acl; |
|
| 49 | + $this->owner = $owner; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Returns a specific child node, referenced by its name. |
|
| 54 | - * |
|
| 55 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 56 | - * exist. |
|
| 57 | - * |
|
| 58 | - * @param string $name |
|
| 59 | - * |
|
| 60 | - * @throws NotFound |
|
| 61 | - * |
|
| 62 | - * @return \Sabre\DAV\INode |
|
| 63 | - */ |
|
| 64 | - public function getChild($name) |
|
| 65 | - { |
|
| 66 | - $path = $this->path.'/'.$name; |
|
| 52 | + /** |
|
| 53 | + * Returns a specific child node, referenced by its name. |
|
| 54 | + * |
|
| 55 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
| 56 | + * exist. |
|
| 57 | + * |
|
| 58 | + * @param string $name |
|
| 59 | + * |
|
| 60 | + * @throws NotFound |
|
| 61 | + * |
|
| 62 | + * @return \Sabre\DAV\INode |
|
| 63 | + */ |
|
| 64 | + public function getChild($name) |
|
| 65 | + { |
|
| 66 | + $path = $this->path.'/'.$name; |
|
| 67 | 67 | |
| 68 | - if (!file_exists($path)) { |
|
| 69 | - throw new NotFound('File could not be located'); |
|
| 70 | - } |
|
| 71 | - if ('.' == $name || '..' == $name) { |
|
| 72 | - throw new Forbidden('Permission denied to . and ..'); |
|
| 73 | - } |
|
| 74 | - if (is_dir($path)) { |
|
| 75 | - return new self($path, $this->acl, $this->owner); |
|
| 76 | - } else { |
|
| 77 | - return new File($path, $this->acl, $this->owner); |
|
| 78 | - } |
|
| 79 | - } |
|
| 68 | + if (!file_exists($path)) { |
|
| 69 | + throw new NotFound('File could not be located'); |
|
| 70 | + } |
|
| 71 | + if ('.' == $name || '..' == $name) { |
|
| 72 | + throw new Forbidden('Permission denied to . and ..'); |
|
| 73 | + } |
|
| 74 | + if (is_dir($path)) { |
|
| 75 | + return new self($path, $this->acl, $this->owner); |
|
| 76 | + } else { |
|
| 77 | + return new File($path, $this->acl, $this->owner); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Returns the owner principal. |
|
| 83 | - * |
|
| 84 | - * This must be a url to a principal, or null if there's no owner |
|
| 85 | - * |
|
| 86 | - * @return string|null |
|
| 87 | - */ |
|
| 88 | - public function getOwner() |
|
| 89 | - { |
|
| 90 | - return $this->owner; |
|
| 91 | - } |
|
| 81 | + /** |
|
| 82 | + * Returns the owner principal. |
|
| 83 | + * |
|
| 84 | + * This must be a url to a principal, or null if there's no owner |
|
| 85 | + * |
|
| 86 | + * @return string|null |
|
| 87 | + */ |
|
| 88 | + public function getOwner() |
|
| 89 | + { |
|
| 90 | + return $this->owner; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns a list of ACE's for this node. |
|
| 95 | - * |
|
| 96 | - * Each ACE has the following properties: |
|
| 97 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 98 | - * currently the only supported privileges |
|
| 99 | - * * 'principal', a url to the principal who owns the node |
|
| 100 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 101 | - * be updated. |
|
| 102 | - * |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - public function getACL() |
|
| 106 | - { |
|
| 107 | - return $this->acl; |
|
| 108 | - } |
|
| 93 | + /** |
|
| 94 | + * Returns a list of ACE's for this node. |
|
| 95 | + * |
|
| 96 | + * Each ACE has the following properties: |
|
| 97 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 98 | + * currently the only supported privileges |
|
| 99 | + * * 'principal', a url to the principal who owns the node |
|
| 100 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 101 | + * be updated. |
|
| 102 | + * |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + public function getACL() |
|
| 106 | + { |
|
| 107 | + return $this->acl; |
|
| 108 | + } |
|
| 109 | 109 | } |