You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.2 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OC\User;
  25. use OCP\UserInterface;
  26. /**
  27. * Abstract base class for user management. Provides methods for querying backend
  28. * capabilities.
  29. */
  30. abstract class Backend implements UserInterface {
  31. /**
  32. * error code for functions not provided by the user backend
  33. */
  34. public const NOT_IMPLEMENTED = -501;
  35. /**
  36. * actions that user backends can define
  37. */
  38. public const CREATE_USER = 1; // 1 << 0
  39. public const SET_PASSWORD = 16; // 1 << 4
  40. public const CHECK_PASSWORD = 256; // 1 << 8
  41. public const GET_HOME = 4096; // 1 << 12
  42. public const GET_DISPLAYNAME = 65536; // 1 << 16
  43. public const SET_DISPLAYNAME = 1048576; // 1 << 20
  44. public const PROVIDE_AVATAR = 16777216; // 1 << 24
  45. public const COUNT_USERS = 268435456; // 1 << 28
  46. protected $possibleActions = [
  47. self::CREATE_USER => 'createUser',
  48. self::SET_PASSWORD => 'setPassword',
  49. self::CHECK_PASSWORD => 'checkPassword',
  50. self::GET_HOME => 'getHome',
  51. self::GET_DISPLAYNAME => 'getDisplayName',
  52. self::SET_DISPLAYNAME => 'setDisplayName',
  53. self::PROVIDE_AVATAR => 'canChangeAvatar',
  54. self::COUNT_USERS => 'countUsers',
  55. ];
  56. /**
  57. * Get all supported actions
  58. * @return int bitwise-or'ed actions
  59. *
  60. * Returns the supported actions as int to be
  61. * compared with self::CREATE_USER etc.
  62. */
  63. public function getSupportedActions() {
  64. $actions = 0;
  65. foreach ($this->possibleActions as $action => $methodName) {
  66. if (method_exists($this, $methodName)) {
  67. $actions |= $action;
  68. }
  69. }
  70. return $actions;
  71. }
  72. /**
  73. * Check if backend implements actions
  74. * @param int $actions bitwise-or'ed actions
  75. * @return boolean
  76. *
  77. * Returns the supported actions as int to be
  78. * compared with self::CREATE_USER etc.
  79. */
  80. public function implementsActions($actions) {
  81. return (bool)($this->getSupportedActions() & $actions);
  82. }
  83. /**
  84. * delete a user
  85. * @param string $uid The username of the user to delete
  86. * @return bool
  87. *
  88. * Deletes a user
  89. */
  90. public function deleteUser($uid) {
  91. return false;
  92. }
  93. /**
  94. * Get a list of all users
  95. *
  96. * @param string $search
  97. * @param null|int $limit
  98. * @param null|int $offset
  99. * @return string[] an array of all uids
  100. */
  101. public function getUsers($search = '', $limit = null, $offset = null) {
  102. return [];
  103. }
  104. /**
  105. * check if a user exists
  106. * @param string $uid the username
  107. * @return boolean
  108. */
  109. public function userExists($uid) {
  110. return false;
  111. }
  112. /**
  113. * get the user's home directory
  114. * @param string $uid the username
  115. * @return boolean
  116. */
  117. public function getHome($uid) {
  118. return false;
  119. }
  120. /**
  121. * get display name of the user
  122. * @param string $uid user ID of the user
  123. * @return string display name
  124. */
  125. public function getDisplayName($uid) {
  126. return $uid;
  127. }
  128. /**
  129. * Get a list of all display names and user ids.
  130. *
  131. * @param string $search
  132. * @param string|null $limit
  133. * @param string|null $offset
  134. * @return array an array of all displayNames (value) and the corresponding uids (key)
  135. */
  136. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  137. $displayNames = [];
  138. $users = $this->getUsers($search, $limit, $offset);
  139. foreach ($users as $user) {
  140. $displayNames[$user] = $user;
  141. }
  142. return $displayNames;
  143. }
  144. /**
  145. * Check if a user list is available or not
  146. * @return boolean if users can be listed or not
  147. */
  148. public function hasUserListings() {
  149. return false;
  150. }
  151. }