|
12 | 12 | * This filter updates userExtSource attributes when he logs in. |
13 | 13 | * |
14 | 14 | * @author Dominik Baránek <[email protected]> |
| 15 | + * @author Pavel Vyskočil <[email protected]> |
15 | 16 | */ |
16 | 17 | class UpdateUserExtSource extends \SimpleSAML\Auth\ProcessingFilter |
17 | 18 | { |
@@ -68,34 +69,38 @@ public function process(&$request) |
68 | 69 |
|
69 | 70 | $attributesToUpdate = array(); |
70 | 71 | 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]]; |
72 | 75 |
|
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; |
77 | 85 | } |
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); |
80 | 101 | } |
81 | | - $attr = $arrayAsString; |
82 | 102 | } |
83 | 103 |
|
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 | | - } |
99 | 104 | } |
100 | 105 |
|
101 | 106 | if (!empty($attributesToUpdate)) { |
|
0 commit comments