3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to enable Single Sign On via CAS (Central Authentication Service)
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 // We bundle the phpCAS library...
35 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/CAS');
37 class CasAuthenticationPlugin extends AuthenticationPlugin
43 function checkPassword($username, $password)
45 global $casTempPassword;
46 return ($casTempPassword == $password);
49 function onAutoload($cls)
54 require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
56 case 'CasloginAction':
57 require_once(INSTALLDIR.'/plugins/CasAuthentication/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
60 return parent::onAutoload($cls);
64 function onStartInitializeRouter($m)
66 $m->connect('main/cas', array('action' => 'caslogin'));
70 function onEndLoginGroupNav(&$action)
72 $action_name = $action->trimmed('action');
74 $action->menuItem(common_local_url('caslogin'),
76 _m('Login or register with CAS'),
77 $action_name === 'caslogin');
82 function onEndShowPageNotice($action)
84 $name = $action->trimmed('action');
89 $instr = '(Have an account with CAS? ' .
90 'Try our [CAS login]'.
91 '(%%action.caslogin%%)!)';
97 $output = common_markup_to_html($instr);
98 $action->raw($output);
102 function onLoginAction($action, &$login)
114 function onInitializePlugin(){
115 parent::onInitializePlugin();
116 if(!isset($this->server)){
117 throw new Exception("must specify a server");
119 if(!isset($this->port)){
120 throw new Exception("must specify a port");
122 if(!isset($this->path)){
123 throw new Exception("must specify a path");
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 :-(
129 $casSettings = array();
130 $casSettings['server']=$this->server;
131 $casSettings['port']=$this->port;
132 $casSettings['path']=$this->path;