ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAuthProviderApache.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Authentication/classes/Provider/class.ilAuthProvider.php';
5include_once './Services/Authentication/interfaces/interface.ilAuthProviderInterface.php';
6include_once './Services/Authentication/interfaces/interface.ilAuthProviderAccountMigrationInterface.php';
7
15{
19
20 private $settings = null;
21
22 private $migration_account = '';
23 private $force_new_account = false;
24
25
31 {
32 parent::__construct($credentials);
33
34 include_once './Services/Administration/classes/class.ilSetting.php';
35 $this->settings = new ilSetting('apache_auth');
36 }
37
42 protected function getSettings()
43 {
44 return $this->settings;
45 }
46
52 {
53 if (!$this->getSettings()->get('apache_enable_auth')) {
54 $this->getLogger()->info('Apache auth disabled.');
55 $this->handleAuthenticationFail($status, 'apache_auth_err_disabled');
56 return false;
57 }
58
59 if (
60 !$this->getSettings()->get('apache_auth_indicator_name') ||
61 !$this->getSettings()->get('apache_auth_indicator_value')
62 ) {
63 $this->getLogger()->warning('Apache auth indicator match failure.');
64 $this->handleAuthenticationFail($status, 'apache_auth_err_indicator_match_failure');
65 return false;
66 }
67
68 if (
69 !in_array(
70 $_SERVER[$this->getSettings()->get('apache_auth_indicator_name')],
71 array_filter(array_map('trim', str_getcsv($this->getSettings()->get('apache_auth_indicator_value'))))
72 )
73 ) {
74 $this->getLogger()->warning('Apache authentication failed (indicator name <-> value');
75 $this->handleAuthenticationFail($status, 'err_wrong_login');
76 return false;
77 }
78
79 include_once './Services/Utilities/classes/class.ilUtil.php';
80 if (!ilUtil::isLogin($this->getCredentials()->getUsername())) {
81 $this->getLogger()->warning('Invalid login name given: ' . $this->getCredentials()->getUsername());
82 $this->handleAuthenticationFail($status, 'apache_auth_err_invalid_login');
83 return false;
84 }
85
86 if (!strlen($this->getCredentials()->getUsername())) {
87 $this->getLogger()->info('No username given');
88 $this->handleAuthenticationFail($status, 'err_wrong_login');
89 return false;
90 }
91
92 // Apache with ldap as data source
93 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
94 if ($this->getSettings()->get('apache_enable_ldap')) {
95 return $this->handleLDAPDataSource($status);
96 }
97
98 $login = ilObjUser::_checkExternalAuthAccount('apache', $this->getCredentials()->getUsername());
99 $usr_id = ilObjUser::_lookupId($login);
100 if (!$usr_id) {
101 $this->getLogger()->info('Cannot find user id for external account: ' . $this->getCredentials()->getUsername());
102 $this->handleAuthenticationFail($status, 'err_wrong_login');
103 return false;
104 }
105
107 $status->setAuthenticatedUserId($usr_id);
108 return true;
109 }
110
118 {
119 $this->force_new_account = true;
120 if ($this->getSettings()->get('apache_enable_ldap')) {
121 return $this->handleLDAPDataSource($status);
122 }
123 }
124
130 {
131 $this->force_new_account = true;
132 if ($this->getSettings()->get('apache_enable_ldap')) {
133 return $this->handleLDAPDataSource($status);
134 }
135 }
136
141 public function getExternalAccountName()
142 {
144 }
145
150 public function setExternalAccountName($a_name)
151 {
152 $this->migration_account = $a_name;
153 }
154
158 public function getTriggerAuthMode()
159 {
160 return AUTH_APACHE;
161 }
162
166 public function getUserAuthModeName()
167 {
168 if ($this->getSettings()->get('apache_ldap_sid')) {
169 return 'ldap_' . (string) $this->getSettings()->get('apache_ldap_sid');
170 }
171 return 'apache';
172 }
173
180 {
181 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
183 $this->getSettings()->get('apache_ldap_sid')
184 );
185
186 $this->getLogger()->debug('Using ldap data source with server configuration: ' . $server->getName());
187
188 include_once './Services/LDAP/classes/class.ilLDAPUserSynchronisation.php';
189 $sync = new ilLDAPUserSynchronisation('ldap_' . $server->getServerId(), $server->getServerId());
190 $sync->setExternalAccount($this->getCredentials()->getUsername());
191 $sync->setUserData(array());
192 $sync->forceCreation($this->force_new_account);
193 $sync->forceReadLdapData(true);
194
195 try {
196 $internal_account = $sync->sync();
197 $this->getLogger()->debug('Internal account: ' . $internal_account);
198 } catch (UnexpectedValueException $e) {
199 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
200 $this->handleAuthenticationFail($status, 'err_wrong_login');
201 return false;
203 // No syncronisation allowed => create Error
204 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
205 $this->handleAuthenticationFail($status, 'err_auth_ldap_no_ilias_user');
206 return false;
208 // Account migration required
209 $this->setExternalAccountName($this->getCredentials()->getUsername());
210 $this->getLogger()->info('Authentication failed: account migration required for external account: ' . $this->getCredentials()->getUsername());
212 return false;
213 }
215 $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
216 return true;
217 }
218}
An exception for terminatinating execution or to throw for unit testing.
const AUTH_APACHE
getTriggerAuthMode()
Get auth mode of current authentication type.
getExternalAccountName()
Get external account name.
createNewAccount(\ilAuthStatus $status)
Create new account for account migration.
handleLDAPDataSource(ilAuthStatus $status)
Handle ldap as data source.
__construct(\ilAuthCredentials $credentials)
Constructor.
doAuthentication(\ilAuthStatus $status)
getUserAuthModeName()
Get user auth mode name.
migrateAccount(\ilAuthStatus $status)
Migrate existing account Maybe ldap sync has to be performed here.
setExternalAccountName($a_name)
Set external account name.
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.
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)
$server
Definition: getUserInfo.php:12
Interface of auth credentials.
Standard interface for auth provider implementations.
$sync
settings()
Definition: settings.php:2
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']