2009-12-22 22:53:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Plugin to enable Single Sign On via CAS (Central Authentication Service)
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Plugin
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
2010-05-27 23:26:47 +01:00
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
2009-12-22 22:53:24 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We bundle the phpCAS library...
|
|
|
|
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/CAS');
|
|
|
|
|
|
|
|
class CasAuthenticationPlugin extends AuthenticationPlugin
|
|
|
|
{
|
|
|
|
public $server;
|
|
|
|
public $port = 443;
|
|
|
|
public $path = '';
|
2010-01-04 19:43:05 +00:00
|
|
|
public $takeOverLogin = false;
|
2009-12-22 22:53:24 +00:00
|
|
|
|
|
|
|
function checkPassword($username, $password)
|
|
|
|
{
|
|
|
|
global $casTempPassword;
|
|
|
|
return ($casTempPassword == $password);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAutoload($cls)
|
|
|
|
{
|
|
|
|
switch ($cls)
|
|
|
|
{
|
|
|
|
case 'phpCAS':
|
|
|
|
require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-28 14:54:26 +01:00
|
|
|
|
|
|
|
// if it's not our exception, try standard places
|
|
|
|
return parent::onAutoload($cls);
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 19:43:05 +00:00
|
|
|
function onArgsInitialize(&$args)
|
|
|
|
{
|
|
|
|
if($this->takeOverLogin && $args['action'] == 'login')
|
|
|
|
{
|
|
|
|
$args['action'] = 'caslogin';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-22 22:53:24 +00:00
|
|
|
function onStartInitializeRouter($m)
|
|
|
|
{
|
|
|
|
$m->connect('main/cas', array('action' => 'caslogin'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-18 20:34:27 +00:00
|
|
|
function onEndLoginGroupNav($action)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
|
|
|
$action->menuItem(common_local_url('caslogin'),
|
2010-09-18 13:31:03 +01:00
|
|
|
// TRANS: Menu item. CAS is Central Authentication Service.
|
2009-12-22 22:53:24 +00:00
|
|
|
_m('CAS'),
|
2010-09-18 13:31:03 +01:00
|
|
|
// TRANS: Tooltip for menu item. CAS is Central Authentication Service.
|
|
|
|
_m('Login or register with CAS.'),
|
2009-12-22 22:53:24 +00:00
|
|
|
$action_name === 'caslogin');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndShowPageNotice($action)
|
|
|
|
{
|
|
|
|
$name = $action->trimmed('action');
|
|
|
|
|
|
|
|
switch ($name)
|
|
|
|
{
|
|
|
|
case 'login':
|
2010-09-18 13:31:03 +01:00
|
|
|
// TRANS: Invitation to users with a CAS account to log in using the service.
|
|
|
|
// TRANS: "[CAS login]" is a link description. (%%action.caslogin%%) is the URL.
|
|
|
|
// TRANS: These two elements may not be separated.
|
|
|
|
$instr = _m('(Have an account with CAS? ' .
|
|
|
|
'Try our [CAS login](%%action.caslogin%%)!)');
|
2009-12-22 22:53:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
$action->raw($output);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginAction($action, &$login)
|
|
|
|
{
|
|
|
|
switch ($action)
|
|
|
|
{
|
|
|
|
case 'caslogin':
|
|
|
|
$login = true;
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInitializePlugin(){
|
|
|
|
parent::onInitializePlugin();
|
|
|
|
if(!isset($this->server)){
|
2011-04-06 17:46:55 +01:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-25 20:10:36 +01:00
|
|
|
throw new Exception(_m("Specifying a server is required."));
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
if(!isset($this->port)){
|
2011-04-06 17:46:55 +01:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-25 20:10:36 +01:00
|
|
|
throw new Exception(_m("Specifying a port is required."));
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
if(!isset($this->path)){
|
2011-04-06 17:46:55 +01:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-25 20:10:36 +01:00
|
|
|
throw new Exception(_m("Specifying a path is required."));
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
//These values need to be accessible to a action object
|
|
|
|
//I can't think of any other way than global variables
|
|
|
|
//to allow the action instance to be able to see values :-(
|
|
|
|
global $casSettings;
|
|
|
|
$casSettings = array();
|
|
|
|
$casSettings['server']=$this->server;
|
|
|
|
$casSettings['port']=$this->port;
|
|
|
|
$casSettings['path']=$this->path;
|
2010-03-02 20:09:28 +00:00
|
|
|
$casSettings['takeOverLogin']=$this->takeOverLogin;
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
2010-01-09 23:58:40 +00:00
|
|
|
|
|
|
|
function onPluginVersion(&$versions)
|
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CAS Authentication',
|
|
|
|
'version' => STATUSNET_VERSION,
|
|
|
|
'author' => 'Craig Andrews',
|
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:CasAuthentication',
|
2010-09-18 13:31:03 +01:00
|
|
|
// TRANS: Plugin description. CAS is Central Authentication Service.
|
|
|
|
'rawdescription' => _m('The CAS Authentication plugin allows for StatusNet to handle authentication through CAS (Central Authentication Service).'));
|
2010-01-09 23:58:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|