|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\md; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert; |
|
8
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
9
|
|
|
|
|
10
|
|
|
use function filter_var; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Abstract class implementing LocalizedURIType. |
|
14
|
|
|
* |
|
15
|
|
|
* @package simplesamlphp/saml2 |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class AbstractLocalizedURI extends AbstractLocalizedName |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Set the content of the element. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $content The value to go in the XML textContent |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function setContent(string $content): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->validateContent($content); |
|
27
|
|
|
$this->content = $content; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get the content of the element. |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getContent(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->sanitizeContent($this->getRawContent()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the raw and unsanitized content of the element. |
|
44
|
|
|
* |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getRawContent(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->content; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Sanitize the content of the element. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $content The unsanitized textContent |
|
57
|
|
|
* @throws \Exception on failure |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function sanitizeContent(string $content): string |
|
61
|
|
|
{ |
|
62
|
|
|
// We've seen metadata in the wild that had stray whitespace around URIs, causing assertions to fail |
|
63
|
|
|
return trim($content); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Validate the content of the element. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $content The value to go in the XML textContent |
|
71
|
|
|
* @throws \Exception on failure |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function validateContent(string $content): void |
|
75
|
|
|
{ |
|
76
|
|
|
Assert::validURI($this->sanitizeContent($content), SchemaViolationException::class); // Covers the empty string |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|