]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/CasAuthenticationPlugin.php
some formatting changes to make inblobs work
[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 Craig Andrews http://candrews.integralblue.com
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
43     function checkPassword($username, $password)
44     {
45         global $casTempPassword;
46         return ($casTempPassword == $password);
47     }
48
49     function onAutoload($cls)
50     {
51         switch ($cls)
52         {
53          case 'phpCAS':
54             require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
55             return false;
56          case 'CasloginAction':
57             require_once(INSTALLDIR.'/plugins/CasAuthentication/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
58             return false;
59          default:
60             return parent::onAutoload($cls);
61         }
62     }
63
64     function onStartInitializeRouter($m)
65     {
66         $m->connect('main/cas', array('action' => 'caslogin'));
67         return true;
68     }
69
70     function onEndLoginGroupNav(&$action)
71     {
72         $action_name = $action->trimmed('action');
73
74         $action->menuItem(common_local_url('caslogin'),
75                           _m('CAS'),
76                           _m('Login or register with CAS'),
77                           $action_name === 'caslogin');
78
79         return true;
80     }
81
82     function onEndShowPageNotice($action)
83     {
84         $name = $action->trimmed('action');
85
86         switch ($name)
87         {
88          case 'login':
89             $instr = '(Have an account with CAS? ' .
90               'Try our [CAS login]'.
91               '(%%action.caslogin%%)!)';
92             break;
93          default:
94             return true;
95         }
96
97         $output = common_markup_to_html($instr);
98         $action->raw($output);
99         return true;
100     }
101
102     function onLoginAction($action, &$login)
103     {
104         switch ($action)
105         {
106          case 'caslogin':
107             $login = true;
108             return false;
109          default:
110             return true;
111         }
112     }
113
114     function onInitializePlugin(){
115         parent::onInitializePlugin();
116         if(!isset($this->server)){
117             throw new Exception("must specify a server");
118         }
119         if(!isset($this->port)){
120             throw new Exception("must specify a port");
121         }
122         if(!isset($this->path)){
123             throw new Exception("must specify a path");
124         }
125         //These values need to be accessible to a action object
126         //I can't think of any other way than global variables
127         //to allow the action instance to be able to see values :-(
128         global $casSettings;
129         $casSettings = array();
130         $casSettings['server']=$this->server;
131         $casSettings['port']=$this->port;
132         $casSettings['path']=$this->path;
133     }
134 }