backend.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * @author Aldo "xoen" Giambelluca <xoen@xoen.org>
  4. * @author Arthur Schiwon <blizzz@owncloud.com>
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Björn Schießle <schiessle@owncloud.com>
  7. * @author Dominik Schmidt <dev@dominik-schmidt.de>
  8. * @author Georg Ehrke <georg@owncloud.com>
  9. * @author Jakob Sack <mail@jakobsack.de>
  10. * @author Joas Schilling <nickvergessen@owncloud.com>
  11. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <icewind@owncloud.com>
  14. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  15. * @author Sam Tuke <mail@samtuke.com>
  16. * @author Thomas Müller <thomas.mueller@tmit.eu>
  17. * @author Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  18. *
  19. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 OC_User_Interface {
  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. * @return array an array of all uids
  129. *
  130. * Get a list of all users.
  131. */
  132. public function getUsers($search = '', $limit = null, $offset = null) {
  133. return array();
  134. }
  135. /**
  136. * check if a user exists
  137. * @param string $uid the username
  138. * @return boolean
  139. */
  140. public function userExists($uid) {
  141. return false;
  142. }
  143. /**
  144. * get the user's home directory
  145. * @param string $uid the username
  146. * @return boolean
  147. */
  148. public function getHome($uid) {
  149. return false;
  150. }
  151. /**
  152. * get display name of the user
  153. * @param string $uid user ID of the user
  154. * @return string display name
  155. */
  156. public function getDisplayName($uid) {
  157. return $uid;
  158. }
  159. /**
  160. * Get a list of all display names
  161. * @return array an array of all displayNames (value) and the corresponding uids (key)
  162. *
  163. * Get a list of all display names and user ids.
  164. */
  165. public function getDisplayNames($search = '', $limit = null, $offset = null) {
  166. $displayNames = array();
  167. $users = $this->getUsers($search, $limit, $offset);
  168. foreach ( $users as $user) {
  169. $displayNames[$user] = $user;
  170. }
  171. return $displayNames;
  172. }
  173. /**
  174. * Check if a user list is available or not
  175. * @return boolean if users can be listed or not
  176. */
  177. public function hasUserListings() {
  178. return false;
  179. }
  180. }