ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
72 public static function _getInstance()
73 {
74 if(self::$instance)
75 {
76 return self::$instance;
77 }
78 return self::$instance = new ilAuthModeDetermination();
79 }
80
89 public function isManualSelection()
90 {
91 return $this->kind == self::TYPE_MANUAL;
92 }
93
100 public function getKind()
101 {
102 return $this->kind;
103 }
104
112 public function setKind($a_kind)
113 {
114 $this->kind = $a_kind;
115 }
116
123 public function getAuthModeSequence($a_username = '')
124 {
125 if(!strlen($a_username))
126 {
127 return $this->position ? $this->position : array();
128 }
129 $sorted = array();
130
131 ilLoggerFactory::getLogger('auth')->dump($this->position, ilLogLevel::DEBUG);
132
133 foreach($this->position as $auth_key)
134 {
135 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
136 $sid = ilLDAPServer::getServerIdByAuthMode($auth_key);
137 if($sid)
138 {
140 ilLoggerFactory::getLogger('auth')->debug('Validating username filter for ' . $server->getName());
141 if(strlen($server->getUsernameFilter()))
142 {
143 //#17731
144 $pattern = str_replace('*','.*?', $server->getUsernameFilter());
145
146 if(preg_match('/^'.$pattern.'$/', $a_username))
147 {
148 ilLoggerFactory::getLogger('auth')->debug('Filter matches for ' . $a_username);
149 array_unshift($sorted, $auth_key);
150 continue;
151 }
152 ilLoggerFactory::getLogger('auth')->debug('Filter matches not for ' . $a_username. ' <-> ' . $server->getUsernameFilter());
153 }
154 }
155 $sorted[] = $auth_key;
156 }
157
158 ilLoggerFactory::getLogger('auth')->dump($this->position, ilLogLevel::DEBUG);
159
160 return (array) $sorted;
161 }
162
169 public function getCountActiveAuthModes()
170 {
171 return count($this->position);
172 }
173
181 public function setAuthModeSequence($a_pos)
182 {
183 $this->position = $a_pos;
184 }
185
193 public function save()
194 {
195 $this->settings->deleteAll();
196
197 $this->settings->set('kind',$this->getKind());
198
199 $counter = 0;
200 foreach($this->position as $auth_mode)
201 {
202 $this->settings->set((string) $counter++,$auth_mode);
203 }
204 }
205
206
214 private function read()
215 {
216 global $ilSetting;
217
218 $this->kind = $this->settings->get('kind',self::TYPE_MANUAL);
219
220 // begin-patch ldap_multiple
221 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
222 // end-patch ldap_multiple
223
224 include_once('Services/Radius/classes/class.ilRadiusSettings.php');
225 $rad_settings = ilRadiusSettings::_getInstance();
226 $rad_active = $rad_settings->isActive();
227
228 $soap_active = $ilSetting->get('soap_auth_active',false);
229
230 // apache settings
231 $apache_settings = new ilSetting('apache_auth');
232 $apache_active = $apache_settings->get('apache_enable_auth');
233
234 // Check if active
235 // begin-patch ldap_multiple
236 $i = 0;
237 while(true)
238 {
239 $auth_mode = $this->settings->get((string) $i++,FALSE);
240 if($auth_mode === FALSE)
241 {
242 break;
243 }
244 if($auth_mode)
245 {
246 // begin-patch ldap_multiple
247 switch((int) $auth_mode)
248 {
249 case AUTH_LOCAL:
250 $this->position[] = $auth_mode;
251 break;
252
253 case AUTH_LDAP:
254 $auth_id = ilLDAPServer::getServerIdByAuthMode($auth_mode);
256
257 if($server->isActive())
258 {
259 $this->position[] = $auth_mode;
260 }
261 break;
262
263 case AUTH_RADIUS:
264 if($rad_active)
265 {
266 $this->position[] = $auth_mode;
267 }
268 break;
269
270 case AUTH_SOAP:
271 if($soap_active)
272 {
273 $this->position[] = $auth_mode;
274 }
275 break;
276
277 case AUTH_APACHE:
278 if($apache_active)
279 {
280 $this->position[] = $auth_mode;
281 }
282 break;
283
284 // begin-patch auth_plugin
285 default:
286 foreach(ilAuthUtils::getAuthPlugins() as $pl)
287 {
288 if($pl->isAuthActive($auth_mode))
289 {
290 $this->position[] = $auth_mode;
291 }
292 }
293 break;
294 // end-patch auth_plugin
295
296 }
297 }
298 }
299 // end-patch ldap_multiple
300
301 // Append missing active auth modes
302 if(!in_array(AUTH_LOCAL,$this->position))
303 {
304 $this->position[] = AUTH_LOCAL;
305 }
306 // begin-patch ldap_multiple
307 foreach(ilLDAPServer::_getActiveServerList() as $sid)
308 {
310 if($server->isActive())
311 {
312 if(!in_array(AUTH_LDAP.'_'.$sid, $this->position))
313 {
314 $this->position[] = (AUTH_LDAP.'_'.$sid);
315 }
316 }
317
318 }
319 // end-patch ldap_multiple
320 if($rad_active)
321 {
322 if(!in_array(AUTH_RADIUS,$this->position))
323 {
324 $this->position[] = AUTH_RADIUS;
325 }
326
327 }
328 if($soap_active)
329 {
330 if(!in_array(AUTH_SOAP,$this->position))
331 {
332 $this->position[] = AUTH_SOAP;
333 }
334 }
335 if($apache_active)
336 {
337 if(!in_array(AUTH_APACHE,$this->position))
338 {
339 $this->position[] = AUTH_APACHE;
340 }
341 }
342 // begin-patch auth_plugin
343 foreach(ilAuthUtils::getAuthPlugins() as $pl)
344 {
345 foreach($pl->getAuthIds() as $auth_id)
346 {
347 if($pl->isAuthActive($auth_id))
348 {
349 if(!in_array($auth_id, $this->position))
350 {
351 $this->position[] = $auth_id;
352 }
353 }
354 }
355 }
356 // end-patch auth_plugin
357 }
358}
359
360
361?>
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.
$server
global $ilSetting
Definition: privfeed.php:40
global $ilDB