Skip to content

Commit 26f8cfe

Browse files
authored
Merge pull request #512 from dbarzin/dev
Dev
2 parents 0ad97ac + 2de68ca commit 26f8cfe

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

app/Exports/AttributesExport.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public function headings(): array
2121
];
2222
}
2323

24-
public function styles(Worksheet $sheet)
24+
public function styles(Worksheet $_sheet)
2525
{
26-
$sheet = null;
2726
// Return
2827
return [
2928
// Style the first row as bold text.

app/Http/Controllers/Auth/LoginController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ public function username()
6363
*/
6464
protected function ldapBindAndGetUser(string $appUsername, string $password): ?LdapEntry
6565
{
66-
6766
try {
6867
$query = LdapEntry::query();
6968

7069
// Optionnel : restreindre à une OU si configuré
71-
$base = config('app.ldap_users_base_dn', env('LDAP_USERS_BASE_DN'));
70+
$base = config('app.ldap_users_base_dn', config('app.ldap_users_base_dn'));
7271
if ($base) {
7372
$query->in($base);
7473
}
@@ -86,12 +85,12 @@ protected function ldapBindAndGetUser(string $appUsername, string $password): ?L
8685
}
8786
}
8887

89-
\Log::debug("LDAP dn: " . $query->getDn() . " query: " . $query->getQuery());
88+
\Log::debug('LDAP dn: ' . $query->getDn() . ' query: ' . $query->getQuery());
9089

9190
/** @var LdapEntry|null $ldapUser */
9291
$ldapUser = $query->first();
9392
if (! $ldapUser) {
94-
\Log::debug("LDAP user not found !");
93+
\Log::debug('LDAP user not found !');
9594
return null;
9695
}
9796

@@ -149,8 +148,8 @@ protected function attemptLogin(Request $request)
149148
if (! $local && $autoProvision) {
150149
// Minimal safe provisioning – adapt attributes to your schema
151150
$local = User::create([
152-
'name' => $ldapUser->getFirstAttribute('cn') ?: $identifier,
153-
'email' => $ldapUser->getFirstAttribute('mail') ?: 'user@localhost.local',
151+
'name' => $ldapUser->getFirstAttribute('cn') ?? $identifier,
152+
'email' => $ldapUser->getFirstAttribute('mail') ?? 'user@localhost.local',
154153
'login' => $identifier,
155154
'role' => 5, // Auditee
156155
// Store a random password so DB auth is not accidentally usable unless you set one explicitly

app/Http/Controllers/ReportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private function generateMadeControlTable(
244244

245245
foreach ($controls as $control) {
246246
$table->addRow();
247-
$table->addCell(2500)->addText($control->measures()->implode('clause', ', '));
247+
$table->addCell(2500)->addText($control->measures()->get()->implode('clause', ', '));
248248
$table->addCell(12500)->addText(str_replace('&', 'x', $control->name));
249249
$table->addCell(2800)->addText($control->realisation_date, null, ['align' => 'center']);
250250
$table->addCell(12500)->addText($control->scope);

app/Http/Controllers/SocialiteController.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class SocialiteController extends Controller
1818
{
1919
public const ROLES_MAP = [
2020
//'admin' => '1',
21-
'user' => '2',
22-
'auditee' => '5',
23-
'auditor' => '3',
21+
'user' => 2,
22+
'auditee' => 5,
23+
'auditor' => 3,
2424
//'api' => '4',
2525
];
2626

@@ -65,19 +65,19 @@ public function callback(Request $_request, string $provider)
6565

6666
// Get additionnal config for current provider
6767
$config_name = 'services.socialite_controller.'.$provider;
68-
$allow_create_user = false;
69-
$allow_update_user = false;
68+
$allow_createUser = false;
69+
$allow_updateUser = false;
7070
if (config($config_name)) {
71-
$allow_create_user = config($config_name.'.allow_create_user', $allow_create_user);
72-
$allow_update_user = config($config_name.'.allow_update_user', $allow_update_user);
71+
$allow_createUser = config($config_name.'.allow_createUser', $allow_createUser);
72+
$allow_updateUser = config($config_name.'.allow_updateUser', $allow_updateUser);
7373
}
74-
Log::debug('CONFIG: allow_create_user='.($allow_create_user ? 'true' : 'false'));
75-
Log::debug('CONFIG: allow_update_user='.($allow_update_user ? 'true' : 'false'));
74+
Log::debug('CONFIG: allow_createUser='.($allow_createUser ? 'true' : 'false'));
75+
Log::debug('CONFIG: allow_updateUser='.($allow_updateUser ? 'true' : 'false'));
7676

7777
$role_claim = null;
7878
$default_role = null;
7979

80-
if ($allow_create_user || $allow_update_user) {
80+
if ($allow_createUser || $allow_updateUser) {
8181
$role_claim = config($config_name.'.role_claim', '');
8282
Log::debug('CONFIG: role_claim='.$role_claim);
8383
$default_role = config($config_name.'.default_role', '');
@@ -96,8 +96,8 @@ public function callback(Request $_request, string $provider)
9696
}
9797

9898
// If not exist and allow to create user then create it
99-
if (! $user && $allow_create_user) {
100-
$user = $this->create_user($socialite_user, $provider, $role_claim, $default_role);
99+
if (! $user && $allow_createUser) {
100+
$user = $this->createUser($socialite_user, $provider, $role_claim, $default_role);
101101
}
102102

103103
// If no user redirect to login with error message
@@ -106,8 +106,8 @@ public function callback(Request $_request, string $provider)
106106
return redirect('login')->withErrors(['socialite' => trans('cruds.login.error.user_not_exist') ]);
107107
}
108108

109-
if ($allow_update_user) {
110-
$this->update_user($user, $socialite_user, $provider, $role_claim, $default_role);
109+
if ($allow_updateUser) {
110+
$this->updateUser($user, $socialite_user, $provider, $role_claim, $default_role);
111111
}
112112

113113
Log::info("User '{$user->login}' login with {$provider} provider");
@@ -123,11 +123,11 @@ public function callback(Request $_request, string $provider)
123123
/**
124124
* Create user with claims provided.
125125
*/
126-
protected function create_user(SocialiteUser $socialite_user, string $provider, string $role_claim, string $default_role): User
126+
protected function createUser(SocialiteUser $socialite_user, string $provider, string $role_claim, string $default_role): User|null
127127
{
128128
$user = new User();
129129

130-
$user->login = $this->get_user_login($socialite_user);
130+
$user->login = $this->getUserLogin($socialite_user);
131131
$user->name = $socialite_user->name;
132132
$user->email = $socialite_user->email;
133133
$user->title = "User provide by {$provider}";
@@ -152,11 +152,11 @@ protected function create_user(SocialiteUser $socialite_user, string $provider,
152152
/**
153153
* Update user with claims providid.
154154
*/
155-
protected function update_user(User $user, SocialiteUser $socialite_user, string $provider, string $role_claim, string $default_role)
155+
protected function updateUser(User $user, SocialiteUser $socialite_user, string $provider, string $role_claim, string $default_role)
156156
{
157157
$updated = false;
158158

159-
$login = $this->get_user_login($socialite_user);
159+
$login = $this->getUserLogin($socialite_user);
160160
if ($login !== $user->login) {
161161
Log::debug("Login changed {$user->login} => {$login}");
162162
$user->login = $login;
@@ -193,7 +193,7 @@ protected function update_user(User $user, SocialiteUser $socialite_user, string
193193
/**
194194
* Return user's login.
195195
*/
196-
private function get_user_login(SocialiteUser $socialite_user): string
196+
private function getUserLogin(SocialiteUser $socialite_user): string
197197
{
198198
// set login with preferred_username, otherwise use id
199199
if ($socialite_user->offsetExists('preferred_username')) {
@@ -207,15 +207,15 @@ private function get_user_login(SocialiteUser $socialite_user): string
207207
* If no role provided, use $default_role value.
208208
* If $default_role is null and no role provided, null return.
209209
*/
210-
private function get_user_role(SocialiteUser $socialite_user, string $role_claim, string $default_role): string
210+
private function get_user_role(SocialiteUser $socialite_user, string $role_claim, string $default_role): int|null
211211
{
212212
$role_name = '';
213-
if (! empty($role_claim)) {
213+
if ($role_claim !== '') {
214214
$role_name = $this->get_claim_value($socialite_user, $role_claim);
215215
Log::debug("Provided claim '{$role_claim}'='{$role_name}'");
216216
}
217217
if (! array_key_exists($role_name, self::ROLES_MAP)) {
218-
if (! empty($default_role)) {
218+
if ($default_role !== '') {
219219
$role_name = $default_role;
220220
} else {
221221
Log::error("No default role set! A valid role must be provided. role='{$role_name}'");

app/Models/Control.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
use App\Traits\Auditable;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8+
use Illuminate\Database\Eloquent\Relations\HasMany;
79
use Illuminate\Support\Facades\Auth;
810
use Illuminate\Support\Facades\DB;
911
use Illuminate\Support\Facades\File;
10-
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11-
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
12-
use Illuminate\Database\Eloquent\Relations\HasMany;
13-
class Control extends Model
1412

13+
class Control extends Model
1514
{
1615
use Auditable;
1716

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
'ldap_fallback_local' => (bool) env('LDAP_FALLBACK_LOCAL', true),
149149
'ldap_auto_provision' => (bool) env('LDAP_AUTO_PROVISION', false),
150150
'ldap_login_attributes' => env('LDAP_LOGIN_ATTRIBUTES', 'uid,cn,mail,sAMAccountName,userPrincipalName'),
151+
'ldap_users_base_dn' => env('LDAP_USERS_BASE_DN'),
151152

152153
/*
153154
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)