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

Commit e4995bd

Browse files
Update ues fix (#128)
* Fixed Updating UES in Perun
1 parent 1767f8f commit e4995bd

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ All notable changes to this project will be documented in this file.
1616
- Added required attribute 'listOfSps.serviceNameAttr' !!!
1717
- Add translation for multi-languages attributes
1818

19+
#### Fixed
20+
- Fixed Updating UES in Perun
21+
1922
## [v3.9.0]
2023
#### Added
2124
- Added facility capabilities to PerunEntitlement

lib/AdapterRpc.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,13 @@ public function updateUserExtSourceLastAccess($userExtSource)
493493

494494
public function getUserExtSourceAttributes($userExtSourceId, $attrNames)
495495
{
496-
return $this->connector->get('attributesManager', 'getAttributes', [
496+
$attrNamesMap = AttributeUtils::getRpcAttrNames($attrNames);
497+
498+
$perunAttrs = $this->connector->get('attributesManager', 'getAttributes', [
497499
'userExtSource' => $userExtSourceId,
498-
'attrNames' => $attrNames,
500+
'attrNames' => array_keys($attrNamesMap),
499501
]);
502+
return $this->getAttributes($perunAttrs, $attrNamesMap);
500503
}
501504

502505
public function setUserExtSourceAttributes($userExtSourceId, $attributes)
@@ -608,10 +611,11 @@ private function getAttributes($perunAttrs, $attrNamesMap)
608611
$perunAttrName = $perunAttr['namespace'] . ':' . $perunAttr['friendlyName'];
609612
$attributes[$attrNamesMap[$perunAttrName]] = [
610613
'id' => $perunAttr['id'],
611-
'name' => $perunAttrName,
614+
'name' => $attrNamesMap[$perunAttrName],
612615
'displayName' => $perunAttr['displayName'],
613616
'type' => $perunAttr['type'],
614-
'value' => $perunAttr['value']
617+
'value' => $perunAttr['value'],
618+
'friendlyName' => $perunAttr['friendlyName']
615619
];
616620
}
617621

lib/Auth/Process/UpdateUserExtSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public function __construct($config, $reserved)
3737
}
3838

3939
if (isset($config['arrayToStringConversion'])) {
40-
$this->attrsToConversion = AttributeUtils::getRpcAttrNames((array)$config['arrayToStringConversion']);
40+
$this->attrsToConversion = (array)$config['arrayToStringConversion'];
4141
} else {
4242
$this->attrsToConversion = [];
4343
}
4444

45-
$this->attrMap = AttributeUtils::getRpcAttrNames((array)$config['attrMap']);
45+
$this->attrMap = (array)$config['attrMap'];
4646
}
4747

4848
public function process(&$request)

www/updateUes.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
$attrsToConversion = $body['attrsToConversion'];
2020
$perunUserId = $body['perunUserId'];
2121

22-
const UES_ATTR_NMS = 'urn:perun:ues:attribute-def:def:';
22+
const UES_ATTR_NMS = 'urn:perun:ues:attribute-def:def';
2323

2424
try {
2525
$userExtSource = $adapter->getUserExtSource(
@@ -37,7 +37,7 @@
3737
$attributesFromPerunRaw = $adapter->getUserExtSourceAttributes($userExtSource['id'], array_keys($attrMap));
3838
$attributesFromPerun = [];
3939
foreach ($attributesFromPerunRaw as $attributeFromPerunRaw) {
40-
$attributesFromPerun[$attributeFromPerunRaw['friendlyName']] = $attributeFromPerunRaw;
40+
$attributesFromPerun[$attributeFromPerunRaw['name']] = $attributeFromPerunRaw;
4141
}
4242

4343
if ($attributesFromPerun === null) {
@@ -50,12 +50,12 @@
5050

5151
foreach ($attributesFromPerun as $attribute) {
5252

53-
$attrName = UES_ATTR_NMS . $attribute['friendlyName'];
53+
$attrName = $attribute['name'];
5454

5555
if (isset($attrMap[$attrName], $attributesFromIdP[$attrMap[$attrName]])) {
5656
$attr = $attributesFromIdP[$attrMap[$attrName]];
5757

58-
if (in_array(UES_ATTR_NMS . $attribute['friendlyName'], $attrsToConversion)) {
58+
if (in_array($attrName, $attrsToConversion)) {
5959
$arrayAsString = [''];
6060
foreach ($attr as $value) {
6161
$arrayAsString[0] .= $value . ';';
@@ -79,13 +79,19 @@
7979
}
8080
if ($valueFromIdP !== $attribute['value']) {
8181
$attribute['value'] = $valueFromIdP;
82+
$attribute['namespace'] = UES_ATTR_NMS;
8283
array_push($attributesToUpdate, $attribute);
8384
}
8485
}
8586
}
8687

88+
$attributesToUpdateFinal = [];
8789
if (!empty($attributesToUpdate)) {
88-
$adapter->setUserExtSourceAttributes($userExtSource['id'], $attributesToUpdate);
90+
foreach ($attributesToUpdate as $attribute) {
91+
$attribute['name'] = UES_ATTR_NMS . ":" . $attribute['friendlyName'];
92+
array_push($attributesToUpdateFinal, $attribute);
93+
}
94+
$adapter->setUserExtSourceAttributes($userExtSource['id'], $attributesToUpdateFinal);
8995
}
9096

9197
$adapter->updateUserExtSourceLastAccess($userExtSource['id']);

0 commit comments

Comments
 (0)