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;
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');
59 // if it's not our exception, try standard places
60 return parent::onAutoload($cls);
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'),
82 // TRANS: Menu item. CAS is Central Authentication Service.
84 // TRANS: Tooltip for menu item. CAS is Central Authentication Service.
85 _m('Login or register with CAS.'),
86 $action_name === 'caslogin');
91 function onEndShowPageNotice($action)
93 $name = $action->trimmed('action');
98 // TRANS: Invitation to users with a CAS account to log in using the service.
99 // TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
100 // TRANS: These two elements may not be separated.
101 $instr = _m('(Have an account with CAS? ' .
102 'Try our [CAS login](%%action.caslogin%%)!)');
108 $output = common_markup_to_html($instr);
109 $action->raw($output);
113 function onLoginAction($action, &$login)
125 function onInitializePlugin(){
126 parent::onInitializePlugin();
127 if(!isset($this->server)){
128 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
129 throw new Exception(_m("Specifying a server is required."));
131 if(!isset($this->port)){
132 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
133 throw new Exception(_m("Specifying a port is required."));
135 if(!isset($this->path)){
136 // TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
137 throw new Exception(_m("Specifying a path is required."));
139 //These values need to be accessible to a action object
140 //I can't think of any other way than global variables
141 //to allow the action instance to be able to see values :-(
143 $casSettings = array();
144 $casSettings['server']=$this->server;
145 $casSettings['port']=$this->port;
146 $casSettings['path']=$this->path;
147 $casSettings['takeOverLogin']=$this->takeOverLogin;
150 function onPluginVersion(&$versions)
152 $versions[] = array('name' => 'CAS Authentication',
153 'version' => GNUSOCIAL_VERSION,
154 'author' => 'Craig Andrews',
155 'homepage' => 'http://status.net/wiki/Plugin:CasAuthentication',
156 // TRANS: Plugin description. CAS is Central Authentication Service.
157 'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));