ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\FileDelivery\Isolation\IsolationConfig Class Reference

Read-only configuration of the IRSS User Content Isolation feature. More...

+ Collaboration diagram for ILIAS\FileDelivery\Isolation\IsolationConfig:

Public Member Functions

 __construct (private bool $activated, private ?string $content_domain, private ?string $ilias_domain,)
 
 isActivated ()
 
 getContentDomain ()
 
 getIliasDomain ()
 
 getContentHost ()
 
 getIliasHost ()
 
 toArray ()
 

Static Public Member Functions

static fromArray (array $data)
 
static disabled ()
 
static fromArtefact (?string $path=null)
 Load the configuration from the static artefact written by the setup. More...
 
static normalizeOrigin (mixed $value)
 Validate and normalize a configured domain to a bare origin ("scheme://host[:port]"), or null if it is not a usable http/https origin. More...
 
static originFromUrl (mixed $value)
 Reduce a (trusted) application URL to its bare origin "scheme://host[:port]". More...
 

Data Fields

const KEY_ACTIVATED = 'activated'
 
const KEY_CONTENT_DOMAIN = 'content_domain'
 
const KEY_ILIAS_DOMAIN = 'ilias_domain'
 

Private Member Functions

 extractHost (?string $url)
 

Static Private Member Functions

static normalizeUrl (mixed $value)
 Normalize the configured value to a bare origin: "scheme://host[:port]". More...
 

Detailed Description

Read-only configuration of the IRSS User Content Isolation feature.

Loaded from a static PHP artefact written by the setup so that the FileDelivery service can decide whether to deliver content via a dedicated content domain — without any DB dependency.

Both the content domain (admin-configured) and the ILIAS domain (derived from the installed http_path at setup time) are baked into the artefact. The runtime therefore never has to read ilias.ini.php to learn either value.

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 38 of file IsolationConfig.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\FileDelivery\Isolation\IsolationConfig::__construct ( private bool  $activated,
private ?string  $content_domain,
private ?string  $ilias_domain 
)

Definition at line 44 of file IsolationConfig.php.

48 {
49 }

Member Function Documentation

◆ disabled()

◆ extractHost()

ILIAS\FileDelivery\Isolation\IsolationConfig::extractHost ( ?string  $url)
private

Definition at line 132 of file IsolationConfig.php.

132 : ?string
133 {
134 if ($url === null) {
135 return null;
136 }
137 $host = parse_url($url, PHP_URL_HOST);
138 return is_string($host) && $host !== '' ? $host : null;
139 }

Referenced by ILIAS\FileDelivery\Isolation\IsolationConfig\getContentHost(), and ILIAS\FileDelivery\Isolation\IsolationConfig\getIliasHost().

+ Here is the caller graph for this function:

◆ fromArray()

static ILIAS\FileDelivery\Isolation\IsolationConfig::fromArray ( array  $data)
static
Parameters
array<string,mixed>$data

Definition at line 54 of file IsolationConfig.php.

54 : self
55 {
56 $activated = (bool) ($data[self::KEY_ACTIVATED] ?? false);
57 $content = self::normalizeUrl($data[self::KEY_CONTENT_DOMAIN] ?? null);
58 $ilias = self::normalizeUrl($data[self::KEY_ILIAS_DOMAIN] ?? null);
59
60 // Only the content domain is mandatory for isolation; without a separate
61 // origin to deliver from there is nothing to isolate, so it stays off.
62 if ($activated && $content === null) {
63 $activated = false;
64 }
65
66 return new self($activated, $content, $ilias);
67 }
static normalizeUrl(mixed $value)
Normalize the configured value to a bare origin: "scheme://host[:port]".
$data
Definition: storeScorm.php:45

References $data, and ILIAS\FileDelivery\Isolation\IsolationConfig\normalizeUrl().

