ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAuthFrontendCredentialsApache.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Psr\Http\Message\ServerRequestInterface;
22
24{
25 private ServerRequestInterface $httpRequest;
28
29 public function __construct(ServerRequestInterface $httpRequest, ilCtrlInterface $ctrl)
30 {
31 $this->httpRequest = $httpRequest;
32 $this->ctrl = $ctrl;
33 $this->settings = new ilSetting('apache_auth');
35 }
36
41 public function tryAuthenticationOnLoginPage(): void
42 {
43 $cmd = (string) ($this->httpRequest->getQueryParams()['cmd'] ?? '');
44 if ($cmd === '') {
45 $cmd = (string) ($this->httpRequest->getParsedBody()['cmd'] ?? '');
46 }
47
48 if ($cmd === 'force_login') {
49 return;
50 }
51
52 if (!$this->getSettings()->get('apache_enable_auth', '0')) {
53 return;
54 }
55
56 if (!$this->getSettings()->get('apache_auth_authenticate_on_login_page', '0')) {
57 return;
58 }
59
60 if (
61 (defined('IL_CERT_SSO') && (int) IL_CERT_SSO === 1) ||
63 isset($this->httpRequest->getQueryParams()['passed_sso'])
64 ) {
65 return;
66 }
67
68 $path = (string) ($this->httpRequest->getServerParams()['REQUEST_URI'] ?? '');
69 if (str_starts_with($path, '/')) {
70 $path = substr($path, 1);
71 }
72
73 if (!str_starts_with($path, 'http')) {
74 $parts = parse_url(ILIAS_HTTP_PATH);
75 $path = $parts['scheme'] . '://' . $parts['host'] . '/' . $path;
76 }
77
78 $this->ctrl->redirectToURL(
80 './public/sso/index.php?force_mode_apache=1&' .
81 'r=' . urlencode($path) .
82 '&cookie_path=' . urlencode(IL_COOKIE_PATH) .
83 '&ilias_path=' . urlencode(ILIAS_HTTP_PATH)
84 )
85 );
86 }
87
88 protected function getSettings(): ilSetting
89 {
90 return $this->settings;
91 }
92
93 public function initFromRequest(): void
94 {
95 $mappingFieldName = $this->getSettings()->get('apache_auth_username_direct_mapping_fieldname', '');
96
97 $this->logger->dump($this->httpRequest->getServerParams(), ilLogLevel::DEBUG);
98 $this->logger->debug($mappingFieldName);
99
100 switch ($this->getSettings()->get('apache_auth_username_config_type')) {
102 if (isset($this->httpRequest->getServerParams()[$mappingFieldName])) {
103 $this->setUsername($this->httpRequest->getServerParams()[$mappingFieldName]);
104 }
105 break;
106
109 break;
110 }
111 }
112
113 public function hasValidTargetUrl(): bool
114 {
115 $targetUrl = trim((string) ($this->httpRequest->getQueryParams()['r'] ?? ''));
116 if ($targetUrl === '') {
117 return false;
118 }
119
120 $validDomains = [];
121 $path = ILIAS_DATA_DIR . '/' . CLIENT_ID . '/apache_auth_allowed_domains.txt';
122 if (file_exists($path) && is_readable($path)) {
123 foreach (file($path) as $line) {
124 if (trim($line)) {
125 $validDomains[] = trim($line);
126 }
127 }
128 }
129
130 return (new ilWhiteListUrlValidator($targetUrl, $validDomains))->isValid();
131 }
132
133 public function getTargetUrl(): string
134 {
135 return ilUtil::appendUrlParameterString(trim($this->httpRequest->getQueryParams()['r']), 'passed_sso=1');
136 }
137}
const IL_COOKIE_PATH(isset($_GET['client_id']))
Definition: index.php:47
tryAuthenticationOnLoginPage()
Check if an authentication attempt should be done when login page has been called.
__construct(ServerRequestInterface $httpRequest, ilCtrlInterface $ctrl)
static supportsRedirects()
Are redirects supported?
ILIAS Setting Class.
static getHtmlPath(string $relative_path)
get url of path
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
const CLIENT_ID
Definition: constants.php:41
const ILIAS_DATA_DIR
Definition: constants.php:44
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc