From b73dc8a184df94367f339092ba6cf52de0ec0fd1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Wed, 6 Jun 2018 17:21:30 +0200
Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20de=20personnaliser=20l'attri?=
 =?UTF-8?q?but=20LDAP=20utilis=C3=A9=20pour=20peupler=20le=20username=20de?=
 =?UTF-8?q?s=20users?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 config/module.config.php                  |  5 +++
 config/unicaen-auth.global.php.dist       |  6 +++
 src/UnicaenAuth/Options/ModuleOptions.php | 45 +++++++++++++++++++----
 src/UnicaenAuth/Service/User.php          |  2 +-
 4 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/config/module.config.php b/config/module.config.php
index da392d1..3596431 100644
--- a/config/module.config.php
+++ b/config/module.config.php
@@ -18,6 +18,11 @@ $settings = [
         200 => 'UnicaenAuth\Provider\Identity\Db',    // en 2e
         100 => 'UnicaenAuth\Provider\Identity\Ldap',  // en 3e @deprecated
     ],
+
+    /**
+     * Attribut LDAP utilisé pour le username des utilisateurs
+     */
+    'ldap_username' => 'supannaliaslogin',
 ];
 
 return [
diff --git a/config/unicaen-auth.global.php.dist b/config/unicaen-auth.global.php.dist
index 4e85777..b92e8ca 100644
--- a/config/unicaen-auth.global.php.dist
+++ b/config/unicaen-auth.global.php.dist
@@ -15,6 +15,12 @@ $settings = [
     'enable_privileges' => true,
 
     'entity_manager_name' => 'doctrine.entitymanager.orm_default', // nom du gestionnaire d'entités à utiliser
+
+    /**
+     * Attribut LDAP utilisé pour le username des utilisateurs
+     * A personnaliser au besoin
+     */
+    //'ldap_username' => 'supannaliaslogin',
 ];
 
 $config = [
diff --git a/src/UnicaenAuth/Options/ModuleOptions.php b/src/UnicaenAuth/Options/ModuleOptions.php
index 4d3b5fb..0ce96ee 100644
--- a/src/UnicaenAuth/Options/ModuleOptions.php
+++ b/src/UnicaenAuth/Options/ModuleOptions.php
@@ -19,6 +19,11 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
      */
     protected $saveLdapUserInDatabase = false;
 
+    /**
+     * @var string
+     */
+    protected $ldapUsername;
+
     /**
      * @var array
      */
@@ -33,7 +38,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
      * @var string
      */
     protected $entityManagerName = 'doctrine.entitymanager.orm_default';
-    
+
     /**
      * set usernames allowed to make usurpation
      *
@@ -72,7 +77,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
 
         return $this;
     }
-    
+
     /**
      * Retourne la valeur du flag spécifiant si l'utilisateur authentifié doit être
      * enregistré dans la base de données de l'appli
@@ -83,7 +88,33 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
     {
         return $this->saveLdapUserInDatabase;
     }
-    
+
+
+
+    /**
+     * @return string
+     */
+    public function getLdapUsername()
+    {
+        return $this->ldapUsername;
+    }
+
+
+
+    /**
+     * @param string $ldapUsername
+     *
+     * @return ModuleOptions
+     */
+    public function setLdapUsername($ldapUsername)
+    {
+        $this->ldapUsername = $ldapUsername;
+
+        return $this;
+    }
+
+
+
     /**
      * set cas connection params
      *
@@ -97,7 +128,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
 
         return $this;
     }
-    
+
     /**
      * get cas connection params
      *
@@ -107,7 +138,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
     {
         return $this->cas;
     }
-    
+
     /**
      * set shibboleth connection params
      *
@@ -131,7 +162,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
     {
         return $this->shibboleth;
     }
-    
+
     /**
      * @return string
      */
@@ -139,7 +170,7 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
     {
         return $this->entityManagerName;
     }
-    
+
     /**
      * @param string $entityManagerName
      *
diff --git a/src/UnicaenAuth/Service/User.php b/src/UnicaenAuth/Service/User.php
index 7b020a6..c1a483d 100644
--- a/src/UnicaenAuth/Service/User.php
+++ b/src/UnicaenAuth/Service/User.php
@@ -64,7 +64,7 @@ class User implements ServiceLocatorAwareInterface, EventManagerAwareInterface
 
         switch (true) {
             case $userData instanceof People:
-                $username = $userData->getSupannAliasLogin();
+                $username = $userData->getData($this->getOptions()->getLdapUsername());
                 $email = $userData->getMail();
                 $password = 'ldap';
                 $state = in_array('deactivated', ldap_explode_dn($userData->getDn(), 1)) ? 0 : 1;
-- 
GitLab