]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/CasAuthenticationPlugin.php
Fix wrong path on Realtime cleanupchannels script by XRevan86
[quix0rs-gnu-social.git] / plugins / CasAuthentication / CasAuthenticationPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to enable Single Sign On via CAS (Central Authentication Service)
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 // We bundle the phpCAS library...
35 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/CAS');
36
37 class CasAuthenticationPlugin extends AuthenticationPlugin
38 {
39     public $server;
40     public $port = 443;
41     public $path = '';
42     public $takeOverLogin = false;
43     public $user_whitelist = null;
44
45     function checkPassword($username, $password)
46     {
47         global $casTempPassword;
48         return ($casTempPassword == $password);
49     }
50
51     function onAutoload($cls)
52     {
53         switch ($cls)
54         {
55          case 'phpCAS':
56             require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
57             return false;
58         }
59
60         // if it's not our exception, try standard places
61         return parent::onAutoload($cls);
62     }
63
64     function onArgsInitialize(&$args)
65     {
66         if($this->takeOverLogin && $args['action'] == 'login')
67         {
68             $args['action'] = 'caslogin';
69         }
70     }
71
72     function onStartInitializeRouter($m)
73     {
74         $m->connect('main/cas', array('action' => 'caslogin'));
75         return true;
76     }
77
78     function onEndLoginGroupNav($action)
79     {
80         $action_name = $action->trimmed('action');
81
82         $action->menuItem(common_local_url('caslogin'),
83                           // TRANS: Menu item. CAS is Central Authentication Service.
84                           _m('CAS'),
85                           // TRANS: Tooltip for menu item. CAS is Central Authentication Service.
86                           _m('Login or register with CAS.'),
87                           $action_name === 'caslogin');
88
89         return true;
90     }
91
92     function onEndShowPageNotice($action)
93     {
94         $name = $action->trimmed('action');
95
96         switch ($name)
97         {
98          case 'login':
99             // TRANS: Invitation to users with a CAS account to log in using the service.
100             // TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
101             // TRANS: These two elements may not be separated.
102             $instr = _m('(Have an account with CAS? ' .
103               'Try our [CAS login](%%action.caslogin%%)!)');
104             break;
105          default:
106             return true;
107         }
108
109         $output = common_markup_to_html($instr);
110         $action->raw($output);
111         return true;
112     }
113
114     function onLoginAction($action, &$login)
115     {
116         switch ($action)
117         {
118          case 'caslogin':
119             $login = true;
120             return false;
121          default:
122             return true;
123         }
124     }
125
126     function onInitializePlugin(){
127         parent::onInitializePlugin();
128         if(!isset($this->server)){
129             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
130             throw new Exception(_m("Specifying a server is required."));
131         }
132         if(!isset($this->port)){
133             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
134             throw new Exception(_m("Specifying a port is required."));
135         }
136         if(!isset($this->path)){
137             // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
138             throw new Exception(_m("Specifying a path is required."));
139         }
140         //These values need to be accessible to a action object
141         //I can't think of any other way than global variables
142         //to allow the action instance to be able to see values :-(
143         global $casSettings;
144         $casSettings = array();
145         $casSettings['server']=$this->server;
146         $casSettings['port']=$this->port;
147         $casSettings['path']=$this->path;
148         $casSettings['takeOverLogin']=$this->takeOverLogin;
149         $casSettings['user_whitelist']=$this->user_whitelist;
150     }
151
152     function onPluginVersion(array &$versions)
153     {
154         $versions[] = array('name' => 'CAS Authentication',
155                             'version' => GNUSOCIAL_VERSION,
156                             'author' => 'Craig Andrews',
157                             'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/CasAuthentication',
158                             // TRANS: Plugin description. CAS is Central Authentication Service.
159                             'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));
160         return true;
161     }
162 }