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

Commit 063fa34

Browse files
Fixed bug in PerunAttributes.php (#141)
* Fixed bug in PerunAttributes.php for PARTIAL mode when mapping one Perun attribute to more internal attributes caused getting attributes from Perun every time.
1 parent 92afceb commit 063fa34

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ All notable changes to this project will be documented in this file.
1111
#### Added
1212
- Added extended PerunEntitlements
1313

14+
#### Fixed
15+
- Fixed bug in PerunAttributes.php for PARTIAL mode when mapping one Perun attribute to more internal attributes
16+
caused getting attributes from Perun every time.
17+
1418
## [v4.1.1]
1519
#### Fixed
1620
- Fixed bad log message in PerunIdentity in mode USERONLY

lib/Auth/Process/PerunAttributes.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace SimpleSAML\Module\perun\Auth\Process;
44

5+
use SimpleSAML\Auth\ProcessingFilter;
56
use SimpleSAML\Module\perun\Adapter;
6-
use SimpleSAML\Module\perun\AttributeUtils;
77
use SimpleSAML\Error\Exception;
88
use SimpleSAML\Logger;
9+
use SimpleSAML\Module\perun\model\User;
910

1011
/**
1112
* Class PerunAttributes
@@ -19,7 +20,7 @@
1920
*
2021
* @author Ondrej Velisek <[email protected]>
2122
*/
22-
class PerunAttributes extends \SimpleSAML\Auth\ProcessingFilter
23+
class PerunAttributes extends ProcessingFilter
2324
{
2425
private $attrMap;
2526
private $interface;
@@ -63,8 +64,6 @@ public function __construct($config, $reserved)
6364

6465
public function process(&$request)
6566
{
66-
assert(is_array($request));
67-
6867
if (isset($request['perun']['user'])) {
6968
$user = $request['perun']['user'];
7069
} else {
@@ -81,17 +80,42 @@ public function process(&$request)
8180
} elseif ($this->mode === self::MODE_PARTIAL) {
8281
// Check if attribute has some value
8382
foreach ($this->attrMap as $attrName => $attrValue) {
84-
if (isset($request['Attributes'][$attrValue])) {
85-
$attr = $request['Attributes'][$attrValue];
86-
if (empty($attr)) {
83+
if (!is_array($attrValue)) {
84+
$attrValue = [$attrValue];
85+
}
86+
foreach ($attrValue as $value) {
87+
if (empty($request['Attributes'][$value])) {
8788
array_push($attributes, $attrName);
89+
break;
8890
}
89-
} else {
90-
array_push($attributes, $attrName);
9191
}
9292
}
9393
}
9494

95+
if (empty($attributes)) {
96+
return;
97+
}
98+
99+
$this->processAttributes($user, $attributes);
100+
}
101+
102+
private function hasStringKeys($array): bool
103+
{
104+
if (!is_array($array)) {
105+
return false;
106+
}
107+
return count(array_filter(array_keys($array), 'is_string')) > 0;
108+
}
109+
110+
/**
111+
* Method process attributes from Perun system and store them to request
112+
* @param User $user
113+
* @param array $attributes List of attributes which will be loaded from Perun system
114+
* @throws Exception
115+
*/
116+
private function processAttributes(User $user, array $attributes): void
117+
{
118+
95119
$attrs = $this->adapter->getUserAttributesValues($user, $attributes);
96120

97121
foreach ($attrs as $attrName => $attrValue) {
@@ -137,12 +161,4 @@ public function process(&$request)
137161
}
138162
}
139163
}
140-
141-
private function hasStringKeys($array)
142-
{
143-
if (!is_array($array)) {
144-
return false;
145-
}
146-
return count(array_filter(array_keys($array), 'is_string')) > 0;
147-
}
148164
}

0 commit comments

Comments
 (0)