backend.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Dominik Schmidt
  7. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  8. * @copyright 2011 Dominik Schmidt dev@dominik-schmidt.de
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library 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
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * error code for functions not provided by the user backend
  26. */
  27. define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
  28. /**
  29. * actions that user backends can define
  30. */
  31. define('OC_USER_BACKEND_CREATE_USER', 0x000001);
  32. define('OC_USER_BACKEND_DELETE_USER', 0x000010);
  33. define('OC_USER_BACKEND_SET_PASSWORD', 0x000100);
  34. define('OC_USER_BACKEND_CHECK_PASSWORD', 0x001000);
  35. define('OC_USER_BACKEND_GET_USERS', 0x010000);
  36. define('OC_USER_BACKEND_USER_EXISTS', 0x100000);
  37. /**
  38. * abstract base class for user management
  39. * subclass this for your own backends and see OC_User_Example for descriptions
  40. */
  41. abstract class OC_User_Backend {
  42. protected $possibleActions = array(
  43. OC_USER_BACKEND_CREATE_USER => 'createUser',
  44. OC_USER_BACKEND_DELETE_USER => 'deleteUser',
  45. OC_USER_BACKEND_SET_PASSWORD => 'setPassword',
  46. OC_USER_BACKEND_CHECK_PASSWORD => 'checkPassword',
  47. OC_USER_BACKEND_GET_USERS => 'getUsers',
  48. OC_USER_BACKEND_USER_EXISTS => 'userExists'
  49. );
  50. /**
  51. * @brief Get all supported actions
  52. * @returns bitwise-or'ed actions
  53. *
  54. * Returns the supported actions as int to be
  55. * compared with OC_USER_BACKEND_CREATE_USER etc.
  56. */
  57. public function getSupportedActions(){
  58. $actions = 0;
  59. foreach($this->possibleActions AS $action => $methodName){
  60. if(method_exists($this, $methodName)) {
  61. $actions |= $action;
  62. }
  63. }
  64. return $actions;
  65. }
  66. /**
  67. * @brief Check if backend implements actions
  68. * @param $actions bitwise-or'ed actions
  69. * @returns boolean
  70. *
  71. * Returns the supported actions as int to be
  72. * compared with OC_USER_BACKEND_CREATE_USER etc.
  73. */
  74. public function implementsActions($actions){
  75. return (bool)($this->getSupportedActions() & $actions);
  76. }
  77. }