|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Model\Assertion; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Model\Context\DeserializationContext; |
|
15
|
|
|
use LightSaml\Model\Context\SerializationContext; |
|
16
|
|
|
use LightSaml\SamlConstants; |
|
17
|
|
|
|
|
18
|
|
|
class AudienceRestriction extends AbstractCondition |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string[] |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $audience = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string|string[] $audience |
|
27
|
|
|
*/ |
|
28
|
15 |
|
public function __construct($audience = array()) |
|
29
|
|
|
{ |
|
30
|
15 |
|
if (false == is_array($audience)) { |
|
|
|
|
|
|
31
|
1 |
|
$audience = array($audience); |
|
32
|
|
|
} |
|
33
|
15 |
|
$this->audience = $audience; |
|
34
|
15 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $audience |
|
38
|
|
|
* |
|
39
|
|
|
* @return AudienceRestriction |
|
40
|
|
|
*/ |
|
41
|
6 |
|
public function addAudience($audience) |
|
42
|
|
|
{ |
|
43
|
6 |
|
$this->audience[] = $audience; |
|
44
|
|
|
|
|
45
|
6 |
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return string[] |
|
50
|
|
|
*/ |
|
51
|
7 |
|
public function getAllAudience() |
|
52
|
|
|
{ |
|
53
|
7 |
|
return $this->audience; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param string $value |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
2 |
|
public function hasAudience($value) |
|
62
|
|
|
{ |
|
63
|
2 |
|
if (is_array($this->audience)) { |
|
64
|
2 |
|
foreach ($this->audience as $a) { |
|
65
|
2 |
|
if ($a == $value) { |
|
66
|
2 |
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param \DOMNode $parent |
|
76
|
|
|
* @param SerializationContext $context |
|
77
|
|
|
*/ |
|
78
|
4 |
|
public function serialize(\DOMNode $parent, SerializationContext $context) |
|
79
|
|
|
{ |
|
80
|
4 |
|
$result = $this->createElement('AudienceRestriction', SamlConstants::NS_ASSERTION, $parent, $context); |
|
81
|
|
|
|
|
82
|
4 |
|
$this->manyElementsToXml($this->getAllAudience(), $result, $context, 'Audience', SamlConstants::NS_ASSERTION); |
|
83
|
4 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param \DOMNode $node |
|
87
|
|
|
* @param DeserializationContext $context |
|
88
|
|
|
*/ |
|
89
|
3 |
View Code Duplication |
public function deserialize(\DOMNode $node, DeserializationContext $context) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
3 |
|
$this->checkXmlNodeName($node, 'AudienceRestriction', SamlConstants::NS_ASSERTION); |
|
92
|
|
|
|
|
93
|
3 |
|
$this->audience = array(); |
|
94
|
3 |
|
$this->manyElementsFromXml($node, $context, 'Audience', 'saml', null, 'addAudience'); |
|
|
|
|
|
|
95
|
3 |
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.