From 65fbea3a9bf2bcb52870278be7ec71fa3d7cdcd0 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Mon, 15 Nov 2021 09:02:35 +0100
Subject: [PATCH] Inject config

---
 .../DbpRelayLdapPersonProviderExtension.php           |  2 +-
 src/Service/LDAPApi.php                               | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php b/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php
index e9feca9..5c16e41 100644
--- a/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php
+++ b/src/DependencyInjection/DbpRelayLdapPersonProviderExtension.php
@@ -20,7 +20,7 @@ class DbpRelayLdapPersonProviderExtension extends ConfigurableExtension
         $loader->load('services.yaml');
 
         // Inject the config value into the UCardService service
-        $definition = $container->getDefinition('Dbp\Relay\LdapPersonProviderBundle\Service\UCardService');
+        $definition = $container->getDefinition('Dbp\Relay\LdapPersonProviderBundle\Service\LDAPApi');
         $definition->addMethodCall('setConfig', [$mergedConfig]);
     }
 
diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php
index a1fbc76..d4ba9e5 100644
--- a/src/Service/LDAPApi.php
+++ b/src/Service/LDAPApi.php
@@ -96,6 +96,17 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
         $this->birthdayAttributeName = $this->params->get('app.ldap.attributes.birthday') ?? '';
     }
 
+    public function setConfig(array $config)
+    {
+        $this->providerConfig = [
+            'hosts' => [$config['host'] ?? ''],
+            'base_dn' => $config['base_dn'] ?? '',
+            'username' => $config['username'] ?? '',
+            'password' => $config['password'] ?? '',
+            'use_tls' => true,
+        ];
+    }
+
     public function setDeploymentEnvironment(string $env)
     {
         $this->deploymentEnv = $env;
-- 
GitLab