From: Dan Brown Date: Mon, 24 May 2021 16:06:50 +0000 (+0100) Subject: Merge branch 'master' of https://github.com/jasonhoule/BookStack into jasonhoule... X-Git-Tag: v21.05~1^2~20 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/85db812feaae5f36ea6214931cec4adb67a9cb39?hp=-c Merge branch 'master' of https://github.com/jasonhoule/BookStack into jasonhoule-master --- 85db812feaae5f36ea6214931cec4adb67a9cb39 diff --combined app/Auth/Access/Guards/LdapSessionGuard.php index cabbfbbcb,f67c04f82..a9802054a --- a/app/Auth/Access/Guards/LdapSessionGuard.php +++ b/app/Auth/Access/Guards/LdapSessionGuard.php @@@ -5,12 -5,14 +5,12 @@@ namespace BookStack\Auth\Access\Guards use BookStack\Auth\Access\LdapService; use BookStack\Auth\Access\RegistrationService; use BookStack\Auth\User; -use BookStack\Auth\UserRepo; use BookStack\Exceptions\LdapException; use BookStack\Exceptions\LoginAttemptException; use BookStack\Exceptions\LoginAttemptEmailNeededException; use BookStack\Exceptions\UserRegistrationException; use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Contracts\Session\Session; -use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; class LdapSessionGuard extends ExternalBaseSessionGuard @@@ -21,13 -23,13 +21,13 @@@ /** * LdapSessionGuard constructor. */ - public function __construct($name, + public function __construct( + $name, UserProvider $provider, Session $session, LdapService $ldapService, RegistrationService $registrationService - ) - { + ) { $this->ldapService = $ldapService; parent::__construct($name, $provider, $session, $registrationService); } @@@ -115,6 -117,17 +115,16 @@@ '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; } - } diff --combined app/Auth/Access/LdapService.php index a438c0984,a7ee3b374..c5b586b4d --- a/app/Auth/Access/LdapService.php +++ b/app/Auth/Access/LdapService.php @@@ -76,6 -76,7 +76,7 @@@ class LdapService extends ExternalAuthS $idAttr = $this->config['id_attribute']; $emailAttr = $this->config['email_attribute']; $displayNameAttr = $this->config['display_name_attribute']; + $thumbnailAttr = $this->config['thumbnail_attribute']; $user = $this->getUserWithAttributes($userName, ['cn', 'dn', $idAttr, $emailAttr, $displayNameAttr]); @@@ -85,10 -86,11 +86,11 @@@ $userCn = $this->getUserResponseProperty($user, 'cn', null); $formatted = [ - 'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']), - 'name' => $this->getUserResponseProperty($user, $displayNameAttr, $userCn), - 'dn' => $user['dn'], + 'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']), + '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']) { @@@ -187,8 -189,8 +189,8 @@@ throw new LdapException(trans('errors.ldap_extension_not_installed')); } - // Check if TLS_INSECURE is set. The handle is set to NULL due to the nature of - // the LDAP_OPT_X_TLS_REQUIRE_CERT option. It can only be set globally and not per handle. + // Disable certificate verification. + // This option works globally and must be set before a connection is created. if ($this->config['tls_insecure']) { $this->ldap->setOption(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER); } @@@ -205,14 -207,6 +207,14 @@@ $this->ldap->setVersion($ldapConnection, $this->config['version']); } + // Start and verify TLS if it's enabled + if ($this->config['start_tls']) { + $started = $this->ldap->startTls($ldapConnection); + if (!$started) { + throw new LdapException('Could not start TLS connection'); + } + } + $this->ldapConnection = $ldapConnection; return $this->ldapConnection; } diff --combined app/Config/services.php index 699339614,230234e4c..7fac1f51c --- a/app/Config/services.php +++ b/app/Config/services.php @@@ -132,7 -132,8 +132,9 @@@ return 'group_attribute' => env('LDAP_GROUP_ATTRIBUTE', 'memberOf'), 'remove_from_groups' => env('LDAP_REMOVE_FROM_GROUPS', false), 'tls_insecure' => env('LDAP_TLS_INSECURE', false), + 'start_tls' => env('LDAP_START_TLS', false), + 'import_thumbnail_photos' => env('LDAP_IMPORT_THUMBNAIL_PHOTOS', false), + 'thumbnail_attribute' => env('LDAP_THUMBNAIL_ATTRIBUTE', 'thumbnailPhoto'), ], ];