Skip to content

Commit

Permalink
fix: do no hit LDAP if no exposed attribute is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez committed Aug 30, 2024
1 parent 2b0f208 commit 720eeb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public function registerEventListener() {

try {
$attrs = $uProxy->getExposedAttributes($targetUser->getUID());
if ($attrs === null || $attrs === false) {
// either there are no exposed attributes or the user isn't found in LDAP
// if there are no exposed attributes configured, we won't contact the LDAP server,
// so we don't know if the user really exists.
$event->setAttributes('user_ldap_state', 'Unknown');
return;
}

$event->setAttributes('user_ldap_state', 'OK');
foreach ($attrs as $key => $value) {
Expand Down
11 changes: 8 additions & 3 deletions lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,21 @@ public function getAvatar($uid) {
* only the first value will be returned.
*
* @param string $uid
* @return array<string,string>|false key -> value map containing the attributes
* and their values. False if the user isn't found
* @return array<string,string>|false|null key -> value map containing the
* attributes and their values. False if the user isn't found. Null if no
* attribute is configured
*/
public function getExposedAttributes($uid) {
$exposedAttrs = $this->userManager->getExposedAttributes();
if (\count($exposedAttrs) === 0) {
return null;
}

$userEntry = $this->userManager->getCachedEntry($uid);
if ($userEntry === null) {
return false;
}

$exposedAttrs = $this->userManager->getExposedAttributes();
$attrs = [];
foreach ($exposedAttrs as $attr) {
$attrs[$attr] = $userEntry->getAttribute($attr);
Expand Down

0 comments on commit 720eeb6

Please sign in to comment.