Referenced by ILIAS\Tests\FileDelivery\Delivery\BaseDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\ServicesBaseUriTest\activeConfig(), ILIAS\FileDelivery\Isolation\IsolationConfig\fromArtefact(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutContentDomainIsForcedOff(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testBareHostnamesGetHttpsScheme(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayToArrayRoundtripIsStable(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayWithFullSpecExample(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromEmptyArrayIsDisabled(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testInactiveStillParsesDomains(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testNonBareOriginsAreRejected(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testToArrayUsesSpecKeys(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testTrailingSlashIsStripped(), and ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testUnusableDomainsNormalizeToNull().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromArtefact()

static ILIAS\FileDelivery\Isolation\IsolationConfig::fromArtefact ( ?string  $path = null)
static

Load the configuration from the static artefact written by the setup.

A missing, unreadable or malformed artefact keeps the feature off, so an installation that never ran the FileDelivery setup behaves as before.

Parameters
string | null$pathonly passed in tests; defaults to the artefact location the setup writes to

Definition at line 83 of file IsolationConfig.php.

83 : self
84 {
85 $path ??= IsolationObjective::PATH();
86 if (!is_file($path)) {
87 return self::disabled();
88 }
89
90 $data = @include $path;
91
92 return self::fromArray(is_array($data) ? $data : []);
93 }

References $data, ILIAS\FileDelivery\Isolation\IsolationConfig\disabled(), ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), and ILIAS\FileDelivery\Setup\BuildStaticConfigStoredObjective\PATH().

Referenced by ILIAS\FileDelivery\Setup\Agent\buildIsolationObjective(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArtefactReadsTheStoredSettings(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArtefactWithNonArrayContentIsDisabled(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArtefactWithoutFileIsDisabled(), and ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArtefactWithoutReturnValueIsDisabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getContentDomain()

ILIAS\FileDelivery\Isolation\IsolationConfig::getContentDomain ( )

Definition at line 112 of file IsolationConfig.php.

112 : ?string
113 {
114 return $this->content_domain;
115 }

◆ getContentHost()

ILIAS\FileDelivery\Isolation\IsolationConfig::getContentHost ( )

Definition at line 122 of file IsolationConfig.php.

122 : ?string
123 {
124 return $this->extractHost($this->content_domain);
125 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\extractHost().

+ Here is the call graph for this function:

◆ getIliasDomain()

ILIAS\FileDelivery\Isolation\IsolationConfig::getIliasDomain ( )

Definition at line 117 of file IsolationConfig.php.

117 : ?string
118 {
119 return $this->ilias_domain;
120 }

◆ getIliasHost()

ILIAS\FileDelivery\Isolation\IsolationConfig::getIliasHost ( )

Definition at line 127 of file IsolationConfig.php.

127 : ?string
128 {
129 return $this->extractHost($this->ilias_domain);
130 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\extractHost().

+ Here is the call graph for this function:

◆ isActivated()

ILIAS\FileDelivery\Isolation\IsolationConfig::isActivated ( )

Definition at line 107 of file IsolationConfig.php.

107 : bool
108 {
109 return $this->activated;
110 }

◆ normalizeOrigin()

static ILIAS\FileDelivery\Isolation\IsolationConfig::normalizeOrigin ( mixed  $value)
static

Validate and normalize a configured domain to a bare origin ("scheme://host[:port]"), or null if it is not a usable http/https origin.

Shared with the setup layer so that the setup and the runtime enforce one identical set of rules for what a content/ILIAS domain may look like.

Definition at line 102 of file IsolationConfig.php.

102 : ?string
103 {
104 return self::normalizeUrl($value);
105 }

References ILIAS\FileDelivery\Isolation\IsolationConfig\normalizeUrl().

Referenced by ILIAS\FileDelivery\Setup\FileDeliverySetupConfig\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizeUrl()

static ILIAS\FileDelivery\Isolation\IsolationConfig::normalizeUrl ( mixed  $value)
staticprivate

Normalize the configured value to a bare origin: "scheme://host[:port]".

Security: the result is used both as the base for asset URLs and as the value of the Access-Control-Allow-Origin response header. It must therefore be a clean origin only — any scheme other than http/https, and any userinfo, path, query or fragment, makes the value unusable (returns null, which keeps isolation disabled). The setup layer rejects such input loudly; this is the runtime safety net.

Definition at line 163 of file IsolationConfig.php.

163 : ?string
164 {
165 if (!is_string($value)) {
166 return null;
167 }
168 $value = trim($value);
169 if ($value === '') {
170 return null;
171 }
172 // accept either a full URL ("https://host[:port]") or a bare hostname ("host.example.org")
173 if (!preg_match('#^[a-z][a-z0-9+.\-]*://#i', $value)) {
174 $value = 'https://' . ltrim($value, '/');
175 }
176
177 $parts = parse_url($value);
178 if (!is_array($parts) || !isset($parts['host']) || $parts['host'] === '') {
179 return null;
180 }
181
182 $scheme = strtolower($parts['scheme'] ?? '');
183 if ($scheme !== 'http' && $scheme !== 'https') {
184 return null;
185 }
186
187 // reject anything that is more than a bare origin
188 if (isset($parts['user']) || isset($parts['pass'])
189 || isset($parts['query']) || isset($parts['fragment'])
190 || (isset($parts['path']) && $parts['path'] !== '' && $parts['path'] !== '/')
191 ) {
192 return null;
193 }
194
195 $origin = $scheme . '://' . strtolower($parts['host']);
196 if (isset($parts['port'])) {
197 $origin .= ':' . $parts['port'];
198 }
199
200 return $origin;
201 }

Referenced by ILIAS\FileDelivery\Isolation\IsolationConfig\fromArray(), and ILIAS\FileDelivery\Isolation\IsolationConfig\normalizeOrigin().

+ Here is the caller graph for this function:

◆ originFromUrl()

static ILIAS\FileDelivery\Isolation\IsolationConfig::originFromUrl ( mixed  $value)
static

Reduce a (trusted) application URL to its bare origin "scheme://host[:port]".

Unlike {

See also
self::normalizeOrigin()} this tolerates a path/query/fragment and simply discards them, because the source is the internally configured ILIAS http_path (which may carry a sub-directory) rather than admin-provided config. The result is only ever used as a CORS allow-origin, which must be an origin.

Used by the setup layer to derive the ILIAS domain from http_path at build time so the value can be baked into the artefact.

Definition at line 214 of file IsolationConfig.php.

214 : ?string
215 {
216 if (!is_string($value)) {
217 return null;
218 }
219 $value = trim($value);
220 if ($value === '') {
221 return null;
222 }
223 if (!preg_match('#^[a-z][a-z0-9+.\-]*://#i', $value)) {
224 $value = 'https://' . ltrim($value, '/');
225 }
226
227 $parts = parse_url($value);
228 if (!is_array($parts) || !isset($parts['host']) || $parts['host'] === '') {
229 return null;
230 }
231
232 $scheme = strtolower($parts['scheme'] ?? '');
233 if ($scheme !== 'http' && $scheme !== 'https') {
234 return null;
235 }
236
237 $origin = $scheme . '://' . strtolower($parts['host']);
238 if (isset($parts['port'])) {
239 $origin .= ':' . $parts['port'];
240 }
241
242 return $origin;
243 }

Referenced by ILIAS\FileDelivery\Setup\IsolationObjective\readIliasDomain(), and ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testOriginFromUrlReducesTrustedAppUrlToBareOrigin().

+ Here is the caller graph for this function:

◆ toArray()

ILIAS\FileDelivery\Isolation\IsolationConfig::toArray ( )
Returns
array<string, mixed>

Definition at line 144 of file IsolationConfig.php.

144 : array
145 {
146 return [
147 self::KEY_ACTIVATED => $this->activated,
148 self::KEY_CONTENT_DOMAIN => $this->content_domain,
149 self::KEY_ILIAS_DOMAIN => $this->ilias_domain,
150 ];
151 }

Field Documentation

◆ KEY_ACTIVATED

const ILIAS\FileDelivery\Isolation\IsolationConfig::KEY_ACTIVATED = 'activated'

Definition at line 40 of file IsolationConfig.php.

Referenced by ILIAS\Tests\FileDelivery\Setup\AgentTest\activatedArtefact(), ILIAS\Tests\FileDelivery\Delivery\BaseDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\ServicesBaseUriTest\activeConfig(), ILIAS\FileDelivery\Setup\IsolationObjective\build(), ILIAS\FileDelivery\Setup\IsolationObjective\buildIn(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutContentDomainIsForcedOff(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testBareHostnamesGetHttpsScheme(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDerivesIliasDomainFromHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDoesNotThrowForSameHostWhenInactive(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInWithoutIniResourceLeavesIliasDomainNull(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildProducesContentDomainWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testDefaultBuildIsDisabledArtifact(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayToArrayRoundtripIsStable(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayWithFullSpecExample(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testInactiveStillParsesDomains(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testNonBareOriginsAreRejected(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testToArrayUsesSpecKeys(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testTrailingSlashIsStripped(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testUnusableDomainsNormalizeToNull(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutConfigAndArtefactStaysDeactivated(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutConfigKeepsCurrentSettings(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutSectionKeepsCurrentSettings(), and ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithSectionOverridesCurrentSettings().

◆ KEY_CONTENT_DOMAIN

const ILIAS\FileDelivery\Isolation\IsolationConfig::KEY_CONTENT_DOMAIN = 'content_domain'

Definition at line 41 of file IsolationConfig.php.

Referenced by ILIAS\Tests\FileDelivery\Setup\AgentTest\activatedArtefact(), ILIAS\Tests\FileDelivery\Delivery\BaseDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\ServicesBaseUriTest\activeConfig(), ILIAS\FileDelivery\Setup\IsolationObjective\build(), ILIAS\FileDelivery\Setup\IsolationObjective\buildIn(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutIliasDomainStaysActiveWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testBareHostnamesGetHttpsScheme(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDerivesIliasDomainFromHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildProducesContentDomainWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testDefaultBuildIsDisabledArtifact(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayToArrayRoundtripIsStable(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayWithFullSpecExample(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testInactiveStillParsesDomains(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testMaliciousDomainIsEscapedAndNotExecuted(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testNonBareOriginsAreRejected(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testToArrayUsesSpecKeys(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testTrailingSlashIsStripped(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testUnusableDomainsNormalizeToNull(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutConfigAndArtefactStaysDeactivated(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutConfigKeepsCurrentSettings(), ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithoutSectionKeepsCurrentSettings(), and ILIAS\Tests\FileDelivery\Setup\AgentTest\testUpdateWithSectionOverridesCurrentSettings().

◆ KEY_ILIAS_DOMAIN

const ILIAS\FileDelivery\Isolation\IsolationConfig::KEY_ILIAS_DOMAIN = 'ilias_domain'

Definition at line 42 of file IsolationConfig.php.

Referenced by ILIAS\Tests\FileDelivery\Setup\AgentTest\activatedArtefact(), ILIAS\Tests\FileDelivery\Delivery\BaseDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\LegacyDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\Delivery\StreamDeliveryIsolationTest\activeConfig(), ILIAS\Tests\FileDelivery\ServicesBaseUriTest\activeConfig(), ILIAS\FileDelivery\Setup\IsolationObjective\build(), ILIAS\FileDelivery\Setup\IsolationObjective\buildIn(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testActivatedWithoutContentDomainIsForcedOff(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testBareHostnamesGetHttpsScheme(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInDerivesIliasDomainFromHttpPath(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildInWithoutIniResourceLeavesIliasDomainNull(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testBuildProducesContentDomainWithNullIliasDomain(), ILIAS\Tests\FileDelivery\Setup\IsolationObjectiveTest\testDefaultBuildIsDisabledArtifact(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayToArrayRoundtripIsStable(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testFromArrayWithFullSpecExample(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testInactiveStillParsesDomains(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testNonBareOriginsAreRejected(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testToArrayUsesSpecKeys(), ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testTrailingSlashIsStripped(), and ILIAS\Tests\FileDelivery\Isolation\IsolationConfigTest\testUnusableDomainsNormalizeToNull().


The documentation for this class was generated from the following file: