ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
IsolationObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
40{
41 public function __construct(
42 private readonly bool $activated = false,
43 private readonly ?string $content_domain = null,
44 ) {
45 }
46
47 public function getArtifactName(): string
48 {
49 return 'isolation';
50 }
51
52 #[\Override]
53 public function getPreconditions(Environment $environment): array
54 {
55 // ilias.ini.php must be loaded as a resource so we can read http_path;
56 // and http_path must have been written into it before we read it.
57 $preconditions = [new \ilIniFilesLoadedObjective()];
58 if ($environment->hasConfigFor('http')) {
59 $preconditions[] = new \ilHttpConfigStoredObjective($environment->getConfigFor('http'));
60 }
61 return $preconditions;
62 }
63
64 #[\Override]
65 public function buildIn(Environment $env): Artifact
66 {
67 $ilias_domain = $this->readIliasDomain($env);
68
69 if ($this->activated
70 && $this->content_domain !== null
71 && $ilias_domain !== null
72 && strcasecmp(
73 (string) parse_url($this->content_domain, PHP_URL_HOST),
74 (string) parse_url($ilias_domain, PHP_URL_HOST)
75 ) === 0
76 ) {
77 throw new UnachievableException(
78 'IRSS User Content Isolation requires the content domain to differ from the '
79 . 'ILIAS domain (http_path); serving user content from the same host defeats '
80 . 'the isolation.'
81 );
82 }
83
84 return new ArrayArtifact([
85 IsolationConfig::KEY_ACTIVATED => $this->activated,
86 IsolationConfig::KEY_CONTENT_DOMAIN => $this->content_domain,
87 IsolationConfig::KEY_ILIAS_DOMAIN => $ilias_domain,
88 ]);
89 }
90
91 public function build(): Artifact
92 {
93 // Used only when no Environment is available (e.g. tests). The ILIAS
94 // domain is resolved in buildIn() from http_path, so it stays null here.
95 return new ArrayArtifact([
96 IsolationConfig::KEY_ACTIVATED => $this->activated,
97 IsolationConfig::KEY_CONTENT_DOMAIN => $this->content_domain,
99 ]);
100 }
101
106 private function readIliasDomain(Environment $env): ?string
107 {
109 if (!$ini instanceof \ilIniFile) {
110 return null;
111 }
112
114 $ini->readVariable('server', 'http_path') ?: null
115 );
116 }
117}
Read-only configuration of the IRSS User Content Isolation feature.
static originFromUrl(mixed $value)
Reduce a (trusted) application URL to its bare origin "scheme://host[:port]".
Writes the IRSS User Content Isolation settings to a static PHP artefact so the FileDelivery runtime ...
getPreconditions(Environment $environment)
Objectives might depend on other objectives.
readIliasDomain(Environment $env)
Read the installed http_path from ilias.ini.php and reduce it to a bare origin to be used as the CORS...
__construct(private readonly bool $activated=false, private readonly ?string $content_domain=null,)
An array as an artifact.
Signals that some goal won't be achievable by actions of the system ever.
INI file parser — compatibility wrapper.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
hasConfigFor(string $component)
getConfigFor(string $component)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.