SystemPrincipalBackend.php 5.4 KB

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