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 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/
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
39 const PLUGIN_VERSION = '2.0.0';
44 public $takeOverLogin = false;
45 public $user_whitelist = null;
47 function checkPassword($username, $password)
49 global $casTempPassword;
50 return ($casTempPassword == $password);
53 function onAutoload($cls)
58 require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
62 // if it's not our exception, try standard places
63 return parent::onAutoload($cls);
66 function onArgsInitialize(&$args)
68 if($this->takeOverLogin && $args['action'] == 'login')
70 $args['action'] = 'caslogin';
74 function onStartInitializeRouter($m)
76 $m->connect('main/cas', array('action' => 'caslogin'));
80 function onEndLoginGroupNav($action)
82 $action_name = $action->trimmed('action');
84 $action->menuItem(common_local_url('caslogin'),
85 // TRANS: Menu item. CAS is Central Authentication Service.
87 // TRANS: Tooltip for menu item. CAS is Central Authentication Service.
88 _m('Login or register with CAS.'),
89 $action_name === 'caslogin');
94 function onEndShowPageNotice($action)
96 $name = $action->trimmed('action');
101 // TRANS: Invitation to users with a CAS account to log in using the service.
102 // TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
103 // TRANS: These two elements may not be separated.
104 $instr = _m('(Have an account with CAS? ' .
105 'Try our [CAS login](%%action.caslogin%%)!)');
111 $output = common_markup_to_html($instr);
112 $action->raw($output);
116 function onLoginAction($action, &$login)
128 function onInitializePlugin(){
129 parent::onInitializePlugin();
130 if(!isset($this->server)){
131 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
132 throw new Exception(_m("Specifying a server is required."));
134 if(!isset($this->port)){
135 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
136 throw new Exception(_m("Specifying a port is required."));
138 if(!isset($this->path)){
139 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
140 throw new Exception(_m("Specifying a path is required."));
142 //These values need to be accessible to a action object
143 //I can't think of any other way than global variables
144 //to allow the action instance to be able to see values :-(
146 $casSettings = array();
147 $casSettings['server']=$this->server;
148 $casSettings['port']=$this->port;
149 $casSettings['path']=$this->path;
150 $casSettings['takeOverLogin']=$this->takeOverLogin;
151 $casSettings['user_whitelist']=$this->user_whitelist;
154 function onPluginVersion(array &$versions)
156 $versions[] = array('name' => 'CAS Authentication',
157 'version' => self::PLUGIN_VERSION,
158 'author' => 'Craig Andrews',
159 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/CasAuthentication',
160 // TRANS: Plugin description. CAS is Central Authentication Service.
161 'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));