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

Commit 4f4f942

Browse files
author
Pavel Vyskočil
committed
Fixed bugs in UpdateUES process filter
* Added checks into UpdateUserExtSource process filter to prevent undefined index or undefined offset errors
1 parent b0e31e3 commit 4f4f942

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
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+
- Added checks into UpdateUserExtSource process filter to prevent undefined index or undefined offset errors
57

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

lib/Auth/Process/UpdateUserExtSource.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* This filter updates userExtSource attributes when he logs in.
1313
*
1414
* @author Dominik Baránek <[email protected]>
15+
* @author Pavel Vyskočil <[email protected]>
1516
*/
1617
class UpdateUserExtSource extends \SimpleSAML\Auth\ProcessingFilter
1718
{
@@ -68,34 +69,38 @@ public function process(&$request)
6869

6970
$attributesToUpdate = array();
7071
foreach ($attributes as $attribute) {
71-
$attr = $request['Attributes'][$this->attrMap[self::UES_ATTR_NMS . $attribute['friendlyName']]];
72+
$attrName = self::UES_ATTR_NMS . $attribute['friendlyName'];
73+
if (isset($this->attrMap[$attrName]) && isset($request['Attributes'][$this->attrMap[$attrName]])) {
74+
$attr = $request['Attributes'][$this->attrMap[$attrName]];
7275

73-
if (in_array(self::UES_ATTR_NMS . $attribute['friendlyName'], $this->attrsToConversion)) {
74-
$arrayAsString = array();
75-
foreach ($attr as $value) {
76-
$arrayAsString[0] .= $value . ';';
76+
if (in_array(self::UES_ATTR_NMS . $attribute['friendlyName'], $this->attrsToConversion)) {
77+
$arrayAsString = array('');
78+
foreach ($attr as $value) {
79+
$arrayAsString[0] .= $value . ';';
80+
}
81+
if (!empty($arrayAsString[0])) {
82+
$arrayAsString[0] = substr($arrayAsString[0], 0, -1);
83+
}
84+
$attr = $arrayAsString;
7785
}
78-
if (!empty($arrayAsString[0])) {
79-
$arrayAsString[0] = substr($arrayAsString[0], 0, -1);
86+
87+
if (strpos($attribute['type'], 'String') ||
88+
strpos($attribute['type'], 'Integer') ||
89+
strpos($attribute['type'], 'Boolean')) {
90+
$valueFromIdP = $attr[0];
91+
} elseif (strpos($attribute['type'], 'Array') || strpos($attribute['type'], 'Map')) {
92+
$valueFromIdP = $attr;
93+
} else {
94+
throw new Exception(
95+
'sspmod_perun_Auth_Process_UpdateUserExtSource: unsupported type of attribute.'
96+
);
97+
}
98+
if ($valueFromIdP !== $attribute['value']) {
99+
$attribute['value'] = $valueFromIdP;
100+
array_push($attributesToUpdate, $attribute);
80101
}
81-
$attr = $arrayAsString;
82102
}
83103

84-
if (strpos($attribute['type'], 'String') ||
85-
strpos($attribute['type'], 'Integer') ||
86-
strpos($attribute['type'], 'Boolean')) {
87-
$valueFromIdP = $attr[0];
88-
} elseif (strpos($attribute['type'], 'Array') || strpos($attribute['type'], 'Map')) {
89-
$valueFromIdP = $attr;
90-
} else {
91-
throw new Exception(
92-
"sspmod_perun_Auth_Process_UpdateUserExtSource: unsupported type of attribute."
93-
);
94-
}
95-
if ($valueFromIdP != $attribute['value']) {
96-
$attribute['value'] = $valueFromIdP;
97-
array_push($attributesToUpdate, $attribute);
98-
}
99104
}
100105

101106
if (!empty($attributesToUpdate)) {

0 commit comments

Comments
 (0)