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
42 public $takeOverLogin = false;
43 public $user_whitelist = null;
45 function checkPassword($username, $password)
47 global $casTempPassword;
48 return ($casTempPassword == $password);
51 function onAutoload($cls)
56 require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
60 // if it's not our exception, try standard places
61 return parent::onAutoload($cls);
64 function onArgsInitialize(&$args)
66 if($this->takeOverLogin && $args['action'] == 'login')
68 $args['action'] = 'caslogin';
72 function onStartInitializeRouter($m)
74 $m->connect('main/cas', array('action' => 'caslogin'));
78 function onEndLoginGroupNav($action)
80 $action_name = $action->trimmed('action');
82 $action->menuItem(common_local_url('caslogin'),
83 // TRANS: Menu item. CAS is Central Authentication Service.
85 // TRANS: Tooltip for menu item. CAS is Central Authentication Service.
86 _m('Login or register with CAS.'),
87 $action_name === 'caslogin');
92 function onEndShowPageNotice($action)
94 $name = $action->trimmed('action');
99 // TRANS: Invitation to users with a CAS account to log in using the service.
100 // TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
101 // TRANS: These two elements may not be separated.
102 $instr = _m('(Have an account with CAS? ' .
103 'Try our [CAS login](%%action.caslogin%%)!)');
109 $output = common_markup_to_html($instr);
110 $action->raw($output);
114 function onLoginAction($action, &$login)
126 function onInitializePlugin(){
127 parent::onInitializePlugin();
128 if(!isset($this->server)){
129 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
130 throw new Exception(_m("Specifying a server is required."));
132 if(!isset($this->port)){
133 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
134 throw new Exception(_m("Specifying a port is required."));
136 if(!isset($this->path)){
137 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
138 throw new Exception(_m("Specifying a path is required."));
140 //These values need to be accessible to a action object
141 //I can't think of any other way than global variables
142 //to allow the action instance to be able to see values :-(
144 $casSettings = array();
145 $casSettings['server']=$this->server;
146 $casSettings['port']=$this->port;
147 $casSettings['path']=$this->path;
148 $casSettings['takeOverLogin']=$this->takeOverLogin;
149 $casSettings['user_whitelist']=$this->user_whitelist;
152 function onPluginVersion(array &$versions)
154 $versions[] = array('name' => 'CAS Authentication',
155 'version' => GNUSOCIAL_VERSION,
156 'author' => 'Craig Andrews',
157 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/CasAuthentication',
158 // TRANS: Plugin description. CAS is Central Authentication Service.
159 'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));