]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Authorization/AuthorizationPlugin.php
some formatting changes to make inblobs work
[quix0rs-gnu-social.git] / plugins / Authorization / 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  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
30     exit(1);
31 }
32
33 /**
34  * Superclass for plugins that do authorization
35  *
36  * @category Plugin
37  * @package  StatusNet
38  * @author   Craig Andrews <candrews@integralblue.com>
39  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40  * @link     http://status.net/
41  */
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     function onInitializePlugin(){
70
71     }
72
73     function onStartSetUser(&$user) {
74         $loginAllowed = $this->loginAllowed($user);
75         if($loginAllowed === true){
76             return;
77         }else if($loginAllowed === false){
78             $user = null;
79             return false;
80         }else{
81             if($this->authoritative) {
82                 $user = null;
83                 return false;
84             }else{
85                 return;
86             }
87         }
88     }
89
90     function onStartSetApiUser(&$user) {
91         return $this->onStartSetUser(&$user);
92     }
93
94     function onStartHasRole($profile, $name, &$has_role) {
95         if($this->hasRole($profile, $name)){
96             $has_role = true;
97             return false;
98         }else{
99             if($this->authoritative) {
100                 $has_role = false;
101                 return false;
102             }else{
103                 return;
104             }
105         }
106     }
107 }
108