Skip to content
Snippets Groups Projects
Unverified Commit 222bf425 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Import saml2 container into ssp (#1442)

* Import the saml2 SspContainer into SSP

* Comment code targeted at saml2v5 for now
parent 0d61a9e5
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace SimpleSAML\Compat;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use SimpleSAML\Assert\Assert;
use SimpleSAML\Logger as SspLogger;
class Logger implements LoggerInterface
{
/**
* System is unusable.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function emergency($message, array $context = []): void
{
SspLogger::emergency($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function alert($message, array $context = []): void
{
SspLogger::alert($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function critical($message, array $context = []): void
{
SspLogger::critical($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function error($message, array $context = []): void
{
SspLogger::error($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function warning($message, array $context = []): void
{
SspLogger::warning($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function notice($message, array $context = []): void
{
SspLogger::notice($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function info($message, array $context = []): void
{
SspLogger::info($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
*
* Type hint not possible due to upstream method signature
*/
public function debug($message, array $context = []): void
{
SspLogger::debug($message . ($context ? " " . var_export($context, true) : ""));
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*
* @throws \SimpleSAML\Assert\AssertionFailedException if assertions are false
*
* Type hint not possible due to upstream method signature
*/
public function log($level, $message, array $context = []): void
{
Assert::string($message);
switch ($level) {
/* From PSR: Calling this method with one of the log level constants
* MUST have the same result as calling the level-specific method
*/
case LogLevel::ALERT:
$this->alert($message, $context);
break;
case LogLevel::CRITICAL:
$this->critical($message, $context);
break;
case LogLevel::DEBUG:
$this->debug($message, $context);
break;
case LogLevel::EMERGENCY:
$this->emergency($message, $context);
break;
case LogLevel::ERROR:
$this->error($message, $context);
break;
case LogLevel::INFO:
$this->info($message, $context);
break;
case LogLevel::NOTICE:
$this->notice($message, $context);
break;
case LogLevel::WARNING:
$this->warning($message, $context);
break;
default:
throw new InvalidArgumentException("Unrecognized log level '$level''");
}
}
}
<?php
declare(strict_types=1);
namespace SimpleSAML\Compat;
use Psr\Log\LoggerInterface;
use SAML2\Compat\AbstractContainer;
use SAML2\XML\saml\CustomIdentifierInterface;
use SimpleSAML\Assert\Assert;
use SimpleSAML\Utils\HTTP;
use SimpleSAML\Utils\Random;
use SimpleSAML\Utils\System;
use SimpleSAML\Utils\XML;
use SimpleSAML\XML\AbstractXMLElement;
class SspContainer extends AbstractContainer
{
/** @var \Psr\Log\LoggerInterface */
protected LoggerInterface $logger;
/** @var array */
protected array $registry = [];
/**
* Create a new SimpleSAMLphp compatible container.
*/
public function __construct()
{
$this->logger = new Logger();
}
/**
* {@inheritdoc}
* @return \Psr\Log\LoggerInterface
*/
public function getLogger(): LoggerInterface
{
return $this->logger;
}
/**
* {@inheritdoc}
* @return string
*/
public function generateId(): string
{
return Random::generateID();
}
/**
* {@inheritdoc}
* @param mixed $message
* @param string $type
*/
public function debugMessage($message, string $type): void
{
XML::debugSAMLMessage($message, $type);
}
/**
* {@inheritdoc}
* @param string $url
* @param array $data
*/
public function redirect(string $url, array $data = []): void
{
HTTP::redirectTrustedURL($url, $data);
}
/**
* {@inheritdoc}
* @param string $url
* @param array $data
*/
public function postRedirect(string $url, array $data = []): void
{
HTTP::submitPOSTData($url, $data);
}
/**
* {@inheritdoc}
* @return string
*/
public function getTempDir(): string
{
/** @psalm-suppress UndefinedClass */
return System::getTempDir();
}
/**
* {@inheritdoc}
* @param string $filename
* @param string $date
* @param int|null $mode
*/
public function writeFile(string $filename, string $data, int $mode = null): void
{
if ($mode === null) {
$mode = 0600;
}
System::writeFile($filename, $data, $mode);
}
/**
* @inheritDoc
public function registerExtensionHandler(string $class): void
{
Assert::subclassOf($class, AbstractXMLElement::class);
if (is_subclass_of($class, CustomIdentifierInterface::class, true)) {
$key = $class::getXsiType() . ':BaseID';
} else {
$key = join(':', [urlencode($class::NS), AbstractXMLElement::getClassName($class)]);
}
$this->registry[$key] = $class;
}
*/
/**
* @inheritDoc
public function getElementHandler(string $namespace, string $element): ?string
{
Assert::notEmpty($namespace, 'Cannot search for handlers without an associated namespace URI.');
Assert::notEmpty($element, 'Cannot search for handlers without an associated element name.');
return $this->registry[join(':', [urlencode($namespace), $element])];
}
*/
/**
* @inheritDoc
public function getIdentifierHandler(string $type): ?string
{
Assert::notEmpty($type, 'Cannot search for identifier handlers with an empty type.');
$handler = $type . ':BaseID';
return array_key_exists($handler, $this->registry) ? $this->registry[$handler] : null;
}
*/
}
......@@ -65,3 +65,7 @@ try {
// set the timezone
\SimpleSAML\Utils\Time::initTimezone();
// set the SAML2 container
$container = new \SimpleSAML\Compat\SspContainer();
\SAML2\Compat\ContainerSingleton::setContainer($container);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment