ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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 return $this->position ? $this->position : array();
127 }
128 $sorted = array();
129
130 foreach ($this->position as $auth_key) {
131 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
132 $sid = ilLDAPServer::getServerIdByAuthMode($auth_key);
133 if ($sid) {
135 ilLoggerFactory::getLogger('auth')->debug('Validating username filter for ' . $server->getName());
136 if (strlen($server->getUsernameFilter())) {
137 //#17731
138 $pattern = str_replace('*', '.*?', $server->getUsernameFilter());
139
140 if (preg_match('/^' . $pattern . '$/', $a_username)) {
141 ilLoggerFactory::getLogger('auth')->debug('Filter matches for ' . $a_username);
142 array_unshift($sorted, $auth_key);
143 continue;
144 }
145 ilLoggerFactory::getLogger('auth')->debug('Filter matches not for ' . $a_username . ' <-> ' . $server->getUsernameFilter());
146 }
147 }
148 $sorted[] = $auth_key;
149 }
150
151 return (array) $sorted;
152 }
153
160 public function getCountActiveAuthModes()
161 {
162 return count($this->position);
163 }
164
172 public function setAuthModeSequence($a_pos)
173 {
174 $this->position = $a_pos;
175 }
176
184 public function save()
185 {
186 $this->settings->deleteAll();
187
188 $this->settings->set('kind', $this->getKind());
189
190 $counter = 0;
191 foreach ($this->position as $auth_mode) {
192 $this->settings->set((string) $counter++, $auth_mode);
193 }
194 }
195
196
204 private function read()
205 {
206 global $ilSetting;
207
208 $this->kind = $this->settings->get('kind', self::TYPE_MANUAL);
209
210 // begin-patch ldap_multiple
211 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
212 // end-patch ldap_multiple
213
214 include_once('Services/Radius/classes/class.ilRadiusSettings.php');
215 $rad_settings = ilRadiusSettings::_getInstance();
216 $rad_active = $rad_settings->isActive();
217
218 $soap_active = $ilSetting->get('soap_auth_active', false);
219
220 // apache settings
221 $apache_settings = new ilSetting('apache_auth');
222 $apache_active = $apache_settings->get('apache_enable_auth');
223
224 // Check if active
225 // begin-patch ldap_multiple
226 $i = 0;
227 while (true) {
228 $auth_mode = $this->settings->get((string) $i++, false);
229 if ($auth_mode === false) {
230 break;
231 }
232 if ($auth_mode) {
233 // begin-patch ldap_multiple
234 switch ((int) $auth_mode) {
235 case AUTH_LOCAL:
236 $this->position[] = $auth_mode;
237 break;
238
239 case AUTH_LDAP:
240 $auth_id = ilLDAPServer::getServerIdByAuthMode($auth_mode);
242
243 if ($server->isActive()) {
244 $this->position[] = $auth_mode;
245 }
246 break;
247
248 case AUTH_RADIUS:
249 if ($rad_active) {
250 $this->position[] = $auth_mode;
251 }
252 break;
253
254 case AUTH_SOAP:
255 if ($soap_active) {
256 $this->position[] = $auth_mode;
257 }
258 break;
259
260 case AUTH_APACHE:
261 if ($apache_active) {
262 $this->position[] = $auth_mode;
263 }
264 break;
265
266 // begin-patch auth_plugin
267 default:
268 foreach (ilAuthUtils::getAuthPlugins() as $pl) {
269 if ($pl->isAuthActive($auth_mode)) {
270 $this->position[] = $auth_mode;
271 }
272 }
273 break;
274 // end-patch auth_plugin
275
276 }
277 }
278 }
279 // end-patch ldap_multiple
280
281 // Append missing active auth modes
282 if (!in_array(AUTH_LOCAL, $this->position)) {
283 $this->position[] = AUTH_LOCAL;
284 }
285 // begin-patch ldap_multiple
286 foreach (ilLDAPServer::_getActiveServerList() as $sid) {
288 if ($server->isActive()) {
289 if (!in_array(AUTH_LDAP . '_' . $sid, $this->position)) {
290 $this->position[] = (AUTH_LDAP . '_' . $sid);
291 }
292 }
293 }
294 // end-patch ldap_multiple
295 if ($rad_active) {
296 if (!in_array(AUTH_RADIUS, $this->position)) {
297 $this->position[] = AUTH_RADIUS;
298 }
299 }
300 if ($soap_active) {
301 if (!in_array(AUTH_SOAP, $this->position)) {
302 $this->position[] = AUTH_SOAP;
303 }
304 }
305 if ($apache_active) {
306 if (!in_array(AUTH_APACHE, $this->position)) {
307 $this->position[] = AUTH_APACHE;
308 }
309 }
310 // begin-patch auth_plugin
311 foreach (ilAuthUtils::getAuthPlugins() as $pl) {
312 foreach ($pl->getAuthIds() as $auth_id) {
313 if ($pl->isAuthActive($auth_id)) {
314 if (!in_array($auth_id, $this->position)) {
315 $this->position[] = $auth_id;
316 }
317 }
318 }
319 }
320 // end-patch auth_plugin
321 }
322}
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
$i
Definition: disco.tpl.php:19
$server
Definition: getUserInfo.php:12
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
global $ilDB