]> BookStack Code Mirror - bookstack/commitdiff
Import thumbnail photos when LDAP users are created.
authorJason Houle <redacted>
Mon, 12 Oct 2020 16:33:55 +0000 (12:33 -0400)
committerJason Houle <redacted>
Mon, 12 Oct 2020 16:33:55 +0000 (12:33 -0400)
app/Auth/Access/Guards/LdapSessionGuard.php
app/Auth/Access/LdapService.php
app/Config/services.php

index 652141c0ce280963abc337f20cd62e19d79e6f40..f67c04f8224d82072aa0cfc9fc765e18670df40f 100644 (file)
@@ -117,7 +117,17 @@ class LdapSessionGuard extends ExternalBaseSessionGuard
             'password' => Str::random(32),
         ];
 
-        return $this->registrationService->registerUser($details, null, false);
+        $user = $this->registrationService->registerUser($details, null, false);
+
+        if (config('services.ldap.import_thumbnail_photos')) {
+            $imageService = app()->make(ImageService::class);
+            $image = $imageService->saveNewFromBase64Uri('data:image/jpg;base64,'.base64_encode($ldapUserDetails['avatar']), $ldapUserDetails['uid'].'.jpg', 'user');
+
+            $user['image_id'] = $image->id;
+            $user->save();
+        }
+
+        return $user;
     }
 
 }
index 92234edcf906bc2934a47443af011de388d2f853..47dc24532864ec61e722005fafee8c7c796f73b9 100644 (file)
@@ -89,6 +89,7 @@ class LdapService extends ExternalAuthService
             'name'  => $this->getUserResponseProperty($user, $displayNameAttr, $userCn),
             'dn'    => $user['dn'],
             'email' => $this->getUserResponseProperty($user, $emailAttr, null),
+            'avatar'=> $this->getUserResponseProperty($user, $thumbnailAttr, null),
         ];
 
         if ($this->config['dump_user_details']) {
index fcde621d2b5296bd9239085adc6409d7d39784a3..230234e4c3e43a6d7a6979528efa3429f658ecf7 100644 (file)
@@ -132,6 +132,8 @@ return [
         'group_attribute' => env('LDAP_GROUP_ATTRIBUTE', 'memberOf'),
         'remove_from_groups' => env('LDAP_REMOVE_FROM_GROUPS', false),
         'tls_insecure' => env('LDAP_TLS_INSECURE', false),
+        'import_thumbnail_photos' => env('LDAP_IMPORT_THUMBNAIL_PHOTOS', false),
+        'thumbnail_attribute' => env('LDAP_THUMBNAIL_ATTRIBUTE', 'thumbnailPhoto'),
     ],
 
 ];