SystemPrincipalBackend.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\DAV;
  25. use Sabre\DAVACL\PrincipalBackend\AbstractBackend;
  26. class SystemPrincipalBackend extends AbstractBackend {
  27. /**
  28. * Returns a list of principals based on a prefix.
  29. *
  30. * This prefix will often contain something like 'principals'. You are only
  31. * expected to return principals that are in this base path.
  32. *
  33. * You are expected to return at least a 'uri' for every user, you can
  34. * return any additional properties if you wish so. Common properties are:
  35. * {DAV:}displayname
  36. * {http://sabredav.org/ns}email-address - This is a custom SabreDAV
  37. * field that's actually injected in a number of other properties. If
  38. * you have an email address, use this property.
  39. *
  40. * @param string $prefixPath
  41. * @return array
  42. */
  43. public function getPrincipalsByPrefix($prefixPath) {
  44. $principals = [];
  45. if ($prefixPath === 'principals/system') {
  46. $principals[] = [
  47. 'uri' => 'principals/system/system',
  48. '{DAV:}displayname' => 'system',
  49. ];
  50. $principals[] = [
  51. 'uri' => 'principals/system/public',
  52. '{DAV:}displayname' => 'public',
  53. ];
  54. }
  55. return $principals;
  56. }
  57. /**
  58. * Returns a specific principal, specified by it's path.
  59. * The returned structure should be the exact same as from
  60. * getPrincipalsByPrefix.
  61. *
  62. * @param string $path
  63. * @return array
  64. */
  65. public function getPrincipalByPath($path) {
  66. if ($path === 'principals/system/system') {
  67. $principal = [
  68. 'uri' => 'principals/system/system',
  69. '{DAV:}displayname' => 'system',
  70. ];
  71. return $principal;
  72. }
  73. if ($path === 'principals/system/public') {
  74. $principal = [
  75. 'uri' => 'principals/system/public',
  76. '{DAV:}displayname' => 'public',
  77. ];
  78. return $principal;
  79. }
  80. return null;
  81. }
  82. /**
  83. * Updates one ore more webdav properties on a principal.
  84. *
  85. * The list of mutations is stored in a Sabre\DAV\PropPatch object.
  86. * To do the actual updates, you must tell this object which properties
  87. * you're going to process with the handle() method.
  88. *
  89. * Calling the handle method is like telling the PropPatch object "I
  90. * promise I can handle updating this property".
  91. *
  92. * Read the PropPatch documentation for more info and examples.
  93. *
  94. * @param string $path
  95. * @param \Sabre\DAV\PropPatch $propPatch
  96. * @return void
  97. */
  98. public function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) {
  99. }
  100. /**
  101. * This method is used to search for principals matching a set of
  102. * properties.
  103. *
  104. * This search is specifically used by RFC3744's principal-property-search
  105. * REPORT.
  106. *
  107. * The actual search should be a unicode-non-case-sensitive search. The
  108. * keys in searchProperties are the WebDAV property names, while the values
  109. * are the property values to search on.
  110. *
  111. * By default, if multiple properties are submitted to this method, the
  112. * various properties should be combined with 'AND'. If $test is set to
  113. * 'anyof', it should be combined using 'OR'.
  114. *
  115. * This method should simply return an array with full principal uri's.
  116. *
  117. * If somebody attempted to search on a property the backend does not
  118. * support, you should simply return 0 results.
  119. *
  120. * You can also just return 0 results if you choose to not support
  121. * searching at all, but keep in mind that this may stop certain features
  122. * from working.
  123. *
  124. * @param string $prefixPath
  125. * @param array $searchProperties
  126. * @param string $test
  127. * @return array
  128. */
  129. public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') {
  130. return [];
  131. }
  132. /**
  133. * Returns the list of members for a group-principal
  134. *
  135. * @param string $principal
  136. * @return array
  137. */
  138. public function getGroupMemberSet($principal) {
  139. // TODO: for now the group principal has only one member, the user itself
  140. $principal = $this->getPrincipalByPath($principal);
  141. if (!$principal) {
  142. throw new \Sabre\DAV\Exception('Principal not found');
  143. }
  144. return [$principal['uri']];
  145. }
  146. /**
  147. * Returns the list of groups a principal is a member of
  148. *
  149. * @param string $principal
  150. * @return array
  151. */
  152. public function getGroupMembership($principal) {
  153. list($prefix, ) = \Sabre\Uri\split($principal);
  154. if ($prefix === 'principals/system') {
  155. $principal = $this->getPrincipalByPath($principal);
  156. if (!$principal) {
  157. throw new \Sabre\DAV\Exception('Principal not found');
  158. }
  159. return [];
  160. }
  161. return [];
  162. }
  163. /**
  164. * Updates the list of group members for a group principal.
  165. *
  166. * The principals should be passed as a list of uri's.
  167. *
  168. * @param string $principal
  169. * @param array $members
  170. * @return void
  171. */
  172. public function setGroupMemberSet($principal, array $members) {
  173. throw new \Sabre\DAV\Exception('Setting members of the group is not supported yet');
  174. }
  175. }