Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"symfony/config": "^5.4",
"symfony/console": "^5.4",
"symfony/dependency-injection": "^5.4",
"symfony/filesystem": "^5.4",
"symfony/finder": "^5.4",
"symfony/framework-bundle": "^5.4",
"symfony/http-foundation": "^5.4",
Expand Down Expand Up @@ -94,8 +95,9 @@
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"simplesamlphp/composer-module-installer": true,
"composer/package-versions-deprecated": true
"muglug/package-versions-56": true
}
}
}
14 changes: 7 additions & 7 deletions composer.lock

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

61 changes: 42 additions & 19 deletions lib/SimpleSAML/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,33 @@

namespace SimpleSAML;

use Exception;
use ParseError;
use SAML2\Constants;
use SimpleSAML\Assert\Assert;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\Error;
use SimpleSAML\Utils;
use Symfony\Component\Filesystem\Filesystem;

use function array_key_exists;
use function array_keys;
use function dirname;
use function implode;
use function interface_exists;
use function in_array;
use function is_array;
use function is_bool;
use function is_int;
use function is_string;
use function ob_end_clean;
use function ob_get_length;
use function ob_start;
use function preg_match;
use function preg_replace;
use function rtrim;
use function substr;
use function var_export;

/**
* Configuration of SimpleSAMLphp
Expand Down Expand Up @@ -106,7 +128,8 @@ private static function loadFromFile(string $filename, bool $required): Configur
return self::$loadedConfigs[$filename];
}

if (file_exists($filename)) {
$fileSystem = new Filesystem();
if ($fileSystem->exists($filename)) {
/** @psalm-var mixed $config */
$config = 'UNINITIALIZED';

