|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\Assert; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert as BaseAssert; |
|
8
|
|
|
use SimpleSAML\Assert\AssertionFailedException; |
|
9
|
|
|
use SimpleSAML\SAML11\Constants as C; |
|
10
|
|
|
use SimpleSAML\SAML11\Exception\ProtocolViolationException; |
|
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @package simplesamlphp/assert |
|
15
|
|
|
*/ |
|
16
|
|
|
trait CustomAssertionTrait |
|
17
|
|
|
{ |
|
18
|
|
|
private static string $scheme_regex = '/^([a-z][a-z0-9\+\-\.]+[:])/i'; |
|
19
|
|
|
|
|
20
|
|
|
/*********************************************************************************** |
|
21
|
|
|
* NOTE: Custom assertions may be added below this line. * |
|
22
|
|
|
* They SHOULD be marked as `private` to ensure the call is forced * |
|
23
|
|
|
* through __callStatic(). * |
|
24
|
|
|
* Assertions marked `public` are called directly and will * |
|
25
|
|
|
* not handle any custom exception passed to it. * |
|
26
|
|
|
***********************************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string $value |
|
31
|
|
|
* @param string $message |
|
32
|
|
|
*/ |
|
33
|
|
|
private static function validDateTime(string $value, string $message = ''): void |
|
34
|
|
|
{ |
|
35
|
|
|
try { |
|
36
|
|
|
BaseAssert::validDateTime($value, $message); |
|
37
|
|
|
} catch (AssertionFailedException $e) { |
|
38
|
|
|
throw new SchemaViolationException($e->getMessage()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
try { |
|
42
|
|
|
BaseAssert::endsWith( |
|
43
|
|
|
$value, |
|
44
|
|
|
'Z', |
|
45
|
|
|
$message ?: '%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.', |
|
46
|
|
|
); |
|
47
|
|
|
} catch (AssertionFailedException $e) { |
|
48
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $value |
|
55
|
|
|
* @param string $message |
|
56
|
|
|
*/ |
|
57
|
|
|
private static function validURI(string $value, string $message = ''): void |
|
58
|
|
|
{ |
|
59
|
|
|
try { |
|
60
|
|
|
BaseAssert::validURI($value, $message); |
|
61
|
|
|
} catch (AssertionFailedException $e) { |
|
62
|
|
|
throw new SchemaViolationException($e->getMessage()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
try { |
|
66
|
|
|
BaseAssert::notWhitespaceOnly($value, $message ?: '%s is not a SAML1.1-compliant URI'); |
|
67
|
|
|
} catch (AssertionFailedException $e) { |
|
68
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|