1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\Assert; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\AssertionFailedException; |
8
|
|
|
use SimpleSAML\SAML2\Constants as C; |
9
|
|
|
use SimpleSAML\SAML2\Exception\ProtocolViolationException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package simplesamlphp/saml2 |
13
|
|
|
*/ |
14
|
|
|
trait CustomAssertionTrait |
15
|
|
|
{ |
16
|
|
|
private static string $scheme_regex = '/^([a-z][a-z0-9\+\-\.]+[:])/i'; |
17
|
|
|
|
18
|
|
|
/*********************************************************************************** |
19
|
|
|
* NOTE: Custom assertions may be added below this line. * |
20
|
|
|
* They SHOULD be marked as `private` to ensure the call is forced * |
21
|
|
|
* through __callStatic(). * |
22
|
|
|
* Assertions marked `public` are called directly and will * |
23
|
|
|
* not handle any custom exception passed to it. * |
24
|
|
|
***********************************************************************************/ |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $value |
29
|
|
|
* @param string $message |
30
|
|
|
*/ |
31
|
|
|
protected static function validDateTime(string $value, string $message = ''): void |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
parent::validDateTime($value); |
34
|
|
|
|
35
|
|
|
try { |
36
|
|
|
parent::endsWith( |
37
|
|
|
$value, |
38
|
|
|
'Z', |
39
|
|
|
'%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.', |
40
|
|
|
); |
41
|
|
|
} catch (AssertionFailedException $e) { |
42
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $value |
49
|
|
|
* @param string $message |
50
|
|
|
*/ |
51
|
|
|
protected static function validURI(string $value, string $message = ''): void |
52
|
|
|
{ |
53
|
|
|
parent::validURI($value); |
54
|
|
|
|
55
|
|
|
try { |
56
|
|
|
// If it doesn't have a scheme, it's not an absolute URI |
57
|
|
|
parent::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML2-compliant URI'); |
58
|
|
|
} catch (AssertionFailedException $e) { |
59
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $value |
66
|
|
|
* @param string $message |
67
|
|
|
*/ |
68
|
|
|
protected static function validEntityID(string $value, string $message = ''): void |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
static::validURI($value); |
71
|
|
|
|
72
|
|
|
try { |
73
|
|
|
parent::notWhitespaceOnly($value); |
74
|
|
|
parent::maxLength( |
75
|
|
|
$value, |
76
|
|
|
C::ENTITYID_MAX_LENGTH, |
77
|
|
|
sprintf('An entityID cannot be longer than %d characters.', C::ENTITYID_MAX_LENGTH), |
78
|
|
|
); |
79
|
|
|
} catch (AssertionFailedException $e) { |
80
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.