Expand All @@ -115,7 +138,7 @@ private static function loadFromFile(string $filename, bool $required): Configur
if (interface_exists('Throwable', false)) {
try {
require($filename);
} catch (\ParseError $e) {
} catch (ParseError $e) {
self::$loadedConfigs[$filename] = self::loadFromArray([], '[ARRAY]', 'simplesaml');
throw new Error\ConfigurationError($e->getMessage(), $filename, []);
}
Expand Down Expand Up @@ -204,7 +227,7 @@ public static function setPreLoadedConfig(
): void {
if (!array_key_exists($configSet, self::$configDirs)) {
if ($configSet !== 'simplesaml') {
throw new \Exception('Configuration set \'' . $configSet . '\' not initialized.');
throw new Exception('Configuration set \'' . $configSet . '\' not initialized.');
} else {
self::$configDirs['simplesaml'] = dirname(dirname(dirname(__FILE__))) . '/config';
}
Expand Down Expand Up @@ -232,7 +255,7 @@ public static function getConfig(
): Configuration {
if (!array_key_exists($configSet, self::$configDirs)) {
if ($configSet !== 'simplesaml') {
throw new \Exception('Configuration set \'' . $configSet . '\' not initialized.');
throw new Exception('Configuration set \'' . $configSet . '\' not initialized.');
} else {
$configUtils = new Utils\Config();
self::$configDirs['simplesaml'] = $configUtils->getConfigDir();
Expand Down Expand Up @@ -262,7 +285,7 @@ public static function getOptionalConfig(
): Configuration {
if (!array_key_exists($configSet, self::$configDirs)) {
if ($configSet !== 'simplesaml') {
throw new \Exception('Configuration set \'' . $configSet . '\' not initialized.');
throw new Exception('Configuration set \'' . $configSet . '\' not initialized.');
} else {
$configUtils = new Utils\Config();
self::$configDirs['simplesaml'] = $configUtils->getConfigDir();
Expand Down Expand Up @@ -1113,7 +1136,7 @@ private function getDefaultBinding(string $endpointType): string
case 'saml20-idp-remote:ArtifactResolutionService':
return Constants::BINDING_SOAP;
default:
throw new \Exception('Missing default binding for ' . $endpointType . ' in ' . $set);
throw new Exception('Missing default binding for ' . $endpointType . ' in ' . $set);
}
}

Expand Down Expand Up @@ -1142,7 +1165,7 @@ public function getEndpoints(string $endpointType): array
// for backwards-compatibility
$eps = [$eps];
} elseif (!is_array($eps)) {
throw new \Exception($loc . ': Expected array or string.');
throw new Exception($loc . ': Expected array or string.');
}


Expand All @@ -1160,32 +1183,32 @@ public function getEndpoints(string $endpointType): array
$ep['ResponseLocation'] = $responseLocation;
}
} elseif (!is_array($ep)) {
throw new \Exception($iloc . ': Expected a string or an array.');
throw new Exception($iloc . ': Expected a string or an array.');
}

if (!array_key_exists('Location', $ep)) {
throw new \Exception($iloc . ': Missing Location.');
throw new Exception($iloc . ': Missing Location.');
}
if (!is_string($ep['Location'])) {
throw new \Exception($iloc . ': Location must be a string.');
throw new Exception($iloc . ': Location must be a string.');
}

if (!array_key_exists('Binding', $ep)) {
throw new \Exception($iloc . ': Missing Binding.');
throw new Exception($iloc . ': Missing Binding.');
}
if (!is_string($ep['Binding'])) {
throw new \Exception($iloc . ': Binding must be a string.');
throw new Exception($iloc . ': Binding must be a string.');
}

if (array_key_exists('ResponseLocation', $ep)) {
if (!is_string($ep['ResponseLocation'])) {
throw new \Exception($iloc . ': ResponseLocation must be a string.');
throw new Exception($iloc . ': ResponseLocation must be a string.');
}
}

if (array_key_exists('index', $ep)) {
if (!is_int($ep['index'])) {
throw new \Exception($iloc . ': index must be an integer.');
throw new Exception($iloc . ': index must be an integer.');
}
}
}
Expand Down Expand Up @@ -1223,7 +1246,7 @@ public function getEndpointPrioritizedByBinding(

if ($default === self::REQUIRED_OPTION) {
$loc = $this->location . '[' . var_export($endpointType, true) . ']:';
throw new \Exception($loc . 'Could not find a supported ' . $endpointType . ' endpoint.');
throw new Exception($loc . 'Could not find a supported ' . $endpointType . ' endpoint.');
}

return $default;
Expand Down Expand Up @@ -1253,7 +1276,7 @@ public function getDefaultEndpoint(string $endpointType, array $bindings = null,

if ($default === self::REQUIRED_OPTION) {
$loc = $this->location . '[' . var_export($endpointType, true) . ']:';
throw new \Exception($loc . 'Could not find a supported ' . $endpointType . ' endpoint.');
throw new Exception($loc . 'Could not find a supported ' . $endpointType . ' endpoint.');
}

return $default;
Expand Down Expand Up @@ -1368,15 +1391,15 @@ public function getPublicKeys(?string $use = null, bool $required = false, strin
$data = @file_get_contents($file);

if ($data === false) {
throw new \Exception(
throw new Exception(
$this->location . ': Unable to load certificate/public key from file "' . $file . '".'
);
}

// extract certificate data (if this is a certificate)
$pattern = '/^-----BEGIN CERTIFICATE-----([^-]*)^-----END CERTIFICATE-----/m';
if (!preg_match($pattern, $data, $matches)) {
throw new \SimpleSAML\Error\Exception(
throw new Error\Exception(
$this->location . ': Could not find PEM encoded certificate in "' . $file . '".'
);
}
Expand All @@ -1393,7 +1416,7 @@ public function getPublicKeys(?string $use = null, bool $required = false, strin
],
];
} elseif ($required === true) {
throw new \SimpleSAML\Error\Exception($this->location . ': Missing certificate in metadata.');
throw new Error\Exception($this->location . ': Missing certificate in metadata.');
} else {
return [];
}
Expand Down
29 changes: 21 additions & 8 deletions lib/SimpleSAML/Locale/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

namespace SimpleSAML\Locale;

use Exception;
use Gettext\Translations;
use Gettext\Translator;
use SimpleSAML\Configuration;
use SimpleSAML\Logger;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;

class Localization
{
Expand Down Expand Up @@ -66,6 +69,11 @@ class Localization
*/
private string $langcode;

/**
* @var \Symfony\Component\Filesystem\Filesystem;
*/
private Filesystem $fileSystem;


/**
* Constructor
Expand All @@ -74,6 +82,7 @@ class Localization
*/
public function __construct(Configuration $configuration)
{
$this->fileSystem = new Filesystem();
$this->configuration = $configuration;
/** @var string $locales */
$locales = $this->configuration->resolvePath('locales');
Expand Down Expand Up @@ -186,7 +195,7 @@ public function getLangPath(string $domain = self::DEFAULT_DOMAIN): string
// Locale for default language missing even, error out
$error = "Localization directory '$langPath' missing/broken for langcode '$langcode' and domain '$domain'";
Logger::critical($_SERVER['PHP_SELF'] . ' - ' . $error);
throw new \Exception($error);
throw new Exception($error);
}


Expand Down Expand Up @@ -217,7 +226,7 @@ private function loadGettextGettextFromPO(
): void {
try {
$langPath = $this->getLangPath($domain);
} catch (\Exception $e) {
} catch (Exception $e) {
$error = "Something went wrong when trying to get path to language file, cannot load domain '$domain'.";
Logger::debug($_SERVER['PHP_SELF'] . ' - ' . $error);
if ($catchException) {
Expand All @@ -227,14 +236,18 @@ private function loadGettextGettextFromPO(
throw $e;
}
}
$poFile = $domain . '.po';
$poPath = $langPath . $poFile;
if (file_exists($poPath) && is_readable($poPath)) {
$translations = Translations::fromPoFile($poPath);

$file = new File($langPath . $domain . '.po');
if ($this->fileSystem->exists($file->getRealPath()) && $file->isReadable()) {
$translations = Translations::fromPoFile($file->getRealPath());
$this->translator->loadTranslations($translations);
} else {
$error = "Localization file '$poFile' not found in '$langPath', falling back to default";
Logger::debug($_SERVER['PHP_SELF'] . ' - ' . $error);
Logger::debug(sprintf(
"%s - Localization file '%s' not found or not readable in '%s', falling back to default",
$_SERVER['PHP_SELF'],
$file->getfileName(),
$langPath,
));
}
}

Expand Down
Loading