backend.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Aldo "xoen" Giambelluca <xoen@xoen.org>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Björn Schießle <bjoern@schiessle.org>
  8. * @author Dominik Schmidt <dev@dominik-schmidt.de>
  9. * @author Georg Ehrke <georg@owncloud.com>
  10. * @author Jakob Sack <mail@jakobsack.de>
  11. * @author Joas Schilling <coding@schilljs.com>
  12. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  13. * @author Lukas Reschke <lukas@statuscode.ch>
  14. * @author Morris Jobke <hey@morrisjobke.de>
  15. * @author Robin Appelman <robin@icewind.nl>
  16. * @author Sam Tuke <mail@samtuke.com>
  17. * @author Thomas Müller <thomas.mueller@tmit.eu>
  18. * @author Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  19. *
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. /**
  36. * error code for functions not provided by the user backend
  37. * @deprecated Use \OC_User_Backend::NOT_IMPLEMENTED instead
  38. */
  39. define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
  40. /**
  41. * actions that user backends can define
  42. */
  43. /** @deprecated Use \OC_User_Backend::CREATE_USER instead */
  44. define('OC_USER_BACKEND_CREATE_USER', 1 << 0);
  45. /** @deprecated Use \OC_User_Backend::SET_PASSWORD instead */
  46. define('OC_USER_BACKEND_SET_PASSWORD', 1 << 4);
  47. /** @deprecated Use \OC_User_Backend::CHECK_PASSWORD instead */
  48. define('OC_USER_BACKEND_CHECK_PASSWORD', 1 << 8);
  49. /** @deprecated Use \OC_User_Backend::GET_HOME instead */
  50. define('OC_USER_BACKEND_GET_HOME', 1 << 12);
  51. /** @deprecated Use \OC_User_Backend::GET_DISPLAYNAME instead */
  52. define('OC_USER_BACKEND_GET_DISPLAYNAME', 1 << 16);
  53. /** @deprecated Use \OC_User_Backend::SET_DISPLAYNAME instead */
  54. define('OC_USER_BACKEND_SET_DISPLAYNAME', 1 << 20);
  55. /** @deprecated Use \OC_User_Backend::PROVIDE_AVATAR instead */
  56. define('OC_USER_BACKEND_PROVIDE_AVATAR', 1 << 24);
  57. /** @deprecated Use \OC_User_Backend::COUNT_USERS instead */
  58. define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
  59. /**
  60. * Abstract base class for user management. Provides methods for querying backend
  61. * capabilities.
  62. */
  63. abstract class OC_User_Backend implements \OCP\UserInterface {
  64. /**
  65. * error code for functions not provided by the user backend
  66. */
  67. const NOT_IMPLEMENTED = -501;
  68. /**
  69. * actions that user backends can define
  70. */
  71. const CREATE_USER = 1; // 1 << 0
  72. const SET_PASSWORD = 16; // 1 << 4
  73. const CHECK_PASSWORD = 256; // 1 << 8
  74. const GET_HOME = 4096; // 1 << 12
  75. const GET_DISPLAYNAME = 65536; // 1 << 16
  76. const SET_DISPLAYNAME = 1048576; // 1 << 20
  77. const PROVIDE_AVATAR = 16777216; // 1 << 24
  78. const COUNT_USERS = 268435456; // 1 << 28
  79. protected $possibleActions = array(
  80. self::CREATE_USER => 'createUser',
  81. self::SET_PASSWORD => 'setPassword',
  82. self::CHECK_PASSWORD => 'checkPassword',
  83. self::GET_HOME => 'getHome',
  84. self::GET_DISPLAYNAME => 'getDisplayName',
  85. self::SET_DISPLAYNAME => 'setDisplayName',
  86. self::PROVIDE_AVATAR => 'canChangeAvatar',
  87. self::COUNT_USERS => 'countUsers',
  88. );
  89. /**
  90. * Get all supported actions
  91. * @return int bitwise-or'ed actions
  92. *
  93. * Returns the supported actions as int to be
  94. * compared with self::CREATE_USER etc.
  95. */
  96. public function getSupportedActions() {
  97. $actions = 0;
  98. foreach($this->possibleActions AS $action => $methodName) {
  99. if(method_exists($this, $methodName)) {
  100. $actions |= $action;
  101. }
  102. }
  103. return $actions;
  104. }
  105. /**
  106. * Check if backend implements actions
  107. * @param int $actions bitwise-or'ed actions
  108. * @return boolean
  109. *
  110. * Returns the supported actions as int to be
  111. * compared with self::CREATE_USER etc.
  112. */
  113. public function implementsActions($actions) {
  114. return (bool)($this->getSupportedActions() & $actions);
  115. }
  116. /**
  117. * delete a user
  118. * @param string $uid The username of the user to delete
  119. * @return bool
  120. *
  121. * Deletes a user
  122. */
  123. public function deleteUser( $uid ) {
  124. return false;
  125. }
  126. /**
  127. * Get a list of all users
  128. *
  129. * @param string $search
  130. * @param null|int $limit
  131. * @param null|int $offset
  132. * @return string[] an array of all uids
  133. */
  134. public function getUsers($search = '', $limit = null, $offset = null) {
  135. return array();
  136. }
  137. /**
  138. * check if a user exists
  139. * @param string $uid the username
  140. * @return boolean
  141. */
  142. public function userExists($uid) {
  143. return false;
  144. }
  145. /**
  146. * get the user's home directory
  147. * @param string $uid the username
  148. * @return boolean
  149. */
  150. public function getHome($uid) {
  151. return false;
  152. }
  153. /**
  154. * get display name of the user
  155. * @param string $uid user ID of the user
  156. * @return string display name
  157. */
  158. public function getDisplayName($uid) {
  159. return $uid;
  160. }
  161. /**
  162. * Get a list of all display names and user ids.
  163. *
  164. * @param string $search
  165. * @param string|null $limit
  166. * @param string|null $offset
  167. * @return array an array of all displayNames (value) and the corresponding uids (key)
  168. */
  169. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  170. $displayNames = array();
  171. $users = $this->getUsers($search, $limit, $offset);
  172. foreach ( $users as $user) {
  173. $displayNames[$user] = $user;
  174. }
  175. return $displayNames;
  176. }
  177. /**
  178. * Check if a user list is available or not
  179. * @return boolean if users can be listed or not
  180. */
  181. public function hasUserListings() {
  182. return false;
  183. }
  184. }