Skip to content

Commit

Permalink
fix(LDAP): ensure stored groups are formatted as simple list
Browse files Browse the repository at this point in the history
With array_unique it is possible that the keys are not in sequential order
but have gaps. json_encode then would store them as associative array,
which later on json_decode would result in a stdClass by default. This is
unexpected and would also contradict the return type hint.

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Dec 20, 2023
1 parent 4f7ed47 commit cacbcbe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ private function isUserOnLDAP(string $uid): bool {

protected function getCachedGroupsForUserId(string $uid): array {
$groupStr = $this->config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
return json_decode($groupStr) ?? [];
return json_decode($groupStr, true) ?? [];
}

/**
Expand Down Expand Up @@ -838,7 +838,7 @@ public function getUserGroups($uid): array {
return $groups;
}

$groups = array_unique($groups, SORT_LOCALE_STRING);
$groups = array_values(array_unique($groups, SORT_LOCALE_STRING));
$this->access->connection->writeToCache($cacheKey, $groups);

$groupStr = \json_encode($groups);
Expand Down

0 comments on commit cacbcbe

Please sign in to comment.