2009-12-23 07:53:24 +09: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-28 07:26:47 +09:00
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
2009-12-23 07:53:24 +09: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-05 04:43:05 +09:00
|
|
|
public $takeOverLogin = false;
|
2017-04-18 01:34:25 +09:00
|
|
|
public $user_whitelist = null;
|
2009-12-23 07:53:24 +09: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 22:54:26 +09:00
|
|
|
|
|
|
|
// if it's not our exception, try standard places
|
|
|
|
return parent::onAutoload($cls);
|
2009-12-23 07:53:24 +09:00
|
|
|
}
|
|
|
|
|
2010-01-05 04:43:05 +09:00
|
|
|
function onArgsInitialize(&$args)
|
|
|
|
{
|
|
|
|
if($this->takeOverLogin && $args['action'] == 'login')
|
|
|
|
{
|
|
|
|
$args['action'] = 'caslogin';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-23 07:53:24 +09:00
|
|
|
function onStartInitializeRouter($m)
|
|
|
|
{
|
|
|
|
$m->connect('main/cas', array('action' => 'caslogin'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-19 05:34:27 +09:00
|
|
|
function onEndLoginGroupNav($action)
|
2009-12-23 07:53:24 +09:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
|
|
|
$action->menuItem(common_local_url('caslogin'),
|
2010-09-18 21:31:03 +09:00
|
|
|
// TRANS: Menu item. CAS is Central Authentication Service.
|
2009-12-23 07:53:24 +09:00
|
|
|
_m('CAS'),
|
2010-09-18 21:31:03 +09:00
|
|
|
// TRANS: Tooltip for menu item. CAS is Central Authentication Service.
|
|
|
|
_m('Login or register with CAS.'),
|
2009-12-23 07:53:24 +09:00
|
|
|
$action_name === 'caslogin');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEndShowPageNotice($action)
|
|
|
|
{
|
|
|
|
$name = $action->trimmed('action');
|
|
|
|
|
|
|
|
switch ($name)
|
|
|
|
{
|
|
|
|
case 'login':
|
2010-09-18 21:31:03 +09: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-23 07:53:24 +09: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-07 01:46:55 +09:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-26 04:10:36 +09:00
|
|
|
throw new Exception(_m("Specifying a server is required."));
|
2009-12-23 07:53:24 +09:00
|
|
|
}
|
|
|
|
if(!isset($this->port)){
|
2011-04-07 01:46:55 +09:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-26 04:10:36 +09:00
|
|
|
throw new Exception(_m("Specifying a port is required."));
|
2009-12-23 07:53:24 +09:00
|
|
|
}
|
|
|
|
if(!isset($this->path)){
|
2011-04-07 01:46:55 +09:00
|
|
|
// TRANS: Exception thrown when the CAS Authentication plugin has been configured incorrectly.
|
2010-09-26 04:10:36 +09:00
|
|
|
throw new Exception(_m("Specifying a path is required."));
|
2009-12-23 07:53:24 +09: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-03 05:09:28 +09:00
|
|
|
$casSettings['takeOverLogin']=$this->takeOverLogin;
|
2017-04-18 01:34:25 +09:00
|
|
|
$casSettings['user_whitelist']=$this->user_whitelist;
|
2009-12-23 07:53:24 +09:00
|
|
|
}
|
2010-01-10 08:58:40 +09:00
|
|
|
|
2015-06-07 05:04:01 +09:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-01-10 08:58:40 +09:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CAS Authentication',
|
2013-11-01 21:51:41 +09:00
|
|
|
'version' => GNUSOCIAL_VERSION,
|
2010-01-10 08:58:40 +09:00
|
|
|
'author' => 'Craig Andrews',
|
2016-01-23 01:38:42 +09:00
|
|
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/CasAuthentication',
|
2010-09-18 21:31:03 +09: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-10 08:58:40 +09:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-23 07:53:24 +09:00
|
|
|
}
|