@@ -71,6 +71,26 @@ private function getUserWithAttributes(string $userName, array $attributes): ?ar
71
71
return $ users [0 ];
72
72
}
73
73
74
+ /**
75
+ * Build the user display name from the (potentially multiple) attributes defined by the configuration.
76
+ */
77
+ protected function getUserDisplayName (array $ userDetails , array $ displayNameAttrs , string $ defaultValue ): string
78
+ {
79
+ $ displayNameParts = [];
80
+ foreach ($ displayNameAttrs as $ dnAttr ) {
81
+ $ dnComponent = $ this ->getUserResponseProperty ($ userDetails , $ dnAttr , null );
82
+ if ($ dnComponent ) {
83
+ $ displayNameParts [] = $ dnComponent ;
84
+ }
85
+ }
86
+
87
+ if (empty ($ displayNameParts )) {
88
+ return $ defaultValue ;
89
+ }
90
+
91
+ return implode (' ' , $ displayNameParts );
92
+ }
93
+
74
94
/**
75
95
* Get the details of a user from LDAP using the given username.
76
96
* User found via configurable user filter.
@@ -81,11 +101,11 @@ public function getUserDetails(string $userName): ?array
81
101
{
82
102
$ idAttr = $ this ->config ['id_attribute ' ];
83
103
$ emailAttr = $ this ->config ['email_attribute ' ];
84
- $ displayNameAttr = $ this ->config ['display_name_attribute ' ];
104
+ $ displayNameAttrs = explode ( ' | ' , $ this ->config ['display_name_attribute ' ]) ;
85
105
$ thumbnailAttr = $ this ->config ['thumbnail_attribute ' ];
86
106
87
107
$ user = $ this ->getUserWithAttributes ($ userName , array_filter ([
88
- 'cn ' , 'dn ' , $ idAttr , $ emailAttr , $ displayNameAttr , $ thumbnailAttr ,
108
+ 'cn ' , 'dn ' , $ idAttr , $ emailAttr , ... $ displayNameAttrs , $ thumbnailAttr ,
89
109
]));
90
110
91
111
if (is_null ($ user )) {
@@ -95,7 +115,7 @@ public function getUserDetails(string $userName): ?array
95
115
$ userCn = $ this ->getUserResponseProperty ($ user , 'cn ' , null );
96
116
$ formatted = [
97
117
'uid ' => $ this ->getUserResponseProperty ($ user , $ idAttr , $ user ['dn ' ]),
98
- 'name ' => $ this ->getUserResponseProperty ($ user , $ displayNameAttr , $ userCn ),
118
+ 'name ' => $ this ->getUserDisplayName ($ user , $ displayNameAttrs , $ userCn ),
99
119
'dn ' => $ user ['dn ' ],
100
120
'email ' => $ this ->getUserResponseProperty ($ user , $ emailAttr , null ),
101
121
'avatar ' => $ thumbnailAttr ? $ this ->getUserResponseProperty ($ user , $ thumbnailAttr , null ) : null ,
0 commit comments