ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAuthModeDetermination.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
32include_once('Services/Authentication/classes/class.ilAuthUtils.php');
33
35{
36 const TYPE_MANUAL = 0;
37 const TYPE_AUTOMATIC = 1;
38
39 protected static $instance = null;
40
41 protected $db = null;
42 protected $settings = null;
43
44 protected $kind = 0;
45 protected $position = array();
46
47
54 private function __construct()
55 {
56 global $ilSetting,$ilDB;
57
58 $this->db = $ilDB;
59
60 include_once "./Services/Administration/classes/class.ilSetting.php";
61 $this->settings = new ilSetting("auth_mode_determination");
62 $this->read();
63 }
64
73 public static function _getInstance()
74 {
75 if(self::$instance)
76 {
77 return self::$instance;
78 }
79 return self::$instance = new ilAuthModeDetermination();
80 }
81
90 public function isManualSelection()
91 {
92 return $this->kind == self::TYPE_MANUAL;
93 }
94
101 public function getKind()
102 {
103 return $this->kind;
104 }
105
113 public function setKind($a_kind)
114 {
115 $this->kind = $a_kind;
116 }
117
124 public function getAuthModeSequence($a_username = '')
125 {
126 if(!strlen($a_username))
127 {
128 return $this->position ? $this->position : array();
129 }
130 $sorted = array();
131
132 foreach($this->position as $auth_key)
133 {
134 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
135 $sid = ilLDAPServer::getServerIdByAuthMode($auth_key);
136 if($sid)
137 {
139 ilLoggerFactory::getLogger('auth')->debug('Validating username filter for ' . $server->getName());
140 if(strlen($server->getUsernameFilter()))
141 {
142 //#17731
143 $pattern = str_replace('*','.*?', $server->getUsernameFilter());
144
145 if(preg_match('/^'.$pattern.'$/', $a_username))
146 {
147 ilLoggerFactory::getLogger('auth')->debug('Filter matches for ' . $a_username);
148 array_unshift($sorted, $auth_key);
149 continue;
150 }
151 ilLoggerFactory::getLogger('auth')->debug('Filter matches not for ' . $a_username. ' <-> ' . $server->getUsernameFilter());
152 }
153 }
154 $sorted[] = $auth_key;
155 }
156
157 return (array) $sorted;
158 }
159
166 public function getCountActiveAuthModes()
167 {
168 return count($this->position);
169 }
170
178 public function setAuthModeSequence($a_pos)
179 {
180 $this->position = $a_pos;
181 }
182
190 public function save()
191 {
192 $this->settings->deleteAll();
193
194 $this->settings->set('kind',$this->getKind());
195
196 $counter = 0;
197 foreach($this->position as $auth_mode)
198 {
199 $this->settings->set((string) $counter++,$auth_mode);
200 }
201 }
202
203
211 private function read()
212 {
213 global $ilSetting;
214
215 $this->kind = $this->settings->get('kind',self::TYPE_MANUAL);
216
217 // begin-patch ldap_multiple
218 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
219 // end-patch ldap_multiple
220
221 include_once('Services/Radius/classes/class.ilRadiusSettings.php');
222 $rad_settings = ilRadiusSettings::_getInstance();
223 $rad_active = $rad_settings->isActive();
224
225 $soap_active = $ilSetting->get('soap_auth_active',false);
226
227 // apache settings
228 $apache_settings = new ilSetting('apache_auth');
229 $apache_active = $apache_settings->get('apache_enable_auth');
230
231 // Check if active
232 // begin-patch ldap_multiple
233 $i = 0;
234 while(true)
235 {
236 $auth_mode = $this->settings->get((string) $i++,FALSE);
237 if($auth_mode === FALSE)
238 {
239 break;
240 }
241 if($auth_mode)
242 {
243 // begin-patch ldap_multiple
244 switch((int) $auth_mode)
245 {
246 case AUTH_LOCAL:
247 $this->position[] = $auth_mode;
248 break;
249
250 case AUTH_LDAP:
251 $auth_id = ilLDAPServer::getServerIdByAuthMode($auth_mode);
253
254 if($server->isActive())
255 {
256 $this->position[] = $auth_mode;
257 }
258 break;
259
260 case AUTH_RADIUS:
261 if($rad_active)
262 {
263 $this->position[] = $auth_mode;
264 }
265 break;
266
267 case AUTH_SOAP:
268 if($soap_active)
269 {
270 $this->position[] = $auth_mode;
271 }
272 break;
273
274 case AUTH_APACHE:
275 if($apache_active)
276 {
277 $this->position[] = $auth_mode;
278 }
279 break;
280
281 // begin-patch auth_plugin
282 default:
283 foreach(ilAuthUtils::getAuthPlugins() as $pl)
284 {
285 if($pl->isAuthActive($auth_mode))
286 {
287 $this->position[] = $auth_mode;
288 }
289 }
290 break;
291 // end-patch auth_plugin
292
293 }
294 }
295 }
296 // end-patch ldap_multiple
297
298 // Append missing active auth modes
299 if(!in_array(AUTH_LOCAL,$this->position))
300 {
301 $this->position[] = AUTH_LOCAL;
302 }
303 // begin-patch ldap_multiple
304 foreach(ilLDAPServer::_getActiveServerList() as $sid)
305 {
307 if($server->isActive())
308 {
309 if(!in_array(AUTH_LDAP.'_'.$sid, $this->position))
310 {
311 $this->position[] = (AUTH_LDAP.'_'.$sid);
312 }
313 }
314
315 }
316 // end-patch ldap_multiple
317 if($rad_active)
318 {
319 if(!in_array(AUTH_RADIUS,$this->position))
320 {
321 $this->position[] = AUTH_RADIUS;
322 }
323
324 }
325 if($soap_active)
326 {
327 if(!in_array(AUTH_SOAP,$this->position))
328 {
329 $this->position[] = AUTH_SOAP;
330 }
331 }
332 if($apache_active)
333 {
334 if(!in_array(AUTH_APACHE,$this->position))
335 {
336 $this->position[] = AUTH_APACHE;
337 }
338 }
339 // begin-patch auth_plugin
340 foreach(ilAuthUtils::getAuthPlugins() as $pl)
341 {
342 foreach($pl->getAuthIds() as $auth_id)
343 {
344 if($pl->isAuthActive($auth_id))
345 {
346 if(!in_array($auth_id, $this->position))
347 {
348 $this->position[] = $auth_id;
349 }
350 }
351 }
352 }
353 // end-patch auth_plugin
354 }
355}
356
357
358?>
An exception for terminatinating execution or to throw for unit testing.
const AUTH_APACHE
const AUTH_LDAP
const AUTH_LOCAL
const AUTH_RADIUS
const AUTH_SOAP
getCountActiveAuthModes()
get number of auth modes
getAuthModeSequence($a_username='')
get auth mode sequence
__construct()
Constructor (Singleton)
setKind($a_kind)
set kind of determination
setAuthModeSequence($a_pos)
set auth mode sequence
static getAuthPlugins()
Get active enabled auth plugins.
static getServerIdByAuthMode($a_auth_mode)
Get auth id by auth mode.
static getInstanceByServerId($a_server_id)
Get instance by server id.
static _getActiveServerList()
Get active server list.
static getLogger($a_component_id)
Get component logger.
static _getInstance()
singleton get instance
ILIAS Setting Class.
$counter
$server
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
global $ilDB