Skip to content
Snippets Groups Projects
Commit c6698bad authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Resolve duplication of code.

parent fe685373
Branches
Tags
No related merge requests found
...@@ -61,12 +61,7 @@ abstract class SimpleSAML_Auth_Source ...@@ -61,12 +61,7 @@ abstract class SimpleSAML_Auth_Source
foreach ($sources as $id) { foreach ($sources as $id) {
$source = $config->getArray($id); $source = $config->getArray($id);
if (!array_key_exists(0, $source) || !is_string($source[0])) { self::validateSource($source, $id);
throw new Exception(
'Invalid authentication source \''.$id.
'\': First element must be a string which identifies the authentication source.'
);
}
if ($source[0] !== $type) { if ($source[0] !== $type) {
continue; continue;
...@@ -213,12 +208,7 @@ abstract class SimpleSAML_Auth_Source ...@@ -213,12 +208,7 @@ abstract class SimpleSAML_Auth_Source
assert('is_string($authId)'); assert('is_string($authId)');
assert('is_array($config)'); assert('is_array($config)');
if (!array_key_exists(0, $config) || !is_string($config[0])) { self::validateSource($config, $authId);
throw new Exception(
'Invalid authentication source \''.$authId.
'\': First element must be a string which identifies the authentication source.'
);
}
$className = SimpleSAML_Module::resolveClass($config[0], 'Auth_Source', 'SimpleSAML_Auth_Source'); $className = SimpleSAML_Module::resolveClass($config[0], 'Auth_Source', 'SimpleSAML_Auth_Source');
...@@ -375,4 +365,23 @@ abstract class SimpleSAML_Auth_Source ...@@ -375,4 +365,23 @@ abstract class SimpleSAML_Auth_Source
return $config->getOptions(); return $config->getOptions();
} }
/**
* Make sure that the first element of an auth source is its identifier.
*
* @param array $source An array with the auth source configuration.
* @param string $id The auth source identifier.
*
* @throws Exception If the first element of $source is not an identifier for the auth source.
*/
protected static function validateSource($source, $id)
{
if (!array_key_exists(0, $source) || !is_string($source[0])) {
throw new Exception(
'Invalid authentication source \''.$id.
'\': First element must be a string which identifies the authentication source.'
);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment