mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-24 13:00:53 +08:00
Added support for concatenating multiple LDAP attributes in displayName
This commit is contained in:
parent
e4ca3bf132
commit
72d9ffd8b4
@ -71,6 +71,28 @@ class LdapService
|
|||||||
return $users[0];
|
return $users[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the display name.
|
||||||
|
*/
|
||||||
|
protected function getUserDisplayName(array $displayNameAttr, array $userDetails, string $defaultValue): string
|
||||||
|
{
|
||||||
|
$displayName = [];
|
||||||
|
foreach ($displayNameAttr as $dnAttr) {
|
||||||
|
$dnComponent = $this->getUserResponseProperty($userDetails, $dnAttr, null);
|
||||||
|
if ($dnComponent !== null) {
|
||||||
|
$displayName[] = $dnComponent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($displayName) == 0) {
|
||||||
|
$displayName = $defaultValue;
|
||||||
|
} else {
|
||||||
|
$displayName = implode(' ', $displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $displayName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the details of a user from LDAP using the given username.
|
* Get the details of a user from LDAP using the given username.
|
||||||
* User found via configurable user filter.
|
* User found via configurable user filter.
|
||||||
@ -84,9 +106,9 @@ class LdapService
|
|||||||
$displayNameAttr = $this->config['display_name_attribute'];
|
$displayNameAttr = $this->config['display_name_attribute'];
|
||||||
$thumbnailAttr = $this->config['thumbnail_attribute'];
|
$thumbnailAttr = $this->config['thumbnail_attribute'];
|
||||||
|
|
||||||
$user = $this->getUserWithAttributes($userName, array_filter([
|
$user = $this->getUserWithAttributes($userName, array_filter(array_merge($displayNameAttr, [
|
||||||
'cn', 'dn', $idAttr, $emailAttr, $displayNameAttr, $thumbnailAttr,
|
'cn', 'dn', $idAttr, $emailAttr, $thumbnailAttr,
|
||||||
]));
|
])));
|
||||||
|
|
||||||
if (is_null($user)) {
|
if (is_null($user)) {
|
||||||
return null;
|
return null;
|
||||||
@ -95,7 +117,7 @@ class LdapService
|
|||||||
$userCn = $this->getUserResponseProperty($user, 'cn', null);
|
$userCn = $this->getUserResponseProperty($user, 'cn', null);
|
||||||
$formatted = [
|
$formatted = [
|
||||||
'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']),
|
'uid' => $this->getUserResponseProperty($user, $idAttr, $user['dn']),
|
||||||
'name' => $this->getUserResponseProperty($user, $displayNameAttr, $userCn),
|
'name' => $this->getUserDisplayName($displayNameAttr, $user, $userCn),
|
||||||
'dn' => $user['dn'],
|
'dn' => $user['dn'],
|
||||||
'email' => $this->getUserResponseProperty($user, $emailAttr, null),
|
'email' => $this->getUserResponseProperty($user, $emailAttr, null),
|
||||||
'avatar' => $thumbnailAttr ? $this->getUserResponseProperty($user, $thumbnailAttr, null) : null,
|
'avatar' => $thumbnailAttr ? $this->getUserResponseProperty($user, $thumbnailAttr, null) : null,
|
||||||
|
@ -127,7 +127,7 @@ return [
|
|||||||
'version' => env('LDAP_VERSION', false),
|
'version' => env('LDAP_VERSION', false),
|
||||||
'id_attribute' => env('LDAP_ID_ATTRIBUTE', 'uid'),
|
'id_attribute' => env('LDAP_ID_ATTRIBUTE', 'uid'),
|
||||||
'email_attribute' => env('LDAP_EMAIL_ATTRIBUTE', 'mail'),
|
'email_attribute' => env('LDAP_EMAIL_ATTRIBUTE', 'mail'),
|
||||||
'display_name_attribute' => env('LDAP_DISPLAY_NAME_ATTRIBUTE', 'cn'),
|
'display_name_attribute' => explode('|', env('LDAP_DISPLAY_NAME_ATTRIBUTE', 'cn')),
|
||||||
'follow_referrals' => env('LDAP_FOLLOW_REFERRALS', false),
|
'follow_referrals' => env('LDAP_FOLLOW_REFERRALS', false),
|
||||||
'user_to_groups' => env('LDAP_USER_TO_GROUPS', false),
|
'user_to_groups' => env('LDAP_USER_TO_GROUPS', false),
|
||||||
'group_attribute' => env('LDAP_GROUP_ATTRIBUTE', 'memberOf'),
|
'group_attribute' => env('LDAP_GROUP_ATTRIBUTE', 'memberOf'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user