mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Refactored authorizers to classes * Merge changes for #7335 * ! fix php 5.3 incompatibility * Update ADAuthorizationAuthorizer.php * Fix get_user -> getUser * Rename AuthorizerFactory to Auth, fix interface missing functions * Add phpdocs to all interface methods and normalize the names a bit. * Re-work auth_test.php AD bind tests to work properly with the new class. Reflection is not the nicest tool, but I think it is appropriate here. Handle exceptions more nicely in auth_test.php * Restore AD getUseList fix Not sure how it got removed * fix auth_test.php style
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace LibreNMS\Authentication;
|
|
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Interfaces\Authentication\Authorizer;
|
|
|
|
class Auth
|
|
{
|
|
protected static $_instance;
|
|
|
|
/**
|
|
* Gets the authorizer based on the config
|
|
*
|
|
* @return Authorizer
|
|
*/
|
|
public static function get()
|
|
{
|
|
if (!static::$_instance) {
|
|
$configToClassMap = array(
|
|
'mysql' => 'LibreNMS\Authentication\MysqlAuthorizer',
|
|
'active_directory' => 'LibreNMS\Authentication\ActiveDirectoryAuthorizer',
|
|
'ldap' => 'LibreNMS\Authentication\LdapAuthorizer',
|
|
'radius' => 'LibreNMS\Authentication\RadiusAuthorizer',
|
|
'http-auth' => 'LibreNMS\Authentication\HttpAuthAuthorizer',
|
|
'ad-authorization' => 'LibreNMS\Authentication\ADAuthorizationAuthorizer',
|
|
'ldap-authorization' => 'LibreNMS\Authentication\LdapAuthorizationAuthorizer',
|
|
);
|
|
|
|
$auth_mechanism = Config::get('auth_mechanism');
|
|
if (!isset($configToClassMap[$auth_mechanism])) {
|
|
throw new \RuntimeException($auth_mechanism . ' not found as auth_mechanism');
|
|
}
|
|
|
|
static::$_instance = new $configToClassMap[$auth_mechanism]();
|
|
}
|
|
return static::$_instance;
|
|
}
|
|
}
|