ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAuthProviderApache.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
13
14 private $settings = null;
15
16 private $migration_account = '';
17 private $force_new_account = false;
18
24 {
26 $this->settings = new ilSetting('apache_auth');
27 }
28
33 protected function getSettings() : ilSetting
34 {
35 return $this->settings;
36 }
37
42 {
43 if (!$this->getSettings()->get('apache_enable_auth')) {
44 $this->getLogger()->info('Apache auth disabled.');
45 $this->handleAuthenticationFail($status, 'apache_auth_err_disabled');
46 return false;
47 }
48
49 if (
50 !$this->getSettings()->get('apache_auth_indicator_name') ||
51 !$this->getSettings()->get('apache_auth_indicator_value')
52 ) {
53 $this->getLogger()->warning('Apache auth indicator match failure.');
54 $this->handleAuthenticationFail($status, 'apache_auth_err_indicator_match_failure');
55 return false;
56 }
57
58 $validIndicatorValues = array_filter(array_map(
59 'trim',
60 str_getcsv($this->getSettings()->get('apache_auth_indicator_value'))
61 ));
62 if (!in_array($_SERVER[$this->getSettings()->get('apache_auth_indicator_name')], $validIndicatorValues)) {
63 $this->getLogger()->warning('Apache authentication failed (indicator name <-> value');
64 $this->handleAuthenticationFail($status, 'err_wrong_login');
65 return false;
66 }
67
68 if (!ilUtil::isLogin($this->getCredentials()->getUsername())) {
69 $this->getLogger()->warning('Invalid login name given: ' . $this->getCredentials()->getUsername());
70 $this->handleAuthenticationFail($status, 'apache_auth_err_invalid_login');
71 return false;
72 }
73
74 if (!strlen($this->getCredentials()->getUsername())) {
75 $this->getLogger()->info('No username given');
76 $this->handleAuthenticationFail($status, 'err_wrong_login');
77 return false;
78 }
79
80 // Apache with ldap as data source
81 if ($this->getSettings()->get('apache_enable_ldap')) {
82 return $this->handleLDAPDataSource($status);
83 }
84
85 $login = ilObjUser::_checkExternalAuthAccount('apache', $this->getCredentials()->getUsername());
87 if (!$usr_id) {
88 $this->getLogger()->info('Cannot find user id for external account: ' . $this->getCredentials()->getUsername());
89 $this->handleAuthenticationFail($status, 'err_wrong_login');
90 return false;
91 }
92
94 $status->setAuthenticatedUserId($usr_id);
95 return true;
96 }
97
102 {
103 $this->force_new_account = true;
104 if ($this->getSettings()->get('apache_enable_ldap')) {
105 return $this->handleLDAPDataSource($status);
106 }
107 }
108
113 {
114 $this->force_new_account = true;
115 if ($this->getSettings()->get('apache_enable_ldap')) {
116 return $this->handleLDAPDataSource($status);
117 }
118 }
119
123 public function getExternalAccountName()
124 {
126 }
127
131 public function setExternalAccountName(string $name) : void
132 {
133 $this->migration_account = $name;
134 }
135
139 public function getTriggerAuthMode()
140 {
141 return AUTH_APACHE;
142 }
143
147 public function getUserAuthModeName()
148 {
149 if ($this->getSettings()->get('apache_ldap_sid')) {
150 return 'ldap_' . (string) $this->getSettings()->get('apache_ldap_sid');
151 }
152
153 return 'apache';
154 }
155
159 protected function handleLDAPDataSource(ilAuthStatus $status) : bool
160 {
162 $this->getSettings()->get('apache_ldap_sid')
163 );
164
165 $this->getLogger()->debug('Using ldap data source with server configuration: ' . $server->getName());
166
167 $sync = new ilLDAPUserSynchronisation('ldap_' . $server->getServerId(), $server->getServerId());
168 $sync->setExternalAccount($this->getCredentials()->getUsername());
169 $sync->setUserData(array());
170 $sync->forceCreation($this->force_new_account);
171 $sync->forceReadLdapData(true);
172
173 try {
174 $internal_account = $sync->sync();
175 $this->getLogger()->debug('Internal account: ' . $internal_account);
176 } catch (UnexpectedValueException $e) {
177 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
178 $this->handleAuthenticationFail($status, 'err_wrong_login');
179 return false;
181 $this->handleAuthenticationFail($status, 'err_auth_ldap_failed');
182 return false;
183 }
185 // No syncronisation allowed => create Error
186 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
187 $this->handleAuthenticationFail($status, 'err_auth_ldap_no_ilias_user');
188 return false;
190 // Account migration required
191 $this->setExternalAccountName($this->getCredentials()->getUsername());
192 $this->getLogger()->info('Authentication failed: account migration required for external account: ' . $this->getCredentials()->getUsername());
194 return false;
195 }
196
198 $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
199 return true;
200 }
201}
An exception for terminatinating execution or to throw for unit testing.
const AUTH_APACHE
createNewAccount(ilAuthStatus $status)
@inheritDoc
migrateAccount(ilAuthStatus $status)
@inheritDoc
handleLDAPDataSource(ilAuthStatus $status)
@inheritDoc
doAuthentication(ilAuthStatus $status)
@inheritDoc
__construct(ilAuthCredentials $credentials)
Constructor.
Base class for authentication providers (radius, ldap, apache, ...)
getLogger()
Get logger.
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
Auth status implementation.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
Description of ilLDAPAccountMigrationRequiredException.
static getInstanceByServerId($a_server_id)
Get instance by server id.
Thrown in case of failed synchronisation settings.
Synchronization of user accounts used in auth container ldap, radius , cas,...
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
static _lookupId($a_user_str)
Lookup id by login.
ILIAS Setting Class.
static isLogin($a_login)
$login
Definition: cron.php:13
$server
Interface of auth credentials.
Standard interface for auth provider implementations.
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
settings()
Definition: settings.php:2