Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/support/2.7' into support/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Goiffon committed Nov 24, 2022
2 parents feafd5e + e9c91d9 commit df4a205
Show file tree
Hide file tree
Showing 73 changed files with 2,686 additions and 673 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -131,7 +131,7 @@ Our tests are located in the `test/` directory, containing a PHPUnit config file

When your code is working, please:

* stash as much as possible your commits,
* squash as much as possible your commits,
* rebase your branch on our repo last commit,
* create a pull request.

Expand Down
14 changes: 11 additions & 3 deletions datamodels/2.x/authent-cas/composer.json
@@ -1,5 +1,13 @@
{
"require" : {
"apereo/phpcas" : "~1.3"
}
"config" : {
"classmap-authoritative" : true
},
"autoload" : {
"psr-4" : {
"Combodo\\iTop\\Cas\\" : "src"
}
},
"require" : {
"apereo/phpcas" : "~1.6.0"
}
}
86 changes: 75 additions & 11 deletions datamodels/2.x/authent-cas/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions datamodels/2.x/authent-cas/main.php

This file was deleted.

4 changes: 3 additions & 1 deletion datamodels/2.x/authent-cas/module.authent-cas.php
Expand Up @@ -24,7 +24,8 @@
//
'datamodel' => array(
'model.authent-cas.php',
'main.php'
'vendor/autoload.php',
'src/CASLoginExtension.php',
),
'webservice' => array(

Expand All @@ -50,6 +51,7 @@
'cas_port' => '',
'cas_context' => '',
'cas_version' => '',
'service_base_url' => '',
),
)
);
17 changes: 17 additions & 0 deletions datamodels/2.x/authent-cas/src/CASLog.php
@@ -0,0 +1,17 @@
<?php
/**
* @copyright Copyright (C) 2010-2022 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/

namespace Combodo\iTop\Cas;

use LogAPI;

class CASLog extends LogAPI
{
const CHANNEL_DEFAULT = 'CASLog';

protected static $m_oFileLog = null;
}

81 changes: 81 additions & 0 deletions datamodels/2.x/authent-cas/src/CASLogger.php
@@ -0,0 +1,81 @@
<?php
/**
* @copyright Copyright (C) 2010-2022 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/

namespace Combodo\iTop\Cas;

use IssueLog;
use LogAPI;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

class CASLogger implements LoggerInterface
{
public function __construct($sDebugFile)
{
CASLog::Enable($sDebugFile);
}

const LEVEL_COMPAT = [
LogLevel::EMERGENCY => LogAPI::LEVEL_ERROR,
LogLevel::ALERT => LogAPI::LEVEL_ERROR,
LogLevel::CRITICAL => LogAPI::LEVEL_ERROR,
LogLevel::ERROR => LogAPI::LEVEL_ERROR,
LogLevel::WARNING => LogAPI::LEVEL_WARNING,
LogLevel::NOTICE => LogAPI::LEVEL_INFO,
LogLevel::INFO => LogAPI::LEVEL_INFO,
LogLevel::DEBUG => LogAPI::LEVEL_DEBUG,
];

public function emergency($message, array $context = array())
{
CASLog::Error('EMERGENCY: '.$message, CASLog::CHANNEL_DEFAULT, $context);
IssueLog::Error('EMERGENCY: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function alert($message, array $context = array())
{
CASLog::Error('ALERT: '.$message, CASLog::CHANNEL_DEFAULT, $context);
IssueLog::Error('ALERT: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function critical($message, array $context = array())
{
CASLog::Error('CRITICAL: '.$message, CASLog::CHANNEL_DEFAULT, $context);
IssueLog::Error('CRITICAL: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function error($message, array $context = array())
{
CASLog::Error('ERROR: '.$message, CASLog::CHANNEL_DEFAULT, $context);
IssueLog::Error('ERROR: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function warning($message, array $context = array())
{
CASLog::Warning('WARNING: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function notice($message, array $context = array())
{
CASLog::Info('NOTICE: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function info($message, array $context = array())
{
CASLog::Info('INFO: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function debug($message, array $context = array())
{
CASLog::Debug('DEBUG: '.$message, CASLog::CHANNEL_DEFAULT, $context);
}

public function log($level, $message, array $context = array())
{
$sLevel = self::LEVEL_COMPAT[$level] ?? LogAPI::LEVEL_ERROR;
CASLog::Log($sLevel, strtoupper($level).": $message", CASLog::CHANNEL_DEFAULT, $context);
}
}
37 changes: 35 additions & 2 deletions datamodels/2.x/authent-cas/src/CASLoginExtension.php
Expand Up @@ -153,15 +153,16 @@ private static function InitCASClient()
$bCASDebug = Config::Get('cas_debug');
if ($bCASDebug)
{
phpCAS::setDebug(APPROOT.'log/cas.log');
phpCAS::setLogger(new CASLogger(APPROOT.'log/cas.log'));
}

// Initialize phpCAS
$sCASVersion = Config::Get('cas_version');
$sCASHost = Config::Get('cas_host');
$iCASPort = Config::Get('cas_port');
$sCASContext = Config::Get('cas_context');
phpCAS::client($sCASVersion, $sCASHost, $iCASPort, $sCASContext, false /* session already started */);
$sServiceBaseURL = Config::Get('service_base_url', self::GetServiceBaseURL());
phpCAS::client($sCASVersion, $sCASHost, $iCASPort, $sCASContext, $sServiceBaseURL, false /* session already started */);
$sCASCACertPath = Config::Get('cas_server_ca_cert_path');
if (empty($sCASCACertPath))
{
Expand All @@ -177,6 +178,38 @@ private static function InitCASClient()
}
}

