]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/authorizationplugin.php
Merge commit 'origin/0.9.x' into 0.9.x
[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
44 abstract class AuthorizationPlugin extends Plugin
45 {
46     //is this plugin authoritative for authorization?
47     public $authoritative = false;
48
49     //------------Auth plugin should implement some (or all) of these methods------------\\
50
51     /**
52     * Is a user allowed to log in?
53     * @param user
54     * @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
55     */
56     function loginAllowed($user) {
57         return null;
58     }
59
60     /**
61     * Does a profile grant the user a named role?
62     * @param profile
63     * @return boolean true if the profile has the role, false if not
64     */
65     function hasRole($profile, $name) {
66         return false;
67     }
68
69     //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\
70
71     function onStartSetUser($user) {
72         $loginAllowed = $this->loginAllowed($user);
73         if($loginAllowed === true){
74             return;
75         }else if($loginAllowed === false){
76             $user = null;
77             return false;
78         }else{
79             if($this->authoritative) {
80                 $user = null;
81                 return false;
82             }else{
83                 return;
84             }
85         }
86     }
87
88     function onStartSetApiUser($user) {
89         return $this->onStartSetUser($user);
90     }
91
92     function onStartHasRole($profile, $name, &$has_role) {
93         if($this->hasRole($profile, $name)){
94             $has_role = true;
95             return false;
96         }else{
97             if($this->authoritative) {
98                 $has_role = false;
99                 return false;
100             }else{
101                 return;
102             }
103         }
104     }
105 }
106