Skip to content

Commit 0ad97ac

Browse files
authored
Merge pull request #511 from dbarzin/dev
update login
2 parents 4421385 + ff04940 commit 0ad97ac

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ LDAP_TLS=false
7070
# Candidate attributes to identify the username entered in the form
7171
# Order matters: the first match wins.
7272
# OpenLDAP: uid, cn, mail ; AD: sAMAccountName, userPrincipalName, mail
73-
LDAP_LOGIN_ATTRIBUTE="uid,cn,mail,sAMAccountName,userPrincipalName"
73+
LDAP_LOGIN_ATTRIBUTES="uid,cn,mail,sAMAccountName,userPrincipalName"
7474

7575
##################################################
7676
# Socialite

app/Http/Controllers/Auth/LoginController.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
]);

app/Http/Controllers/UserController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function store(Request $request)
5858
$this->validate($request, [
5959
'login' => 'required|unique:users|min:1|max:30',
6060
'name' => 'required|min:1|max:90',
61-
'title' => 'required|min:1|max:30',
61+
'title' => 'nullable|min:1|max:30',
6262
'email' => 'required|unique:users|email:rfc',
63-
'role' => 'required',
63+
'role' => 'required|min:1|max:5',
6464
]);
6565

6666
// Custom password validation if LDAP is not enabled
@@ -138,9 +138,9 @@ public function update(Request $request, User $user)
138138
$this->validate($request, [
139139
'login' => 'required|min:1|max:30|unique:users,login,'.$user->id,
140140
'name' => 'required|min:1|max:90',
141-
'title' => 'required|min:1|max:30',
141+
'title' => 'nullable|min:1|max:30',
142142
'email' => 'required|email:rfc|unique:users,email,'.$user->id,
143-
'role' => 'required',
143+
'role' => 'min:1|max:5',
144144
]);
145145

146146
// Custom password validation if LDAP is not enabled

0 commit comments

Comments
 (0)