2009-12-22 22:53:24 +00:00
|
|
|
<?php
|
2019-11-01 11:19:42 +00:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-12-22 22:53:24 +00:00
|
|
|
/**
|
|
|
|
* Plugin to enable Single Sign On via CAS (Central Authentication Service)
|
|
|
|
*
|
|
|
|
* @category Plugin
|
2019-11-01 11:19:42 +00:00
|
|
|
* @package GNUsocial
|
2009-12-22 22:53:24 +00:00
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
2010-05-27 23:26:47 +01:00
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
2019-11-01 11:19:42 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-12-22 22:53:24 +00:00
|
|
|
*/
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
defined('GNUSOCIAL') || die();
|
2009-12-22 22:53:24 +00:00
|
|
|
|
|
|
|
class CasAuthenticationPlugin extends AuthenticationPlugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2009-12-22 22:53:24 +00:00
|
|
|
public $server;
|
|
|
|
public $port = 443;
|
|
|
|
public $path = '';
|
2010-01-04 19:43:05 +00:00
|
|
|
public $takeOverLogin = false;
|
2017-04-17 17:34:25 +01:00
|
|
|
public $user_whitelist = null;
|
2009-12-22 22:53:24 +00:00
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function checkPassword($username, $password)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
|
|
|
global $casTempPassword;
|
|
|
|
return ($casTempPassword == $password);
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onArgsInitialize(&$args)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
2019-11-01 11:19:42 +00:00
|
|
|
if ($this->takeOverLogin && $args['action'] === 'login') {
|
2010-01-04 19:43:05 +00:00
|
|
|
$args['action'] = 'caslogin';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onStartInitializeRouter($m)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
|
|
|
$m->connect('main/cas', array('action' => 'caslogin'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onEndLoginGroupNav($action)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
$action->menuItem(
|
|
|
|
common_local_url('caslogin'),
|
|
|
|
// TRANS: Menu item. CAS is Central Authentication Service.
|
|
|
|
_m('CAS'),
|
|
|
|
// TRANS: Tooltip for menu item. CAS is Central Authentication Service.
|
|
|
|
_m('Login or register with CAS.'),
|
|
|
|
($action_name === 'caslogin')
|
|
|
|
);
|
2009-12-22 22:53:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onEndShowPageNotice($action)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
|
|
|
$name = $action->trimmed('action');
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
switch ($name) {
|
|
|
|
case 'login':
|
|
|
|
// 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%%)!)');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
$action->raw($output);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onLoginAction($action, &$login)
|
2009-12-22 22:53:24 +00:00
|
|
|
{
|
2019-11-01 11:19:42 +00:00
|
|
|
switch ($action) {
|
|
|
|
case 'caslogin':
|
|
|
|
$login = true;
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:19:42 +00:00
|
|
|
public function onInitializePlugin()
|
|
|
|
{
|
2009-12-22 22:53:24 +00:00
|
|
|
parent::onInitializePlugin();
|
2019-11-01 11:19:42 +00:00
|
|
|
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
|
|
|
}
|
2019-11-01 11:19:42 +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
|
|
|
}
|
2019-11-01 11:19:42 +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;
|
2017-04-17 17:34:25 +01:00
|
|
|
$casSettings['user_whitelist']=$this->user_whitelist;
|
2009-12-22 22:53:24 +00:00
|
|
|
}
|
2010-01-09 23:58:40 +00:00
|
|
|
|
2019-08-12 15:03:30 +01:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2010-01-09 23:58:40 +00:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'CAS Authentication',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-01-09 23:58:40 +00:00
|
|
|
'author' => 'Craig Andrews',
|
2019-11-21 00:21:22 +00:00
|
|
|
'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/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
|
|
|
}
|