]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/authorizationplugin.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / authorizationplugin.php
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
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Superclass for plugins that do authorization
36  *
37  * @category Plugin
38  * @package  StatusNet
39  * @author   Craig Andrews <candrews@integralblue.com>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 abstract class AuthorizationPlugin extends Plugin
44 {
45     //is this plugin authoritative for authorization?
46     public $authoritative = false;
47
48     //------------Auth plugin should implement some (or all) of these methods------------\\
49
50     /**
51     * Is a user allowed to log in?
52     * @param user
53     * @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
54     */
55     function loginAllowed($user) {
56         return null;
57     }
58
59     /**
60     * Does a profile grant the user a named role?
61     * @param profile
62     * @return boolean true if the profile has the role, false if not
63     */
64     function hasRole($profile, $name) {
65         return false;
66     }
67
68     //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\
69
70     function onStartSetUser($user) {
71         $loginAllowed = $this->loginAllowed($user);
72         if($loginAllowed === true){
73             return;
74         }else if($loginAllowed === false){
75             $user = null;
76             return false;
77         }else{
78             if($this->authoritative) {
79                 $user = null;
80                 return false;
81             }else{
82                 return;
83             }
84         }
85     }
86
87     function onStartSetApiUser($user) {
88         return $this->onStartSetUser($user);
89     }
90
91     function onStartHasRole($profile, $name, &$has_role) {
92         if($this->hasRole($profile, $name)){
93             $has_role = true;
94             return false;
95         }else{
96             if($this->authoritative) {
97                 $has_role = false;
98                 return false;
99             }else{
100                 return;
101             }
102         }
103     }
104 }