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

Commit d2c27dd

Browse files
committed
Fixed the bug in 'getEntitylesAttribute' function
* Fixed the bug in 'getEntitylesAttribute' function to return correct value of Entityless attribute. Before this fix the method was usable only for EntitylessAttribute with type LinkedHashMap. Now the function is usable for all types of PerunAttributes.
1 parent 9e3dbb3 commit d2c27dd

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
#### Fixed
6+
- Fixed the bug in 'getEntitylesAttribute' function to return correct value of Entityless attribute
57

68
## [v3.3.0]
79
#### Added

lib/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ abstract public function getUserAttributes($user, $attrNames);
9999

100100
/**
101101
* @param string $attrName
102-
* @return array of all entityless attributes with attrName (for all namespaces of same attribute).
102+
* @return map of all entityless attributes with attrName (for all namespaces of same attribute).
103103
*/
104104
abstract public function getEntitylessAttribute($attrName);
105105

lib/AdapterRpc.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,25 @@ public function getUserAttributes($user, $attrNames)
250250

251251
public function getEntitylessAttribute($attrName)
252252
{
253-
$perunAttrs = $this->connector->get('attributesManager', 'getEntitylessAttributes', [
253+
$attributes = [];
254+
255+
$perunAttrValues = $this->connector->get('attributesManager', 'getEntitylessAttributes', [
254256
'attrName' => $attrName,
255257
]);
256258

257-
$attributes = [];
258-
foreach ($perunAttrs as $perunAttr) {
259-
$attributes[key($perunAttr['value'])] = $perunAttr['value'][key($perunAttr['value'])];
259+
if (!isset($perunAttrValues[0]['id'])) {
260+
return $attributes;
261+
}
262+
$attrId = $perunAttrValues[0]['id'];
263+
264+
$perunAttrKeys = $this->connector->get('attributesManager', 'getEntitylessKeys', [
265+
'attributeDefinition' => $attrId,
266+
]);
267+
268+
for ($i = 0, $iMax = count($perunAttrKeys); $i < $iMax; $i++) {
269+
$key = $perunAttrKeys[$i];
270+
$value = $perunAttrValues[$i];
271+
$attributes[$key] = $value;
260272
}
261273

262274
return $attributes;

lib/Auth/Process/ForceAup.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ public function process(&$request)
151151
return;
152152
}
153153

154-
$perunAups = $this->adapter->getEntitylessAttribute($this->perunAupsAttr);
154+
$perunAupsAttr = $this->adapter->getEntitylessAttribute($this->perunAupsAttr);
155+
156+
$perunAups = [];
157+
foreach ($perunAupsAttr as $key => $attr) {
158+
$perunAups[$key] = $attr['value'];
159+
}
155160

156161
$userAups = $this->adapter->getUserAttributes(
157162
$user,

0 commit comments

Comments
 (0)