Skip to content

Commit

Permalink
Replace sppmod_* with namespaced version (batch 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jun 1, 2018
1 parent 12c2ed8 commit cc2967b
Show file tree
Hide file tree
Showing 77 changed files with 573 additions and 446 deletions.
2 changes: 1 addition & 1 deletion lib/SimpleSAML/Logger/FileLoggingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function log($level, $string)
}

$string = str_replace($formats, $replacements, $string);
file_put_contents($this->logFile, $string.PHP_EOL, FILE_APPEND);
file_put_contents($this->logFile, $string.\PHP_EOL, FILE_APPEND);
}
}
}
6 changes: 3 additions & 3 deletions modules/metarefresh/bin/metarefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// Add library autoloader.
require_once($baseDir . '/lib/_autoload.php');

if(!SimpleSAML\Module::isModuleEnabled('metarefresh')) {
if(!\SimpleSAML\Module::isModuleEnabled('metarefresh')) {
echo("You need to enable the metarefresh module before this script can be used.\n");
echo("You can enable it by running the following command:\n");
echo(' echo >"' . $baseDir . '/modules/metarefresh/enable' . "\"\n");
exit(1);
}

/* Initialize the configuration. */
$configdir = SimpleSAML\Utils\Config::getConfigDir();
$configdir = \SimpleSAML\Utils\Config::getConfigDir();
\SimpleSAML\Configuration::setConfigDir($configdir);

/* $outputDir contains the directory we will store the generated metadata in. */
Expand Down Expand Up @@ -128,7 +128,7 @@


/* The metadata global variable will be filled with the metadata we extract. */
$metaloader = new sspmod_metarefresh_MetaLoader();
$metaloader = new \SimpleSAML\Module\metarefresh\MetaLoader();

foreach($files as $f) {
$source = array('src' => $f);
Expand Down
8 changes: 4 additions & 4 deletions modules/metarefresh/hooks/hook_cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function metarefresh_hook_cron(&$croninfo) {
$cronTags = $set->getArray('cron');
if (!in_array($croninfo['tag'], $cronTags, true)) continue;

SimpleSAML\Logger::info('cron [metarefresh]: Executing set [' . $setkey . ']');
\SimpleSAML\Logger::info('cron [metarefresh]: Executing set [' . $setkey . ']');

$expireAfter = $set->getInteger('expireAfter', NULL);
if ($expireAfter !== NULL) {
Expand All @@ -41,7 +41,7 @@ function metarefresh_hook_cron(&$croninfo) {
'directory' => $outputDir,
));

$metaloader = new sspmod_metarefresh_MetaLoader($expire, $stateFile, $oldMetadataSrc);
$metaloader = new \SimpleSAML\Module\metarefresh\MetaLoader($expire, $stateFile, $oldMetadataSrc);

# Get global blacklist, whitelist and caching info
$blacklist = $mconfig->getArray('blacklist', array());
Expand Down Expand Up @@ -86,7 +86,7 @@ function metarefresh_hook_cron(&$croninfo) {
$source['conditionalGET'] = $conditionalGET;
}

SimpleSAML\Logger::debug('cron [metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');
\SimpleSAML\Logger::debug('cron [metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']');
$metaloader->loadSource($source);
}

Expand All @@ -108,7 +108,7 @@ function metarefresh_hook_cron(&$croninfo) {
}
}

} catch (Exception $e) {
} catch (\Exception $e) {
$croninfo['summary'][] = 'Error during metarefresh: ' . $e->getMessage();
}
}
15 changes: 9 additions & 6 deletions modules/metarefresh/lib/ARP.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace SimpleSAML\Module\metarefresh;

/*
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
* @package SimpleSAMLphp
*/

