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

Commit 16ba084

Browse files
committed
Added support for multiple uid attributes
1 parent b7a8e56 commit 16ba084

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/Auth/Process/ProcessTargetedID.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class sspmod_perun_Auth_Process_ProcessTargetedID extends SimpleSAML_Auth_ProcessingFilter
1414
{
15-
private $uidAttr;
15+
private $uidsAttr;
1616
private $prefix;
1717

1818
public function __construct($config, $reserved)
@@ -21,27 +21,34 @@ public function __construct($config, $reserved)
2121

2222
assert('is_array($config)');
2323

24-
if (!isset($config['uidAttr'])) {
25-
throw new SimpleSAML_Error_Exception("perun:ProcessTargetedID: missing mandatory configuration option 'uidAttr'.");
24+
if (!isset($config['uidsAttr'])) {
25+
throw new SimpleSAML_Error_Exception("perun:ProcessTargetedID: missing mandatory configuration option 'uidsAttr'.");
2626
}
2727
if (!isset($config['prefix'])) {
2828
throw new SimpleSAML_Error_Exception("perun:ProcessTargetedID: missing mandatory configuration option 'prefix'.");
2929
}
3030

31-
$this->uidAttr = (string) $config['uidAttr'];
31+
$this->uidsAttr = $config['uidsAttr'];
3232
$this->prefix = (string) $config['prefix'];
3333
}
3434

3535
public function process(&$request)
3636
{
3737
assert('is_array($request)');
3838

39-
if (isset($request['Attributes'][$this->uidAttr][0])) {
40-
$uid = $request['Attributes'][$this->uidAttr][0];
41-
} else {
42-
throw new SimpleSAML_Error_Exception("perun:ProcessTargetedID: " .
43-
"missing mandatory attribute " . $this->uidAttr . " in request.");
44-
}
39+
# Iterate through provided attributes and simply get first value
40+
$uid = "";
41+
foreach ($this->uidsAttr as $uidAttr) {
42+
if (isset($request['Attributes'][$uidAttr][0])) {
43+
$uid = $request['Attributes'][$uidAttr][0];
44+
break;
45+
}
46+
}
47+
48+
if (empty($uid)) {
49+
# There is no TargetedID in the request, so we can quit
50+
return;
51+
}
4552

4653
# Do not continue if we have user id with scope
4754
if (strpos($uid, '@') !== false) {

0 commit comments

Comments
 (0)