Skip to content

Commit 57c3d54

Browse files
authored
Merge pull request #5 from simplesamlphp/bugfix/use-last-authenticatingauthority
When multiple AuthenticatingAuthority elements are present, use the last
2 parents 834c838 + fd1476d commit 57c3d54

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

docs/smartattributes.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@ SmartAttributes module
44
The SmartAttributes module provides authentication processing filters to add attributes.
55
The logic in this filter exceeds what is possible with the standard filters such, as [`core:AttributeAdd`], [`core:AttributeAlter`], and [`core:AttributeMap`].
66

7-
8-
97
`smartattributes:SmartID`
10-
=========================
8+
-------------------------
119

1210
A filter to add an identifier attribute, based on the first non-empty attribute from a given list of attribute names.
1311
This is useful when there are multiple SAML IdPs configured, and there is no common identifier among them.
1412
For example some IdPs send eduPersonPrincipalName, while others send eduPersonTargetedID. If any of the social networks are configured as an authsource, they will send yet another identifier.
1513
The filter has the following configuration options:
1614

1715
* `candidates`. An array of attributes names to consider as the identifier attribute. Defaults to:
18-
* eduPersonTargetedID
19-
* eduPersonPrincipalName
20-
* pairwise-id
21-
* subject-id
22-
* openid
23-
* facebook_targetedID
24-
* twitter_targetedID
25-
* windowslive_targetedID
26-
* linkedin_targetedID
16+
* eduPersonTargetedID
17+
* eduPersonPrincipalName
18+
* pairwise-id
19+
* subject-id
20+
* openid
21+
* facebook_targetedID
22+
* twitter_targetedID
23+
* windowslive_targetedID
24+
* linkedin_targetedID
2725
* `id_attribute`. A string to use as the name of the newly added attribute. Defaults to `smart_id`.
28-
* `add_authority`. A boolean to indicate whether or not to append the SAML AuthenticatingAuthority to the resulting identifier. This can be useful to indicate what SAML IdP was used, in case the original identifier is not scoped. Defaults to `TRUE`.
26+
* `add_authority`. A boolean to indicate whether or not to append the SAML AuthenticatingAuthority to the resulting identifier. This can be useful to indicate what SAML IdP was used, in case the original identifier is not scoped. When multiple values are in the AuthenticatingAuthority element, the last (closest to us) will be used. Defaults to `TRUE`.
2927
* `add_candidate`. A boolean to indicate whether or not to prepend the candidate attribute name to the resulting identifier. This can be useful to indicate the attribute originating the identifier. Defaults to `TRUE`.
3028
* `fail_if_empty`. A boolean to indicate whether this module reports a failure if no suitable identifier attribute could be found. Set this to `FALSE` if a missing identifier attribute should be handled at a later step in the AuthProc filter queue. Defaults to `TRUE`.
3129

@@ -42,43 +40,48 @@ Examples
4240

4341
Without any configuration:
4442

45-
'authproc' => array(
46-
50 => array(
47-
'class' => 'smartattributes:SmartID'
48-
),
49-
),
50-
43+
```php
44+
'authproc' => [
45+
50 => [
46+
'class' => 'smartattributes:SmartID'
47+
],
48+
],
49+
```
5150

5251
This will add an attribute called `smart_id` with a value looking like, for example:
5352

5453
`eduPersonTargetedID:c4bcbe7ca8eac074f65291fd5524caa88f3115c8!https://login.terena.org/idp/saml2/idp/metadata.php`
5554

5655
Custom configuration:
5756

58-
'authproc' => array(
59-
50 => array(
60-
'class' => 'smartattributes:SmartID',
61-
'candidates' => array('eduPersonTargetedID', 'eduPersonPrincipalName'),
62-
'id_attribute' => 'FooUniversityLocalID',
63-
'add_authority' => FALSE,
64-
),
65-
),
57+
```php
58+
'authproc' => [
59+
50 => [
60+
'class' => 'smartattributes:SmartID',
61+
'candidates' => ['eduPersonTargetedID', 'eduPersonPrincipalName'],
62+
'id_attribute' => 'FooUniversityLocalID',
63+
'add_authority' => FALSE,
64+
],
65+
],
66+
```
6667

6768
This will add an attribute called `FooUniversityLocalID` with a value like:
6869

6970
`eduPersonTargetedID:c4bcbe7ca8eac074f65291fd5524caa88f3115c8`
7071

7172
If you also want to remove the name of the originating attribute, you could configure it like this:
7273

73-
'authproc' => array(
74-
50 => array(
75-
'class' => 'smartattributes:SmartID',
76-
'candidates' => array('eduPersonTargetedID', 'eduPersonPrincipalName'),
77-
'id_attribute' => 'FooUniversityLocalID',
78-
'add_authority' => FALSE,
79-
'add_candidate' => FALSE,
80-
),
81-
),
74+
```php
75+
'authproc' => [
76+
50 => [
77+
'class' => 'smartattributes:SmartID',
78+
'candidates' => ['eduPersonTargetedID', 'eduPersonPrincipalName'],
79+
'id_attribute' => 'FooUniversityLocalID',
80+
'add_authority' => FALSE,
81+
'add_candidate' => FALSE,
82+
],
83+
],
84+
```
8285

8386
Resulting in:
8487

src/Auth/Process/SmartID.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ private function addID(array $attributes, array $request): string
117117
$state = $request['saml:sp:State'];
118118
foreach ($this->candidates as $idCandidate) {
119119
if (isset($attributes[$idCandidate][0])) {
120-
if (($this->add_authority) && (isset($state['saml:AuthenticatingAuthority'][0]))) {
120+
if ($this->add_authority && count($state['saml:AuthenticatingAuthority']) > 0) {
121+
$authority = end($state['saml:AuthenticatingAuthority']);
121122
return ($this->add_candidate ? $idCandidate . ':' : '') . $attributes[$idCandidate][0] . '!' .
122-
$state['saml:AuthenticatingAuthority'][0];
123+
$authority;
123124
} else {
124125
return ($this->add_candidate ? $idCandidate . ':' : '') . $attributes[$idCandidate][0];
125126
}

0 commit comments

Comments
 (0)