Backend.php 4.0 KB

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