ILIAS  release_8 Revision v8.24
class.ilAuthProviderApache.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/******************************************************************************
6 *
7 * This file is part of ILIAS, a powerful learning management system.
8 *
9 * ILIAS is licensed with the GPL-3.0, you should have received a copy
10 * of said license along with the source code.
11 *
12 * If this is not the case or you just want to try ILIAS, you'll find
13 * us at:
14 * https://www.ilias.de
15 * https://github.com/ILIAS-eLearning
16 *
17 *****************************************************************************/
18
25{
29
31 private string $migration_account = '';
32 private bool $force_new_account = false;
33
35 {
37 $this->settings = new ilSetting('apache_auth');
38 }
39
40 protected function getSettings(): ilSetting
41 {
42 return $this->settings;
43 }
44
45 public function doAuthentication(ilAuthStatus $status): bool
46 {
47 if (!$this->getSettings()->get('apache_enable_auth', '0')) {
48 $this->getLogger()->info('Apache auth disabled.');
49 $this->handleAuthenticationFail($status, 'apache_auth_err_disabled');
50 return false;
51 }
52
53 if (
54 !$this->getSettings()->get('apache_auth_indicator_name', '') ||
55 !$this->getSettings()->get('apache_auth_indicator_value', '')
56 ) {
57 $this->getLogger()->warning('Apache auth indicator match failure.');
58 $this->handleAuthenticationFail($status, 'apache_auth_err_indicator_match_failure');
59 return false;
60 }
61
62 $validIndicatorValues = array_filter(array_map(
63 'trim',
64 str_getcsv($this->getSettings()->get('apache_auth_indicator_value', ''))
65 ));
66 //TODO PHP8-REVIEW: $DIC->http()->request()->getServerParams()['apache_auth_indicator_name']
67 if (
68 !isset($_SERVER[$this->getSettings()->get('apache_auth_indicator_name', '')]) ||
69 !in_array($_SERVER[$this->getSettings()->get('apache_auth_indicator_name', '')], $validIndicatorValues, true)
70 ) {
71 $this->getLogger()->warning('Apache authentication failed (indicator name <-> value');
72 $this->handleAuthenticationFail($status, 'err_wrong_login');
73 return false;
74 }
75
76 if (!ilUtil::isLogin($this->getCredentials()->getUsername())) {
77 $this->getLogger()->warning('Invalid login name given: ' . $this->getCredentials()->getUsername());
78 $this->handleAuthenticationFail($status, 'apache_auth_err_invalid_login');
79 return false;
80 }
81
82 if ($this->getCredentials()->getUsername() === '') {
83 $this->getLogger()->info('No username given');
84 $this->handleAuthenticationFail($status, 'err_wrong_login');
85 return false;
86 }
87
88 // Apache with ldap as data source
89 if ($this->getSettings()->get('apache_enable_ldap', '0')) {
90 return $this->handleLDAPDataSource($status);
91 }
92
93 $login = ilObjUser::_checkExternalAuthAccount('apache', $this->getCredentials()->getUsername());
94 $usr_id = ilObjUser::_lookupId($login);
95 if (!$usr_id) {
96 $this->getLogger()->info('Cannot find user id for external account: ' . $this->getCredentials()->getUsername());
97 $this->handleAuthenticationFail($status, 'err_wrong_login');
98 return false;
99 }
100
102 $status->setAuthenticatedUserId($usr_id);
103 return true;
104 }
105
106 public function migrateAccount(ilAuthStatus $status): void
107 {
108 $this->force_new_account = true;
109 if ($this->getSettings()->get('apache_enable_ldap', '0')) {
110 $this->handleLDAPDataSource($status);
111 }
112 }
113
114 public function createNewAccount(ilAuthStatus $status): void
115 {
116 $this->force_new_account = true;
117 if ($this->getSettings()->get('apache_enable_ldap', '0')) {
118 $this->handleLDAPDataSource($status);
119 }
120 }
121
122 public function getExternalAccountName(): string
123 {
125 }
126
127 public function setExternalAccountName(string $name): void
128 {
129 $this->migration_account = $name;
130 }
131
132 public function getTriggerAuthMode(): string
133 {
134 return (string) ilAuthUtils::AUTH_APACHE;
135 }
136
137 public function getUserAuthModeName(): string
138 {
139 if ($this->getSettings()->get('apache_ldap_sid', '0')) {
140 return 'ldap_' . $this->getSettings()->get('apache_ldap_sid', '');
141 }
142
143 return 'apache';
144 }
145
146 protected function handleLDAPDataSource(ilAuthStatus $status): bool
147 {
149 (int) $this->getSettings()->get('apache_ldap_sid', '0')
150 );
151
152 $this->getLogger()->debug('Using ldap data source with server configuration: ' . $server->getName());
153
154 $sync = new ilLDAPUserSynchronisation('ldap_' . $server->getServerId(), $server->getServerId());
155 $sync->setExternalAccount($this->getCredentials()->getUsername());
156 $sync->setUserData([]);
157 $sync->forceCreation($this->force_new_account);
158 $sync->forceReadLdapData(true);
159
160 try {
161 $internal_account = $sync->sync();
162 $this->getLogger()->debug('Internal account: ' . $internal_account);
163 } catch (UnexpectedValueException $e) {
164 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
165 $this->handleAuthenticationFail($status, 'err_wrong_login');
166 return false;
168 $this->handleAuthenticationFail($status, 'err_auth_ldap_failed');
169 return false;
171 // No syncronisation allowed => create Error
172 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
173 $this->handleAuthenticationFail($status, 'err_auth_ldap_no_ilias_user');
174 return false;
176 $this->setExternalAccountName($this->getCredentials()->getUsername());
177 $this->getLogger()->info('Authentication failed: account migration required for external account: ' . $this->getCredentials()->getUsername());
179 return false;
180 }
181
183 $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
184 return true;
185 }
186}
createNewAccount(ilAuthStatus $status)
Create new ILIAS account for external_account.
getTriggerAuthMode()
Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 1...
migrateAccount(ilAuthStatus $status)
Create new account.
getExternalAccountName()
Get external account name.
handleLDAPDataSource(ilAuthStatus $status)
getUserAuthModeName()
Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth.
doAuthentication(ilAuthStatus $status)
__construct(ilAuthCredentials $credentials)
Constructor.
Base class for authentication providers (ldap, apache, ...)
getLogger()
Get logger.
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
ilAuthCredentials $credentials
Auth status implementation.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Synchronization of user accounts used in auth container ldap, cas,...
static _lookupId($a_user_str)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isLogin(string $a_login)
$server
Interface of auth credentials.
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10