Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit d892ca9

Browse files
Dominik Frantisek Bucikmelanger
authored andcommitted
fix: fix processing attr val of map type in LDAP
- previous implementation did not convert map value to associative array
1 parent 23f7c13 commit d892ca9

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

lib/AdapterLdap.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ class AdapterLdap extends Adapter
5252

5353
public const TYPE_BOOL = 'bool';
5454

55+
public const TYPE_ARRAY = 'array';
56+
57+
//TODO: remove in future major release and replace with self::TYPE_ARRAY
5558
public const TYPE_MAP = 'map';
5659

60+
public const TYPE_DICTIONARY = 'dictionary';
61+
5762
public const INTERNAL_ATTR_NAME = 'internalAttrName';
5863

5964
public const TYPE = 'type';
@@ -272,7 +277,7 @@ public function getUserAttributesValues($user, $attributes)
272277

273278
foreach (array_keys($attrTypeMap) as $attrName) {
274279
$attributesValues[$attrTypeMap[$attrName][self::INTERNAL_ATTR_NAME]] =
275-
$this->setAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
280+
$this->resolveAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
276281
}
277282

278283
return $attributesValues;
@@ -330,7 +335,7 @@ public function getVoAttributesValues($vo, $attributes)
330335

331336
foreach (array_keys($attrTypeMap) as $attrName) {
332337
$attributesValues[$attrTypeMap[$attrName][self::INTERNAL_ATTR_NAME]] =
333-
$this->setAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
338+
$this->resolveAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
334339
}
335340

336341
return $attributesValues;
@@ -365,7 +370,7 @@ public function getFacilityAttributesValues($facility, $attributes)
365370

366371
foreach (array_keys($attrTypeMap) as $attrName) {
367372
$attributesValues[$attrTypeMap[$attrName][self::INTERNAL_ATTR_NAME]] =
368-
$this->setAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
373+
$this->resolveAttrValue($attrTypeMap, $perunAttrs[0], $attrName);
369374
}
370375

371376
return $attributesValues;
@@ -533,20 +538,34 @@ public function getFacilityCapabilities($entityId)
533538
return $facilityCapabilities['capabilities'];
534539
}
535540

536-
private function setAttrValue($attrsNameTypeMap, $attrsFromLdap, $attr)
541+
private function resolveAttrValue($attrsNameTypeMap, $attrsFromLdap, $attr)
537542
{
538-
if (! array_key_exists($attr, $attrsFromLdap) && $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_BOOL) {
539-
return false;
540-
} elseif (! array_key_exists(
541-
$attr,
542-
$attrsFromLdap
543-
) && $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP) {
544-
return [];
545-
} elseif (array_key_exists($attr, $attrsFromLdap) && $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP) {
546-
return $attrsFromLdap[$attr];
547-
} elseif (array_key_exists($attr, $attrsFromLdap)) {
543+
if (! array_key_exists($attr, $attrsFromLdap)) {
544+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_BOOL) {
545+
return false;
546+
} elseif ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP
547+
|| $attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY
548+
) {
549+
return [];
550+
}
551+
} else {
552+
if ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_MAP) {
553+
return $attrsFromLdap[$attr];
554+
} elseif ($attrsNameTypeMap[$attr][self::TYPE] === self::TYPE_DICTIONARY) {
555+
return $this->convertToMap($attrsFromLdap[$attr]);
556+
}
548557
return $attrsFromLdap[$attr][0];
549558
}
550559
return null;
551560
}
561+
562+
private function convertToMap($attrValue)
563+
{
564+
$result = [];
565+
foreach ($attrValue as $sub) {
566+
list($key, $value) = explode('=', $sub, 2);
567+
$result[$key] = $value;
568+
}
569+
return $result;
570+
}
552571
}

0 commit comments

Comments
 (0)