ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
57
58 $ilSetting = $DIC['ilSetting'];
59 $ilDB = $DIC['ilDB'];
60
61 $this->db = $ilDB;
62
63 include_once "./Services/Administration/classes/class.ilSetting.php";
64 $this->settings = new ilSetting("auth_mode_determination");
65 $this->read();
66 }
67
76 public static function _getInstance()
77 {
78 if (self::$instance) {
79 return self::$instance;
80 }
81 return self::$instance = new ilAuthModeDetermination();
82 }
83
92 public function isManualSelection()
93 {
94 return $this->kind == self::TYPE_MANUAL;
95 }
96
103 public function getKind()
104 {
105 return $this->kind;
106 }
107
115 public function setKind($a_kind)
116 {
117 $this->kind = $a_kind;
118 }
119
126 public function getAuthModeSequence($a_username = '')
127 {
128 if (!strlen($a_username)) {
129 return $this->position ? $this->position : array();
130 }
131 $sorted = array();
132
133 foreach ($this->position as $auth_key) {
134 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
135 $sid = ilLDAPServer::getServerIdByAuthMode($auth_key);
136 if ($sid) {
138 ilLoggerFactory::getLogger('auth')->debug('Validating username filter for ' . $server->getName());
139 if (strlen($server->getUsernameFilter())) {
140 //#17731
141 $pattern = str_replace('*', '.*?', $server->getUsernameFilter());
142
143 if (preg_match('/^' . $pattern . '$/', $a_username)) {
144 ilLoggerFactory::getLogger('auth')->debug('Filter matches for ' . $a_username);
145 array_unshift($sorted, $auth_key);
146 continue;
147 }
148 ilLoggerFactory::getLogger('auth')->debug('Filter matches not for ' . $a_username . ' <-> ' . $server->getUsernameFilter());
149 }
150 }
151 $sorted[] = $auth_key;
152 }
153
154 return (array) $sorted;
155 }
156
163 public function getCountActiveAuthModes()
164 {
165 return count($this->position);
166 }
167
175 public function setAuthModeSequence($a_pos)
176 {
177 $this->position = $a_pos;
178 }
179
187 public function save()
188 {
189 $this->settings->deleteAll();
190
191 $this->settings->set('kind', $this->getKind());
192
193 $counter = 0;
194 foreach ($this->position as $auth_mode) {
195 $this->settings->set((string) $counter++, $auth_mode);
196 }
197 }
198
199
207 private function read()
208 {
209 global $DIC;
210
211 $ilSetting = $DIC['ilSetting'];
212
213 $this->kind = $this->settings->get('kind', self::TYPE_MANUAL);
214
215 // begin-patch ldap_multiple
216 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
217 // end-patch ldap_multiple
218
219 include_once('Services/Radius/classes/class.ilRadiusSettings.php');
220 $rad_settings = ilRadiusSettings::_getInstance();
221 $rad_active = $rad_settings->isActive();
222
223 $soap_active = $ilSetting->get('soap_auth_active', false);
224
225 // apache settings
226 $apache_settings = new ilSetting('apache_auth');
227 $apache_active = $apache_settings->get('apache_enable_auth');
228
229 // Check if active
230 // begin-patch ldap_multiple
231 $i = 0;
232 while (true) {
233 $auth_mode = $this->settings->get((string) $i++, false);
234 if ($auth_mode === false) {
235 break;
236 }
237 if ($auth_mode) {
238 // begin-patch ldap_multiple
239 switch ((int) $auth_mode) {
240 case AUTH_LOCAL:
241 $this->position[] = $auth_mode;
242 break;
243
244 case AUTH_LDAP:
245 $auth_id = ilLDAPServer::getServerIdByAuthMode($auth_mode);
247
248 if ($server->isActive()) {
249 $this->position[] = $auth_mode;
250 }
251 break;
252
253 case AUTH_RADIUS:
254 if ($rad_active) {
255 $this->position[] = $auth_mode;
256 }
257 break;
258
259 case AUTH_SOAP:
260 if ($soap_active) {
261 $this->position[] = $auth_mode;
262 }
263 break;
264
265 case AUTH_APACHE:
266 if ($apache_active) {
267 $this->position[] = $auth_mode;
268 }
269 break;
270
271 // begin-patch auth_plugin
272 default:
273 foreach (ilAuthUtils::getAuthPlugins() as $pl) {
274 if ($pl->isAuthActive($auth_mode)) {
275 $this->position[] = $auth_mode;
276 }
277 }
278 break;
279 // end-patch auth_plugin
280
281 }
282 }
283 }
284 // end-patch ldap_multiple
285
286 // Append missing active auth modes
287 if (!in_array(AUTH_LOCAL, $this->position)) {
288 $this->position[] = AUTH_LOCAL;
289 }
290 // begin-patch ldap_multiple
291 foreach (ilLDAPServer::_getActiveServerList() as $sid) {
293 if ($server->isActive()) {
294 if (!in_array(AUTH_LDAP . '_' . $sid, $this->position)) {
295 $this->position[] = (AUTH_LDAP . '_' . $sid);
296 }
297 }
298 }
299 // end-patch ldap_multiple
300 if ($rad_active) {
301 if (!in_array(AUTH_RADIUS, $this->position)) {
302 $this->position[] = AUTH_RADIUS;
303 }
304 }
305 if ($soap_active) {
306 if (!in_array(AUTH_SOAP, $this->position)) {
307 $this->position[] = AUTH_SOAP;
308 }
309 }
310 if ($apache_active) {
311 if (!in_array(AUTH_APACHE, $this->position)) {
312 $this->position[] = AUTH_APACHE;
313 }
314 }
315 // begin-patch auth_plugin
316 foreach (ilAuthUtils::getAuthPlugins() as $pl) {
317 foreach ($pl->getAuthIds() as $auth_id) {
318 if ($pl->isAuthActive($auth_id)) {
319 if (!in_array($auth_id, $this->position)) {
320 $this->position[] = $auth_id;
321 }
322 }
323 }
324 }
325 // end-patch auth_plugin
326 }
327}
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.
$server
$i
Definition: metadata.php:24
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
global $ilDB
$DIC
Definition: xapitoken.php:46