AuthorizationPlugin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Superclass for plugins that do authorization
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  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
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Plugin
  23. * @package StatusNet
  24. * @author Craig Andrews <candrews@integralblue.com>
  25. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Superclass for plugins that do authorization
  34. *
  35. * @category Module
  36. * @package GNUsocial
  37. * @author Craig Andrews <candrews@integralblue.com>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. abstract class AuthorizationPlugin extends Plugin
  42. {
  43. public $widgetOpts;
  44. public $scoped;
  45. //is this plugin authoritative for authorization?
  46. public $authoritative = false;
  47. //------------Auth plugin should implement some (or all) of these methods------------\\
  48. /**
  49. * Is a user allowed to log in?
  50. * @param user
  51. * @return boolean true if the user is allowed to login, false if explicitly not allowed to login, null if we don't explicitly allow or deny login
  52. */
  53. function loginAllowed($user) {
  54. return null;
  55. }
  56. /**
  57. * Does a profile grant the user a named role?
  58. * @param profile
  59. * @return boolean true if the profile has the role, false if not
  60. */
  61. function hasRole($profile, $name) {
  62. return false;
  63. }
  64. //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\
  65. function onStartSetUser($user) {
  66. $loginAllowed = $this->loginAllowed($user);
  67. if($loginAllowed === true){
  68. return;
  69. }else if($loginAllowed === false){
  70. $user = null;
  71. return false;
  72. }else{
  73. if($this->authoritative) {
  74. $user = null;
  75. return false;
  76. }else{
  77. return;
  78. }
  79. }
  80. }
  81. function onStartSetApiUser($user) {
  82. return $this->onStartSetUser($user);
  83. }
  84. function onStartHasRole($profile, $name, &$has_role) {
  85. if($this->hasRole($profile, $name)){
  86. $has_role = true;
  87. return false;
  88. }else{
  89. if($this->authoritative) {
  90. $has_role = false;
  91. return false;
  92. }else{
  93. return;
  94. }
  95. }
  96. }
  97. }