private static function GetServiceBaseURL()
{
$protocol = $_SERVER['REQUEST_SCHEME'];
$protocol .= '://';
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
// explode the host list separated by comma and use the first host
$hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_HOST']);
// see rfc7239#5.3 and rfc7230#2.7.1: port is in HTTP_X_FORWARDED_HOST if non default
return $protocol . $hosts[0];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
$server_url = $_SERVER['HTTP_X_FORWARDED_SERVER'];
} else {
if (empty($_SERVER['SERVER_NAME'])) {
$server_url = $_SERVER['HTTP_HOST'];
} else {
$server_url = $_SERVER['SERVER_NAME'];
}
}
if (!strpos($server_url, ':')) {
if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
$server_port = $_SERVER['SERVER_PORT'];
} else {
$ports = explode(',', $_SERVER['HTTP_X_FORWARDED_PORT']);
$server_port = $ports[0];
}

$server_url .= ':';
$server_url .= $server_port;
}
return $protocol . $server_url;
}

private function DoUserProvisioning($sLogin)
{
$bCASUserSynchro = Config::Get('cas_user_synchro');
Expand Down
6 changes: 4 additions & 2 deletions datamodels/2.x/authent-cas/vendor/apereo/phpcas/CAS.php
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP Version 5
* PHP Version 7
*
* @file CAS.php
* @category Authentication
Expand All @@ -27,4 +27,6 @@
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/

require_once dirname(__FILE__).'/source/CAS.php';
require_once __DIR__.'/source/CAS.php';

trigger_error('Including CAS.php is deprecated. Install phpCAS using composer instead.', E_USER_DEPRECATED);
13 changes: 6 additions & 7 deletions datamodels/2.x/authent-cas/vendor/apereo/phpcas/README.md
Expand Up @@ -6,22 +6,21 @@ users via a Central Authentication Service (CAS) server.

Please see the wiki website for more information:

https://wiki.jasig.org/display/CASC/phpCAS
https://apereo.github.io/phpCAS/

Api documentation can be found here:

https://apereo.github.io/phpCAS/

https://apereo.github.io/phpCAS/api/

[![Build Status](https://travis-ci.org/apereo/phpCAS.png)](https://travis-ci.org/apereo/phpCAS)

[![Test](https://github.com/apereo/phpCAS/actions/workflows/test.yml/badge.svg)](https://github.com/apereo/phpCAS/actions/workflows/test.yml)

LICENSE
-------

Copyright 2007-2015, JA-SIG, Inc.
This project includes software developed by Jasig.
http://www.jasig.org/
Copyright 2007-2020, Apereo Foundation.
This project includes software developed by Apereo Foundation.
http://www.apereo.org/

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
Expand Down

0 comments on commit df4a205

Please sign in to comment.