SystemPrincipalBackend.php 4.8 KB

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