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
42 public $takeOverLogin = false;
44 function checkPassword($username, $password)
46 global $casTempPassword;
47 return ($casTempPassword == $password);
50 function onAutoload($cls)
55 require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
57 case 'CasloginAction':
58 require_once(INSTALLDIR.'/plugins/CasAuthentication/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
63 function onArgsInitialize(&$args)
65 if($this->takeOverLogin && $args['action'] == 'login')
67 $args['action'] = 'caslogin';
71 function onStartInitializeRouter($m)
73 $m->connect('main/cas', array('action' => 'caslogin'));
77 function onEndLoginGroupNav(&$action)
79 $action_name = $action->trimmed('action');
81 $action->menuItem(common_local_url('caslogin'),
83 _m('Login or register with CAS'),
84 $action_name === 'caslogin');
89 function onEndShowPageNotice($action)
91 $name = $action->trimmed('action');
96 $instr = '(Have an account with CAS? ' .
97 'Try our [CAS login]'.
98 '(%%action.caslogin%%)!)';
104 $output = common_markup_to_html($instr);
105 $action->raw($output);
109 function onLoginAction($action, &$login)
121 function onInitializePlugin(){
122 parent::onInitializePlugin();
123 if(!isset($this->server)){
124 throw new Exception("must specify a server");
126 if(!isset($this->port)){
127 throw new Exception("must specify a port");
129 if(!isset($this->path)){
130 throw new Exception("must specify a path");
132 //These values need to be accessible to a action object
133 //I can't think of any other way than global variables
134 //to allow the action instance to be able to see values :-(
136 $casSettings = array();
137 $casSettings['server']=$this->server;
138 $casSettings['port']=$this->port;
139 $casSettings['path']=$this->path;
142 function onPluginVersion(&$versions)
144 $versions[] = array('name' => 'CAS Authentication',
145 'version' => STATUSNET_VERSION,
146 'author' => 'Craig Andrews',
147 'homepage' => 'http://status.net/wiki/Plugin:CasAuthentication',
149 _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));