Skip to content

Commit cacbcbe

Browse files
committed
fix(LDAP): ensure stored groups are formatted as simple list
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 <[email protected]>
1 parent 4f7ed47 commit cacbcbe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ private function isUserOnLDAP(string $uid): bool {
685685

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

691691
/**
@@ -838,7 +838,7 @@ public function getUserGroups($uid): array {
838838
return $groups;
839839
}
840840

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

844844
$groupStr = \json_encode($groups);

0 commit comments

Comments
 (0)