|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace OpenConext\Profile\Value; |
|
20
|
|
|
|
|
21
|
|
|
use Surfnet\SamlBundle\SAML2\Attribute\Attribute; |
|
22
|
|
|
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet; |
|
23
|
|
|
|
|
24
|
|
|
class SpecifiedConsent |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Consent |
|
28
|
|
|
*/ |
|
29
|
|
|
private $consent; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var AttributeSet |
|
33
|
|
|
*/ |
|
34
|
|
|
private $releasedAttributes; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Arp |
|
38
|
|
|
*/ |
|
39
|
|
|
private $arp; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param Consent $consent |
|
43
|
|
|
* @param AttributeSet $releasedAttributes |
|
44
|
|
|
* @param Arp $arp |
|
45
|
|
|
* @return SpecifiedConsent |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function specifies(Consent $consent, AttributeSet $releasedAttributes, Arp $arp) |
|
48
|
|
|
{ |
|
49
|
|
|
return new self($consent, $releasedAttributes, $arp); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param Consent $consent |
|
54
|
|
|
* @param AttributeSet $releasedAttributes |
|
55
|
|
|
* @param Arp $arp |
|
56
|
|
|
*/ |
|
57
|
|
|
private function __construct(Consent $consent, AttributeSet $releasedAttributes, Arp $arp) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->consent = $consent; |
|
60
|
|
|
$this->releasedAttributes = $releasedAttributes; |
|
61
|
|
|
$this->arp = $arp; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Consent |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getConsent() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->consent; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return AttributeSet |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getReleasedAttributes() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->releasedAttributes; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function hasMultipleSources() |
|
81
|
|
|
{ |
|
82
|
|
|
$sources = []; |
|
83
|
|
|
foreach ($this->getReleasedAttributes() as $attribute) { |
|
84
|
|
|
$source = $attribute->getValue()[0]['source']; |
|
85
|
|
|
$sources[$source] = $source; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$sources = array_merge($sources, $this->arp->getNonIdpAttributes()); |
|
89
|
|
|
|
|
90
|
|
|
return count($sources) > 1; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Groups the released attributes on the group they originate from. This can be used to show the AA attributes. |
|
95
|
|
|
* Note that the attributes from the IdP source are omitted in the results. |
|
96
|
|
|
* |
|
97
|
|
|
* @return Attribute[] |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getReleasedAttributesGroupedBySource() |
|
100
|
|
|
{ |
|
101
|
|
|
$grouped = []; |
|
102
|
|
|
foreach ($this->getReleasedAttributes() as $attribute) { |
|
103
|
|
|
// The source is the same for all possible attribute values, so use the first one. |
|
104
|
|
|
$source = $attribute->getValue()[0]['source']; |
|
105
|
|
|
if ($source !== 'idp') { |
|
106
|
|
|
continue; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$grouped[$source][] = $attribute; |
|
110
|
|
|
} |
|
111
|
|
|
$grouped = array_merge($grouped, $this->arp->getNonIdpAttributes()); |
|
112
|
|
|
|
|
113
|
|
|
return $grouped; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return bool |
|
118
|
|
|
*/ |
|
119
|
|
|
public function hasMotivations() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->arp->hasMotivations(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getMotivation(Attribute $attribute) |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
return $this->arp->getMotivationFor($attribute); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|