Backend.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\User;
  23. use \OCP\UserInterface;
  24. /**
  25. * Abstract base class for user management. Provides methods for querying backend
  26. * capabilities.
  27. */
  28. abstract class Backend implements UserInterface {
  29. /**
  30. * error code for functions not provided by the user backend
  31. */
  32. const NOT_IMPLEMENTED = -501;
  33. /**
  34. * actions that user backends can define
  35. */
  36. const CREATE_USER = 1; // 1 << 0
  37. const SET_PASSWORD = 16; // 1 << 4
  38. const CHECK_PASSWORD = 256; // 1 << 8
  39. const GET_HOME = 4096; // 1 << 12
  40. const GET_DISPLAYNAME = 65536; // 1 << 16
  41. const SET_DISPLAYNAME = 1048576; // 1 << 20
  42. const PROVIDE_AVATAR = 16777216; // 1 << 24
  43. const COUNT_USERS = 268435456; // 1 << 28
  44. protected $possibleActions = array(
  45. self::CREATE_USER => 'createUser',
  46. self::SET_PASSWORD => 'setPassword',
  47. self::CHECK_PASSWORD => 'checkPassword',
  48. self::GET_HOME => 'getHome',
  49. self::GET_DISPLAYNAME => 'getDisplayName',
  50. self::SET_DISPLAYNAME => 'setDisplayName',
  51. self::PROVIDE_AVATAR => 'canChangeAvatar',
  52. self::COUNT_USERS => 'countUsers',
  53. );
  54. /**
  55. * Get all supported actions
  56. * @return int bitwise-or'ed actions
  57. *
  58. * Returns the supported actions as int to be
  59. * compared with self::CREATE_USER etc.
  60. */
  61. public function getSupportedActions() {
  62. $actions = 0;
  63. foreach($this->possibleActions AS $action => $methodName) {
  64. if(method_exists($this, $methodName)) {
  65. $actions |= $action;
  66. }
  67. }
  68. return $actions;
  69. }
  70. /**
  71. * Check if backend implements actions
  72. * @param int $actions bitwise-or'ed actions
  73. * @return boolean
  74. *
  75. * Returns the supported actions as int to be
  76. * compared with self::CREATE_USER etc.
  77. */
  78. public function implementsActions($actions) {
  79. return (bool)($this->getSupportedActions() & $actions);
  80. }
  81. /**
  82. * delete a user
  83. * @param string $uid The username of the user to delete
  84. * @return bool
  85. *
  86. * Deletes a user
  87. */
  88. public function deleteUser( $uid ) {
  89. return false;
  90. }
  91. /**
  92. * Get a list of all users
  93. *
  94. * @param string $search
  95. * @param null|int $limit
  96. * @param null|int $offset
  97. * @return string[] an array of all uids
  98. */
  99. public function getUsers($search = '', $limit = null, $offset = null) {
  100. return array();
  101. }
  102. /**
  103. * check if a user exists
  104. * @param string $uid the username
  105. * @return boolean
  106. */
  107. public function userExists($uid) {
  108. return false;
  109. }
  110. /**
  111. * get the user's home directory
  112. * @param string $uid the username
  113. * @return boolean
  114. */
  115. public function getHome($uid) {
  116. return false;
  117. }
  118. /**
  119. * get display name of the user
  120. * @param string $uid user ID of the user
  121. * @return string display name
  122. */
  123. public function getDisplayName($uid) {
  124. return $uid;
  125. }
  126. /**
  127. * Get a list of all display names and user ids.
  128. *
  129. * @param string $search
  130. * @param string|null $limit
  131. * @param string|null $offset
  132. * @return array an array of all displayNames (value) and the corresponding uids (key)
  133. */
  134. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  135. $displayNames = array();
  136. $users = $this->getUsers($search, $limit, $offset);
  137. foreach ( $users as $user) {
  138. $displayNames[$user] = $user;
  139. }
  140. return $displayNames;
  141. }
  142. /**
  143. * Check if a user list is available or not
  144. * @return boolean if users can be listed or not
  145. */
  146. public function hasUserListings() {
  147. return false;
  148. }
  149. }