Refactor authentication system (#2602)
Make auth configuration available via UI, remove FOSUserBundle and SAML-Bundle dependency
This commit is contained in:
@@ -70,14 +70,24 @@ class AppExtension extends Extension
|
||||
|
||||
$this->createPermissionParameter($config['permissions'], $container);
|
||||
$this->createThemeParameter($config['theme'], $container);
|
||||
$this->createUserParameter($config['user'], $container);
|
||||
$container->setParameter('kimai.saml', $config['saml']);
|
||||
$container->setParameter('kimai.saml.connection', $config['saml']['connection']);
|
||||
$container->setParameter('kimai.timesheet', $config['timesheet']); // @deprecated since 1.13
|
||||
$container->setParameter('kimai.timesheet.rates', $config['timesheet']['rates']);
|
||||
$container->setParameter('kimai.timesheet.rounding', $config['timesheet']['rounding']);
|
||||
|
||||
$this->setLdapParameter($config['ldap'], $container);
|
||||
if (!isset($config['ldap']['connection']['baseDn'])) {
|
||||
$config['ldap']['connection']['baseDn'] = $config['ldap']['user']['baseDn'];
|
||||
}
|
||||
|
||||
if (empty($config['ldap']['connection']['accountFilterFormat']) && $config['ldap']['connection']['bindRequiresDn']) {
|
||||
$filter = '';
|
||||
if (!empty($config['ldap']['user']['filter'])) {
|
||||
$filter = $config['ldap']['user']['filter'];
|
||||
}
|
||||
$config['ldap']['connection']['accountFilterFormat'] = '(&' . $filter . '(' . $config['ldap']['user']['usernameAttribute'] . '=%s))';
|
||||
}
|
||||
|
||||
// @deprecated since 1.15
|
||||
$container->setParameter('kimai.ldap', $config['ldap']);
|
||||
|
||||
// translation files, which can overwrite the default kimai translations
|
||||
$localTranslations = [];
|
||||
@@ -129,23 +139,6 @@ class AppExtension extends Extension
|
||||
$container->setParameter('kimai.languages', $config);
|
||||
}
|
||||
|
||||
protected function setLdapParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (!isset($config['connection']['baseDn'])) {
|
||||
$config['connection']['baseDn'] = $config['user']['baseDn'];
|
||||
}
|
||||
|
||||
if (empty($config['connection']['accountFilterFormat']) && $config['connection']['bindRequiresDn']) {
|
||||
$filter = '';
|
||||
if (!empty($config['user']['filter'])) {
|
||||
$filter = $config['user']['filter'];
|
||||
}
|
||||
$config['connection']['accountFilterFormat'] = '(&' . $filter . '(' . $config['user']['usernameAttribute'] . '=%s))';
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.ldap', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs some pre-compilation on the configured permissions from kimai.yaml
|
||||
* to save us from constant array lookups from during runtime.
|
||||
@@ -229,27 +222,6 @@ class AppExtension extends Extension
|
||||
$container->setParameter('kimai.theme.show_about', $config['show_about']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function createUserParameter(array $config, ContainerBuilder $container)
|
||||
{
|
||||
if (!$config['registration']) {
|
||||
$routes = $container->getParameter('admin_lte_theme.routes');
|
||||
$routes['adminlte_registration'] = null;
|
||||
$container->setParameter('admin_lte_theme.routes', $routes);
|
||||
}
|
||||
|
||||
if (!$config['password_reset']) {
|
||||
$routes = $container->getParameter('admin_lte_theme.routes');
|
||||
$routes['adminlte_password_reset'] = null;
|
||||
$container->setParameter('admin_lte_theme.routes', $routes);
|
||||
}
|
||||
|
||||
$container->setParameter('kimai.fosuser', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\DependencyInjection\Compiler;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Configuration\ThemeConfiguration;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
@@ -29,8 +30,8 @@ class TwigContextCompilerPass implements CompilerPassInterface
|
||||
$theme = $container->getDefinition(ThemeConfiguration::class);
|
||||
$twig->addMethodCall('addGlobal', ['kimai_context', $theme]);
|
||||
|
||||
$saml = $container->getParameter('kimai.saml');
|
||||
$twig->addMethodCall('addGlobal', ['saml', $saml]);
|
||||
$config = $container->getDefinition(SystemConfiguration::class);
|
||||
$twig->addMethodCall('addGlobal', ['kimai_config', $config]);
|
||||
|
||||
$definition = $container->getDefinition('twig.loader.native_filesystem');
|
||||
|
||||
|
||||
@@ -512,12 +512,21 @@ class Configuration implements ConfigurationInterface
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('registration')
|
||||
->booleanNode('login')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->booleanNode('registration')
|
||||
->defaultFalse()
|
||||
->end()
|
||||
->booleanNode('password_reset')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->integerNode('password_reset_retry_ttl')
|
||||
->defaultValue(7200)
|
||||
->end()
|
||||
->integerNode('password_reset_token_ttl')
|
||||
->defaultValue(86400)
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
@@ -670,6 +679,9 @@ class Configuration implements ConfigurationInterface
|
||||
$node
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('activate')
|
||||
->defaultFalse()
|
||||
->end()
|
||||
->arrayNode('connection')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
@@ -767,13 +779,13 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->validate()
|
||||
->ifTrue(static function ($v) {
|
||||
return null !== $v['connection']['host'] && !\extension_loaded('ldap');
|
||||
return $v['activate'] && !\extension_loaded('ldap');
|
||||
})
|
||||
->thenInvalid('LDAP is activated, but the LDAP PHP extension is not loaded.')
|
||||
->end()
|
||||
->validate()
|
||||
->ifTrue(static function ($v) {
|
||||
return null !== $v['connection']['host'] && empty($v['user']['baseDn']);
|
||||
return $v['activate'] && empty($v['user']['baseDn']);
|
||||
})
|
||||
->thenInvalid('The "ldap.user.baseDn" config must be set if LDAP is activated.')
|
||||
->end()
|
||||
|
||||
Reference in New Issue
Block a user