@@ -63,12 +63,19 @@ public function username()
6363 */
6464 protected function ldapBindAndGetUser (string $ appUsername , string $ password ): ?LdapEntry
6565 {
66- // Recherche agnostique du schéma : AD ou OpenLDAP
67- // On construit une requête OR sur une liste d'attributs configurables
68- $ attrs = array_filter (array_map ('trim ' , explode (', ' , config ('ldap_login_attributes ' ))));
6966
7067 try {
7168 $ query = LdapEntry::query ();
69+
70+ // Optionnel : restreindre à une OU si configuré
71+ $ base = config ('app.ldap_users_base_dn ' , env ('LDAP_USERS_BASE_DN ' ));
72+ if ($ base ) {
73+ $ query ->in ($ base );
74+ }
75+
76+ // Filtre de localisation : OR sur les attributs pertinents
77+ $ attrs = array_filter (array_map ('trim ' , explode (', ' , config ('app.ldap_login_attributes ' ))));
78+
7279 $ first = true ;
7380 foreach ($ attrs as $ attr ) {
7481 if ($ first ) {
@@ -79,9 +86,12 @@ protected function ldapBindAndGetUser(string $appUsername, string $password): ?L
7986 }
8087 }
8188
89+ \Log::debug ("LDAP dn: " . $ query ->getDn () . " query: " . $ query ->getQuery ());
90+
8291 /** @var LdapEntry|null $ldapUser */
8392 $ ldapUser = $ query ->first ();
8493 if (! $ ldapUser ) {
94+ \Log::debug ("LDAP user not found ! " );
8595 return null ;
8696 }
8797
@@ -140,8 +150,9 @@ protected function attemptLogin(Request $request)
140150 // Minimal safe provisioning – adapt attributes to your schema
141151 $ local = User::create ([
142152 'name ' => $ ldapUser ->getFirstAttribute ('cn ' ) ?: $ identifier ,
143- 'email ' => $ ldapUser ->getFirstAttribute ('mail ' ) ?: null ,
153+ 'email ' => $ ldapUser ->getFirstAttribute ('mail ' ) ?: ' user@localhost.local ' ,
144154 'login ' => $ identifier ,
155+ 'role ' => 5 , // Auditee
145156 // Store a random password so DB auth is not accidentally usable unless you set one explicitly
146157 'password ' => bcrypt (str ()->random (32 )),
147158 ]);
0 commit comments