-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathAbstractContainer.php
More file actions
184 lines (151 loc) · 6.35 KB
/
Copy pathAbstractContainer.php
File metadata and controls
184 lines (151 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
declare(strict_types=1);
namespace SimpleSAML\SAML2\Compat;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;
use SimpleSAML\SAML2\Assert\Assert;
use SimpleSAML\SAML2\XML\ExtensionPointInterface;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\ElementInterface;
use SimpleSAML\XMLSchema\Type\QNameValue;
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use function array_key_exists;
use function constant;
abstract class AbstractContainer
{
/** @var array */
protected array $registry = [];
/** @var array */
protected array $extRegistry = [];
/** @var array|null */
protected ?array $blacklistedEncryptionAlgorithms = [
EncryptionAlgorithmFactory::DEFAULT_BLACKLIST,
KeyTransportAlgorithmFactory::DEFAULT_BLACKLIST,
SignatureAlgorithmFactory::DEFAULT_BLACKLIST,
];
/**
* Get the list of algorithms that are blacklisted for any encryption operation.
*
* @return string[]|null An array with all algorithm identifiers that are blacklisted, or null if we want to use the
* defaults.
*/
public function getBlacklistedEncryptionAlgorithms(): ?array
{
return $this->blacklistedEncryptionAlgorithms;
}
/**
* Register a class that can handle a given element.
*
* @param string $class The class name of a class extending AbstractElement
*/
public function registerElementHandler(string $class): void
{
Assert::subclassOf($class, AbstractElement::class);
$key = '{' . constant($class::NS) . '}' . AbstractElement::getClassName($class);
$this->registry[$key] = $class;
}
/**
* Register a class that can handle given extension points of the standard.
*
* @param string $class The class name of a class extending AbstractElement or implementing ExtensionPointInterface.
*/
public function registerExtensionHandler(string $class): void
{
Assert::subclassOf($class, ExtensionPointInterface::class);
$key = '{' . $class::getXsiTypeNamespaceURI() . '}' . $class::getXsiTypeName();
$this->extRegistry[$key] = $class;
}
/**
* Search for a class that implements an element in the given $namespace.
*
* Such classes must have been registered previously by calling registerExtensionHandler(), and they must
* extend \SimpleSAML\XML\AbstractElement.
*
* @param \SimpleSAML\XMLSchema\Type\QNameValue $qName The qualified name of the element.
*
* @return string|null The fully-qualified name of a class extending \SimpleSAML\XML\AbstractElement and
* implementing support for the given element, or null if no such class has been registered before.
*/
public function getElementHandler(QNameValue $qName): ?string
{
$key = '{' . $qName->getNameSpaceURI()->getValue() . '}' . $qName->getLocalName()->getValue();
if (array_key_exists($key, $this->registry) === true) {
Assert::implementsInterface($this->registry[$key], ElementInterface::class);
return $this->registry[$key];
}
return null;
}
/**
* Search for a class that implements a custom element type.
*
* Such classes must have been registered previously by calling registerExtensionHandler(), and they must
* implement \SimpleSAML\SAML11\XML\saml\ExtensionPointInterface.
*
* @param \SimpleSAML\XMLSchema\Type\QNameValue $qName The qualified name of the extension.
* @return string|null The fully-qualified name of a class implementing
* \SimpleSAML\SAML11\XML\saml\ExtensionPointInterface or null if no such class has been registered before.
*/
public function getExtensionHandler(QNameValue $qName): ?string
{
$key = '{' . $qName->getNameSpaceURI()->getValue() . '}' . $qName->getLocalName()->getValue();
if (array_key_exists($key, $this->extRegistry) === true) {
Assert::implementsInterface($this->extRegistry[$key], ExtensionPointInterface::class);
return $this->extRegistry[$key];
}
return null;
}
/**
* Set the list of algorithms that are blacklisted for any encryption operation.
*
* @param string[]|null $algos An array with all algorithm identifiers that are blacklisted,
* or null if we want to use the defaults.
*/
abstract public function setBlacklistedAlgorithms(?array $algos): void;
/**
* Get a PSR-3 compatible logger.
* @return \Psr\Log\LoggerInterface
*/
abstract public function getLogger(): LoggerInterface;
/**
* Log an incoming message to the debug log.
*
* Type can be either:
* - **in** XML received from third party
* - **out** XML that will be sent to third party
* - **encrypt** XML that is about to be encrypted
* - **decrypt** XML that was just decrypted
*
* @param \Dom\Element|string $message
*/
abstract public function debugMessage($message, string $type): void;
/**
* Trigger the user to perform a POST to the given URL with the given data.
*/
abstract public function getPOSTRedirectURL(string $url, array $data = []): string;
/**
* This function retrieves the path to a directory where temporary files can be saved.
*
* @return string Path to a temporary directory, without a trailing directory separator.
*
* @throws \Exception If the temporary directory cannot be created or it exists and does not belong
* to the current user.
*/
abstract public function getTempDir(): string;
/**
* Atomically write a file.
*
* This is a helper function for writing data atomically to a file. It does this by writing the file data to a
* temporary file, then renaming it to the required file name.
*
* @param string $filename The path to the file we want to write to.
* @param string $data The data we should write to the file.
* @param int|null $mode The permissions to apply to the file. Defaults to 0600.
*/
abstract public function writeFile(string $filename, string $data, ?int $mode = null): void;
/**
* Get the system clock, using UTC for a timezone
*/
abstract public function getClock(): ClockInterface;
}