class sspmod_metarefresh_ARP
class ARP
{
/**
* @var array
Expand All @@ -26,10 +29,10 @@ class sspmod_metarefresh_ARP
*/
private $suffix;

/**
* Constructor
*
* @param array $metadata
/**
* Constructor
*
* @param array $metadata
* @param string $attributemap
* @param string $prefix
* @param string $suffix
Expand All @@ -56,7 +59,7 @@ private function loadAttributeMap($attributemap)
include($config->getPathValue('attributemap', 'attributemap/') . $attributemap . '.php');
// Note that $attributemap was a string before the call to include() and is now an array!
$this->attributes = $attributemap;
}
}

/**
* @param string $name
Expand Down
65 changes: 34 additions & 31 deletions modules/metarefresh/lib/MetaLoader.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

namespace SimpleSAML\Module\metarefresh;

/**
* @package SimpleSAMLphp
* @author Andreas Åkre Solberg <andreas.solberg@uninett.no>
*/
class sspmod_metarefresh_MetaLoader

class MetaLoader
{
private $expire;
private $metadata;
Expand Down Expand Up @@ -41,7 +45,6 @@ public function __construct($expire = null, $stateFile = null, $oldMetadataSrc =
}

$this->state = array();

}


Expand Down Expand Up @@ -85,24 +88,24 @@ public function loadSource($source)
// GET!
try {
list($data, $responseHeaders) = \SimpleSAML\Utils\HTTP::fetch($source['src'], $context, true);
} catch(Exception $e) {
SimpleSAML\Logger::warning('metarefresh: ' . $e->getMessage());
} catch(\Exception $e) {
\SimpleSAML\Logger::warning('metarefresh: ' . $e->getMessage());
}

// We have response headers, so the request succeeded
if (!isset($responseHeaders)) {
// No response headers, this means the request failed in some way, so re-use old data
SimpleSAML\Logger::debug('No response from ' . $source['src'] . ' - attempting to re-use cached metadata');
\SimpleSAML\Logger::debug('No response from ' . $source['src'] . ' - attempting to re-use cached metadata');
$this->addCachedMetadata($source);
return;
} elseif (preg_match('@^HTTP/1\.[01]\s304\s@', $responseHeaders[0])) {
// 304 response
SimpleSAML\Logger::debug('Received HTTP 304 (Not Modified) - attempting to re-use cached metadata');
\SimpleSAML\Logger::debug('Received HTTP 304 (Not Modified) - attempting to re-use cached metadata');
$this->addCachedMetadata($source);
return;
} elseif (!preg_match('@^HTTP/1\.[01]\s200\s@', $responseHeaders[0])) {
// Other error
SimpleSAML\Logger::debug('Error from ' . $source['src'] . ' - attempting to re-use cached metadata');
\SimpleSAML\Logger::debug('Error from ' . $source['src'] . ' - attempting to re-use cached metadata');
$this->addCachedMetadata($source);
return;
}
Expand All @@ -115,14 +118,14 @@ public function loadSource($source)
// Everything OK. Proceed.
if (isset($source['conditionalGET']) && $source['conditionalGET']) {
// Stale or no metadata, so a fresh copy
SimpleSAML\Logger::debug('Downloaded fresh copy');
\SimpleSAML\Logger::debug('Downloaded fresh copy');
}

try {
$entities = $this->loadXML($data, $source);
} catch(Exception $e) {
SimpleSAML\Logger::debug('XML parser error when parsing ' . $source['src'] . ' - attempting to re-use cached metadata');
SimpleSAML\Logger::debug('XML parser returned: ' . $e->getMessage());
} catch(\Exception $e) {
\SimpleSAML\Logger::debug('XML parser error when parsing ' . $source['src'] . ' - attempting to re-use cached metadata');
\SimpleSAML\Logger::debug('XML parser returned: ' . $e->getMessage());
$this->addCachedMetadata($source);
return;
}
Expand All @@ -131,33 +134,33 @@ public function loadSource($source)

if (isset($source['blacklist'])) {
if (!empty($source['blacklist']) && in_array($entity->getEntityID(), $source['blacklist'], true)) {
SimpleSAML\Logger::info('Skipping "' . $entity->getEntityID() . '" - blacklisted.' . "\n");
\SimpleSAML\Logger::info('Skipping "' . $entity->getEntityID() . '" - blacklisted.' . "\n");
continue;
}
}

if (isset($source['whitelist'])) {
if (!empty($source['whitelist']) && !in_array($entity->getEntityID(), $source['whitelist'], true)) {
SimpleSAML\Logger::info('Skipping "' . $entity->getEntityID() . '" - not in the whitelist.' . "\n");
\SimpleSAML\Logger::info('Skipping "' . $entity->getEntityID() . '" - not in the whitelist.' . "\n");
continue;
}
}

if (array_key_exists('certificates', $source) && $source['certificates'] !== null) {
if (!$entity->validateSignature($source['certificates'])) {
SimpleSAML\Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature using certificate.' . "\n");
\SimpleSAML\Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature using certificate.' . "\n");
continue;
}
}

if (array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== null) {
if (!array_key_exists('certificates', $source) || $source['certificates'] == null) {
if (!$entity->validateFingerprint($source['validateFingerprint'])) {
SimpleSAML\Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature using fingerprint.' . "\n");
\SimpleSAML\Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature using fingerprint.' . "\n");
continue;
}
} else {
SimpleSAML\Logger::info('Skipping validation with fingerprint since option certificate is set.' . "\n");
\SimpleSAML\Logger::info('Skipping validation with fingerprint since option certificate is set.' . "\n");
}
}

Expand Down Expand Up @@ -266,7 +269,7 @@ private function loadXML($data, $source)
{
try {
$doc = \SAML2\DOMDocumentFactory::fromString($data);
} catch (Exception $e) {
} catch (\Exception $e) {
throw new Exception('Failed to read XML from ' . $source['src']);
}
if ($doc->documentElement === null) {
Expand All @@ -282,8 +285,8 @@ private function loadXML($data, $source)
public function writeState()
{
if ($this->changed) {
SimpleSAML\Logger::debug('Writing: ' . $this->stateFile);
SimpleSAML\Utils\System::writeFile(
\SimpleSAML\Logger::debug('Writing: ' . $this->stateFile);
\SimpleSAML\Utils\System::writeFile(
$this->stateFile,
"<?php\n/* This file was generated by the metarefresh module at ".$this->getTime() . ".\n".
" Do not update it manually as it will get overwritten. */\n".
Expand Down Expand Up @@ -379,7 +382,7 @@ public function writeARPfile($config)
}

// $metadata, $attributemap, $prefix, $suffix
$arp = new sspmod_metarefresh_ARP($md,
$arp = new \SimpleSAML\Module\metarefresh\ARP($md,
$config->getValue('attributemap', ''),
$config->getValue('prefix', ''),
$config->getValue('suffix', '')
Expand All @@ -388,7 +391,7 @@ public function writeARPfile($config)

$arpxml = $arp->getXML();

SimpleSAML\Logger::info('Writing ARP file: ' . $arpfile . "\n");
\SimpleSAML\Logger::info('Writing ARP file: ' . $arpfile . "\n");
file_put_contents($arpfile, $arpxml);
}

Expand All @@ -403,10 +406,10 @@ public function writeMetadataFiles($outputDir)
}

if (!file_exists($outputDir)) {
SimpleSAML\Logger::info('Creating directory: ' . $outputDir . "\n");
\SimpleSAML\Logger::info('Creating directory: ' . $outputDir . "\n");
$res = @mkdir($outputDir, 0777, true);
if ($res === false) {
throw new Exception('Error creating directory: ' . $outputDir);
throw new \Exception('Error creating directory: ' . $outputDir);
}
}

Expand All @@ -415,7 +418,7 @@ public function writeMetadataFiles($outputDir)

if (array_key_exists($type, $this->metadata)) {
$elements = $this->metadata[$type];
SimpleSAML\Logger::debug('Writing: ' . $filename);
\SimpleSAML\Logger::debug('Writing: ' . $filename);

$content = '<?php' . "\n" . '/* This file was generated by the metarefresh module at '. $this->getTime() . "\n";
$content .= ' Do not update it manually as it will get overwritten' . "\n" . '*/' . "\n";
Expand All @@ -428,12 +431,12 @@ public function writeMetadataFiles($outputDir)

$content .= "\n" . '?>';

SimpleSAML\Utils\System::writeFile($filename, $content, 0644);
\SimpleSAML\Utils\System::writeFile($filename, $content, 0644);
} elseif (is_file($filename)) {
if (unlink($filename)) {
SimpleSAML\Logger::debug('Deleting stale metadata file: ' . $filename);
\SimpleSAML\Logger::debug('Deleting stale metadata file: ' . $filename);
} else {
SimpleSAML\Logger::warning('Could not delete stale metadata file: ' . $filename);
\SimpleSAML\Logger::warning('Could not delete stale metadata file: ' . $filename);
}
}
}
Expand All @@ -456,7 +459,7 @@ public function writeMetadataSerialize($outputDir)
foreach ($elements as $m) {
$entityId = $m['metadata']['entityid'];

SimpleSAML\Logger::debug(
\SimpleSAML\Logger::debug(
'metarefresh: Add metadata entry ' .
var_export($entityId, true) . ' in set ' . var_export($set, true) . '.'
);
Expand All @@ -469,7 +472,7 @@ public function writeMetadataSerialize($outputDir)
foreach ($metaHandler->getMetadataSets() as $set) {
foreach ($metaHandler->getMetadataSet($set) as $entityId => $metadata) {
if (!array_key_exists('expire', $metadata)) {
SimpleSAML\Logger::warning(
\SimpleSAML\Logger::warning(
'metarefresh: Metadata entry without expire timestamp: ' . var_export($entityId, true) .
' in set ' . var_export($set, true) . '.'
);
Expand All @@ -478,8 +481,8 @@ public function writeMetadataSerialize($outputDir)
if ($metadata['expire'] > $ct) {
continue;
}
SimpleSAML\Logger::debug('metarefresh: ' . $entityId . ' expired ' . date('l jS \of F Y h:i:s A', $metadata['expire']));
SimpleSAML\Logger::debug(
\SimpleSAML\Logger::debug('metarefresh: ' . $entityId . ' expired ' . date('l jS \of F Y h:i:s A', $metadata['expire']));
\SimpleSAML\Logger::debug(
'metarefresh: Delete expired metadata entry ' .
var_export($entityId, true) . ' in set ' . var_export($set, true) . '. (' . ($ct - $metadata['expire']) . ' sec)'
);
Expand Down
2 changes: 1 addition & 1 deletion modules/metarefresh/www/fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$expire = NULL;
}

$metaloader = new sspmod_metarefresh_MetaLoader($expire);
$metaloader = new \SimpleSAML\Module\metarefresh\MetaLoader($expire);

# Get global black/whitelists
$blacklist = $mconfig->getArray('blacklist', array());
Expand Down
16 changes: 9 additions & 7 deletions modules/multiauth/lib/Auth/Source/MultiAuth.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace SimpleSAML\Module\multiauth\Auth\Source;

/**
* Authentication source which let the user chooses among a list of
* other authentication sources
Expand All @@ -8,22 +10,22 @@
* @package SimpleSAMLphp
*/

class sspmod_multiauth_Auth_Source_MultiAuth extends \SimpleSAML\Auth\Source
class MultiAuth extends \SimpleSAML\Auth\Source
{
/**
* The key of the AuthId field in the state.
*/
const AUTHID = 'sspmod_multiauth_Auth_Source_MultiAuth.AuthId';
const AUTHID = '\SimpleSAML\Module\multiauth\Auth\Source\MultiAuth.AuthId';

/**
* The string used to identify our states.
*/
const STAGEID = 'sspmod_multiauth_Auth_Source_MultiAuth.StageId';
const STAGEID = '\SimpleSAML\Module\multiauth\Auth\Source\MultiAuth.StageId';

/**
* The key where the sources is saved in the state.
*/
const SOURCESID = 'sspmod_multiauth_Auth_Source_MultiAuth.SourceId';
const SOURCESID = '\SimpleSAML\Module\multiauth\Auth\Source\MultiAuth.SourceId';

/**
* The key where the selected source is saved in the session.
Expand All @@ -49,7 +51,7 @@ public function __construct($info, $config) {
parent::__construct($info, $config);

if (!array_key_exists('sources', $config)) {
throw new Exception('The required "sources" config option was not found');
throw new \Exception('The required "sources" config option was not found');
}

$globalConfiguration = \SimpleSAML\Configuration::getInstance();
Expand Down Expand Up @@ -112,7 +114,7 @@ public function authenticate(&$state) {

/* Redirect to the select source page. We include the identifier of the
saved state array as a parameter to the login form */
$url = SimpleSAML\Module::getModuleURL('multiauth/selectsource.php');
$url = \SimpleSAML\Module::getModuleURL('multiauth/selectsource.php');
$params = array('AuthState' => $id);

// Allowes the user to specify the auth souce to be used
Expand Down Expand Up @@ -150,7 +152,7 @@ function($src) {
$state[self::SOURCESID]
);
if ($as === NULL || !in_array($authId, $valid_sources, true)) {
throw new Exception('Invalid authentication source: ' . $authId);
throw new \Exception('Invalid authentication source: ' . $authId);
}

/* Save the selected authentication source for the logout process. */
Expand Down
Loading

0 comments on commit cc2967b

Please sign in to comment.