Skip to content
Snippets Groups Projects
Commit 5b8f8aa8 authored by Olav Morken's avatar Olav Morken
Browse files

SimpleSAML_Auth_Source: Add $type parameter to getById().

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1777 44740490-163a-0410-bde0-09ae8108e29a
parent 389c8627
No related branches found
No related tags found
No related merge requests found
......@@ -197,24 +197,44 @@ abstract class SimpleSAML_Auth_Source {
* Retrieve authentication source.
*
* This function takes an id of an authentication source, and returns the
* AuthSource object.
* AuthSource object. If no authentication source with the given id can be found,
* NULL will be returned.
*
* If the $type parameter is specified, this function will return an
* authentication source of the given type. If no authentication source or if an
* authentication source of a different type is found, an exception will be thrown.
*
* @param string $authId The authentication source identifier.
* @param string|NULL $type The type of authentication source. If NULL, any type will be accepted.
* @return SimpleSAML_Auth_Source|NULL The AuthSource object, or NULL if no authentication
* source with the given identifier is found.
*/
public static function getById($authId) {
public static function getById($authId, $type = NULL) {
assert('is_string($authId)');
assert('is_null($type) || is_string($type)');
/* For now - load and parse config file. */
$config = SimpleSAML_Configuration::getConfig('authsources.php');
$authConfig = $config->getArray($authId, NULL);
if ($authConfig === NULL) {
if ($type !== NULL) {
throw new SimpleSAML_Error_Exception('No authentication source with id ' .
var_export($authId, TRUE) . ' found.');
}
return NULL;
}
return self::parseAuthSource($authId, $authConfig);
$ret = self::parseAuthSource($authId, $authConfig);
if ($type === NULL || $ret instanceof $type) {
return $ret;
}
/* The authentication source doesn't have the correct type. */
throw new SimpleSAML_Error_Exception('Invalid type of authentication source ' .
var_export($authId, TRUE) . '. Was ' . var_export(get_class($ret), TRUE) .
', should be ' . var_export($type, TRUE) . '.');
}
......
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