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