diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8055697c48751a7d79d2793187934c2d853a3f5c..c028728ae6c1b6290f8551a5ff59cdb2aa48484b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -13,13 +13,35 @@ class Configuration implements ConfigurationInterface { $treeBuilder = new TreeBuilder('dbp_relay_ldap_person_provider'); - $treeBuilder->getRootNode() + $cacheBuilder = new TreeBuilder('cache'); + $cacheNode = $cacheBuilder->getRootNode() ->children() - ->scalarNode('co_oauth2_ucardapi_client_id')->end() - ->scalarNode('co_oauth2_ucardapi_client_secret')->end() - ->scalarNode('co_oauth2_ucardapi_api_url')->end() - ->end() + ->scalarNode('person_cache_path')->end() + ->scalarNode('ldap_cache_path')->end() ->end(); + $treeBuilder->getRootNode()->append($cacheNode); + + $ldapBuilder = new TreeBuilder('ldap'); + $ldapNode = $ldapBuilder->getRootNode() + ->children() + ->scalarNode('host')->end() + ->scalarNode('base_dn')->end() + ->scalarNode('username')->end() + ->scalarNode('password')->end() + ->end(); + + $attributesBuilder = new TreeBuilder('attributes'); + $attributesNode = $attributesBuilder->getRootNode() + ->children() + ->scalarNode('identifier')->end() + ->scalarNode('given_name')->end() + ->scalarNode('family_name')->end() + ->scalarNode('email')->end() + ->scalarNode('birthday')->end() + ->end(); + $ldapNode->append($attributesNode); + + $treeBuilder->getRootNode()->append($ldapNode); return $treeBuilder; } diff --git a/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php b/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php index 5c16e41b3a5380ec383e35fa181429357aa70701..45af31c3aa5e3d2c519b60a05ecaf5b1b7785a08 100644 --- a/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php +++ b/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Dbp\Relay\LdapPersonProviderBundle\DependencyInjection; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -19,9 +20,20 @@ class DbpRelayLdapPersonProviderExtension extends ConfigurableExtension ); $loader->load('services.yaml'); + $ldapCache = $container->register('dbp_api.cache.ldap_person_provider.ldap', FilesystemAdapter::class); + $ldapCache->setArguments(['core-ldap', 360, '%kernel.cache_dir%/dbp/ldap-person-provider-ldap']); + $ldapCache->setPublic(true); + $ldapCache->addTag('cache.pool'); + + $personCacheDef = $container->register('dbp_api.cache.ldap_person_provider.auth_person', FilesystemAdapter::class); + $personCacheDef->setArguments(['core-auth-person', 60, '%kernel.cache_dir%/dbp/ldap-person-provider-auth-person']); + $personCacheDef->addTag('cache.pool'); + // Inject the config value into the UCardService service $definition = $container->getDefinition('Dbp\Relay\LdapPersonProviderBundle\Service\LDAPApi'); $definition->addMethodCall('setConfig', [$mergedConfig]); + $definition->addMethodCall('setLDAPCache', [$ldapCache, 360]); + $definition->addMethodCall('setPersonCache', [$personCacheDef]); } private function extendArrayParameter(ContainerBuilder $container, string $parameter, array $values) diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php index d4ba9e551ad1864bf3052c8fa66325e646729e3e..aec905d9fd850596c526961e7807e358514f7cd7 100644 --- a/src/Service/LDAPApi.php +++ b/src/Service/LDAPApi.php @@ -76,24 +76,24 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface $this->cacheTTL = 0; $this->currentPerson = null; $this->params = $params; - $this->providerConfig = [ - 'hosts' => [$this->params->get('app.ldap.host') ?? ''], - 'base_dn' => $this->params->get('app.ldap.base_dn') ?? '', - 'username' => $this->params->get('app.ldap.username') ?? '', - 'password' => $this->params->get('app.ldap.password') ?? '', - 'use_tls' => true, - ]; +// $this->providerConfig = [ +// 'hosts' => [$this->params->get('app.ldap.host') ?? ''], +// 'base_dn' => $this->params->get('app.ldap.base_dn') ?? '', +// 'username' => $this->params->get('app.ldap.username') ?? '', +// 'password' => $this->params->get('app.ldap.password') ?? '', +// 'use_tls' => true, +// ]; $this->locator = $locator; $this->deploymentEnv = 'production'; - $this->setPersonCache(new FilesystemAdapter('app-core-auth-person', 60, (string) $this->params->get('app.cache.person-cache-path'))); - $this->setLDAPCache(new FilesystemAdapter('app-core-ldap', 360, (string) $this->params->get('app.cache.ldap-cache-path')), 360); +// $this->setPersonCache(new FilesystemAdapter('app-core-auth-person', 60, (string) $this->params->get('app.cache.person-cache-path'))); +// $this->setLDAPCache(new FilesystemAdapter('app-core-ldap', 360, (string) $this->params->get('app.cache.ldap-cache-path')), 360); - $this->identifierAttributeName = $this->params->get('app.ldap.attributes.identifier') ?? 'cn'; - $this->givenNameAttributeName = $this->params->get('app.ldap.attributes.given_name') ?? 'givenName'; - $this->familyNameAttributeName = $this->params->get('app.ldap.attributes.family_name') ?? 'sn'; - $this->emailAttributeName = $this->params->get('app.ldap.attributes.email') ?? ''; - $this->birthdayAttributeName = $this->params->get('app.ldap.attributes.birthday') ?? ''; +// $this->identifierAttributeName = $this->params->get('app.ldap.attributes.identifier') ?? 'cn'; +// $this->givenNameAttributeName = $this->params->get('app.ldap.attributes.given_name') ?? 'givenName'; +// $this->familyNameAttributeName = $this->params->get('app.ldap.attributes.family_name') ?? 'sn'; +// $this->emailAttributeName = $this->params->get('app.ldap.attributes.email') ?? ''; +// $this->birthdayAttributeName = $this->params->get('app.ldap.attributes.birthday') ?? ''; } public function setConfig(array $config)