ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSecuritySettings.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
35{
39
48
49 private static $instance = null;
50 private $db;
51 private $settings;
52
54
61
64
74
77
78 private $protect_admin_role = false;
79
87 private function __construct()
88 {
89 global $ilSetting,$ilDB;
90
91 $this->db = $ilDB;
92 $this->settings = $ilSetting;
93
94 $this->read();
95 }
96
104 public static function _getInstance()
105 {
106 if (is_object(self::$instance)) {
107 return self::$instance;
108 }
109 return self::$instance = new ilSecuritySettings();
110 }
111
112 public function getSecuritySettingsRefId()
113 {
114 return $this->ref_id;
115 }
116
124 public function setPasswordCharsAndNumbersEnabled($a_chars_and_numbers_enabled)
125 {
126 $this->password_chars_and_numbers_enabled = $a_chars_and_numbers_enabled;
127 }
128
137 {
139 }
140
148 public function setPasswordSpecialCharsEnabled($a_password_special_chars_enabled)
149 {
150 $this->password_special_chars_enabled = $a_password_special_chars_enabled;
151 }
152
161 {
163 }
164
170 public function setPasswordMinLength($a_password_min_length)
171 {
172 $this->password_min_length = $a_password_min_length;
173 }
174
180 public function getPasswordMinLength()
181 {
183 }
184
190 public function setPasswordMaxLength($a_password_max_length)
191 {
192 $this->password_max_length = $a_password_max_length;
193 }
194
200 public function getPasswordMaxLength()
201 {
203 }
204
210 public function setPasswordMaxAge($a_password_max_age)
211 {
212 $this->password_max_age = $a_password_max_age;
213 }
214
220 public function getPasswordMaxAge()
221 {
223 }
224
230 public function setLoginMaxAttempts($a_login_max_attempts)
231 {
232 $this->login_max_attempts = $a_login_max_attempts;
233 }
234
240 public function getLoginMaxAttempts()
241 {
243 }
244
250 public function setHTTPSEnabled($value)
251 {
252 $this->https_enable = $value;
253 }
254
260 public function isHTTPSEnabled()
261 {
262 return $this->https_enable;
263 }
264
272 public function setPasswordChangeOnFirstLoginEnabled($a_password_change_on_first_login_enabled)
273 {
274 $this->password_change_on_first_login_enabled = $a_password_change_on_first_login_enabled;
275 }
276
285 {
287 }
288
293 public function isAdminRoleProtected()
294 {
295 return (bool) $this->protect_admin_role;
296 }
297
302 public function protectedAdminRole($a_stat)
303 {
304 $this->protect_admin_role = $a_stat;
305 }
306
311 public function checkAdminRoleAccessible($a_usr_id)
312 {
313 global $rbacreview;
314
315 if (!$this->isAdminRoleProtected()) {
316 return true;
317 }
318 if ($rbacreview->isAssigned($a_usr_id, SYSTEM_ROLE_ID)) {
319 return true;
320 }
321 return false;
322 }
323
329 public function save()
330 {
331 $this->settings->set('https', (int) $this->isHTTPSEnabled());
332
333 $this->settings->set('ps_password_chars_and_numbers_enabled', (bool) $this->isPasswordCharsAndNumbersEnabled());
334 $this->settings->set('ps_password_special_chars_enabled', (bool) $this->isPasswordSpecialCharsEnabled());
335 $this->settings->set('ps_password_min_length', (int) $this->getPasswordMinLength());
336 $this->settings->set('ps_password_max_length', (int) $this->getPasswordMaxLength());
337 $this->settings->set('ps_password_max_age', (int) $this->getPasswordMaxAge());
338 $this->settings->set('ps_login_max_attempts', (int) $this->getLoginMaxAttempts());
339 $this->settings->set('ps_password_uppercase_chars_num', (int) $this->getPasswordNumberOfUppercaseChars());
340 $this->settings->set('ps_password_lowercase_chars_num', (int) $this->getPasswordNumberOfLowercaseChars());
341 $this->settings->set('ps_password_must_not_contain_loginame', (int) $this->getPasswordMustNotContainLoginnameStatus());
342
343 $this->settings->set('ps_password_change_on_first_login_enabled', (bool) $this->isPasswordChangeOnFirstLoginEnabled());
344 $this->settings->set('ps_prevent_simultaneous_logins', (int) $this->isPreventionOfSimultaneousLoginsEnabled());
345 $this->settings->set('ps_protect_admin', (int) $this->isAdminRoleProtected());
346 }
354 private function read()
355 {
356 global $ilDB;
357
358 $query = "SELECT object_reference.ref_id FROM object_reference,tree,object_data " .
359 "WHERE tree.parent = " . $ilDB->quote(SYSTEM_FOLDER_ID, 'integer') . " " .
360 "AND object_data.type = 'ps' " .
361 "AND object_reference.ref_id = tree.child " .
362 "AND object_reference.obj_id = object_data.obj_id";
363 $res = $this->db->query($query);
365 $this->ref_id = $row["ref_id"];
366
367 $this->https_enable = (boolean) $this->settings->get('https', false);
368
369 $this->password_chars_and_numbers_enabled = (bool) $this->settings->get('ps_password_chars_and_numbers_enabled', self::DEFAULT_PASSWORD_CHARS_AND_NUMBERS_ENABLED);
370 $this->password_special_chars_enabled = (bool) $this->settings->get('ps_password_special_chars_enabled', self::DEFAULT_PASSWORD_SPECIAL_CHARS_ENABLED);
371 $this->password_min_length = (int) $this->settings->get('ps_password_min_length', self::DEFAULT_PASSWORD_MIN_LENGTH);
372 $this->password_max_length = (int) $this->settings->get('ps_password_max_length', self::DEFAULT_PASSWORD_MAX_LENGTH);
373 $this->password_max_age = (int) $this->settings->get('ps_password_max_age', self::DEFAULT_PASSWORD_MAX_AGE);
374 $this->login_max_attempts = (int) $this->settings->get('ps_login_max_attempts', self::DEFAULT_LOGIN_MAX_ATTEMPTS);
375 $this->password_ucase_chars_num = (int) $this->settings->get('ps_password_uppercase_chars_num', 0);
376 $this->password_lcase_chars_num = (int) $this->settings->get('ps_password_lowercase_chars_num', 0);
377 $this->password_must_not_contain_loginname = $this->settings->get('ps_password_must_not_contain_loginame', 0) == '1' ? true : false;
378
379 $this->password_change_on_first_login_enabled = (bool) $this->settings->get('ps_password_change_on_first_login_enabled', self::DEFAULT_PASSWORD_CHANGE_ON_FIRST_LOGIN_ENABLED);
380 $this->prevent_simultaneous_logins = (bool) $this->settings->get('ps_prevent_simultaneous_logins', self::DEFAULT_PREVENT_SIMULTANEOUS_LOGINS);
381
382 $this->protect_admin_role = (bool) $this->settings->get('ps_protect_admin', $this->protect_admin_role);
383 }
384
390 public function validate(ilPropertyFormGUI $a_form = null)
391 {
392 $code = null;
393
394 if ($a_form) {
395 include_once "Services/PrivacySecurity/classes/class.ilObjPrivacySecurityGUI.php";
396 }
397
398 include_once './Services/Http/classes/class.ilHTTPS.php';
399
400 if ($this->isHTTPSEnabled()) {
401 if (!ilHTTPS::_checkHTTPS()) {
403 if (!$a_form) {
404 return $code;
405 } else {
406 $a_form->getItemByPostVar('https_enabled')
408 }
409 }
410 }
411
412 if ($this->getPasswordMinLength() < 0) {
414 if (!$a_form) {
415 return $code;
416 } else {
417 $a_form->getItemByPostVar('password_min_length')
419 }
420 }
421
422 if ($this->getPasswordMaxLength() < 0) {
424 if (!$a_form) {
425 return $code;
426 } else {
427 $a_form->getItemByPostVar('password_max_length')
429 }
430 }
431
433
436 if ($this->getPasswordNumberOfUppercaseChars() > 0) {
438 }
439 if ($this->getPasswordNumberOfLowercaseChars() > 0) {
441 }
442 $password_min_length_error_code = self::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN1;
443 }
444
447 $password_min_length_error_code = self::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2;
448
449 if ($this->isPasswordSpecialCharsEnabled()) {
451 $password_min_length_error_code = self::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3;
452 }
453 } elseif ($password_min_length > 1 && $this->isPasswordSpecialCharsEnabled()) {
455 $password_min_length_error_code = self::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3;
456 }
457
458 if ($this->getPasswordMinLength() > 0 && $this->getPasswordMinLength() < $password_min_length) {
459 $code = $password_min_length_error_code;
460 if (!$a_form) {
461 return $code;
462 } else {
463 $a_form->getItemByPostVar('password_min_length')
465 }
466 }
467 if ($this->getPasswordMaxLength() > 0 && $this->getPasswordMaxLength() < $this->getPasswordMinLength()) {
469 if (!$a_form) {
470 return $code;
471 } else {
472 $a_form->getItemByPostVar('password_max_length')
474 }
475 }
476
477 if ($this->getPasswordMaxAge() < 0) {
479 if (!$a_form) {
480 return $code;
481 } else {
482 $a_form->getItemByPostVar('password_max_age')
484 }
485 }
486
487 if ($this->getLoginMaxAttempts() < 0) {
489 if (!$a_form) {
490 return $code;
491 } else {
492 $a_form->getItemByPostVar('login_max_attempts')
494 }
495 }
496
497 /*
498 * todo: have to check for local auth if first login password change is enabled??
499 * than: add errorcode
500 */
501
502 if (!$a_form) {
503 return 0;
504 } else {
505 return !(bool) $code;
506 }
507 }
508
515 {
517 }
518
524 public function setPreventionOfSimultaneousLogins($value)
525 {
526 $this->prevent_simultaneous_logins = (bool) $value;
527 }
528
534 {
535 $this->password_ucase_chars_num = $password_ucase_chars_num;
536 }
537
543 {
545 }
546
552 {
553 $this->password_lcase_chars_num = $password_lcase_chars_num;
554 }
555
561 {
563 }
564
570 {
571 $this->password_must_not_contain_loginname = $status;
572 }
573
579 {
581 }
582}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
static _checkHTTPS()
static method to check if https connections are possible for this server @access public
static getErrorMessage($code)
return error message for error code
This class represents a property form user interface.
Singleton class that stores all security settings.
setLoginMaxAttempts($a_login_max_attempts)
set the maximum count of login attempts
setPasswordMaxAge($a_password_max_age)
set the maximum password age
checkAdminRoleAccessible($a_usr_id)
Check if the administrator role is accessible for a specific user.
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2
validate(ilPropertyFormGUI $a_form=null)
validate settings
setPasswordMaxLength($a_password_max_length)
set the maximum length for passwords
isPasswordSpecialCharsEnabled()
get boolean if the passwords have to contain special characters
isAdminRoleProtected()
Check if admin role is protected.
getLoginMaxAttempts()
get the maximum count of login attempts
setPasswordCharsAndNumbersEnabled($a_chars_and_numbers_enabled)
set if the passwords have to contain characters and numbers
getPasswordMustNotContainLoginnameStatus()
Return whether the password must not contain the loginname or not.
const SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS
getPasswordMinLength()
get the minimum length for passwords
setPasswordNumberOfUppercaseChars($password_ucase_chars_num)
Set number of uppercase characters required.
protectedAdminRole($a_stat)
Set admin role protection status.
static $SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3
setPasswordChangeOnFirstLoginEnabled($a_password_change_on_first_login_enabled)
set if the passwords have to be changed by users on first login
getPasswordMaxLength()
get the maximum length for passwords
setPasswordMustNotContainLoginnameStatus($status)
Set whether the password must not contain the loginname or not.
isPreventionOfSimultaneousLoginsEnabled()
Prevention of simultaneous logins with the same account.
setPasswordSpecialCharsEnabled($a_password_special_chars_enabled)
set if the passwords have to contain special characters
getPasswordNumberOfUppercaseChars()
Returns number of uppercase characters required.
isHTTPSEnabled()
read access to https enabled property
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE
isPasswordCharsAndNumbersEnabled()
get boolean if the passwords have to contain characters and numbers
isPasswordChangeOnFirstLoginEnabled()
get boolean if the passwords have to be changed by users on first login
setHTTPSEnabled($value)
Enable https for certain scripts.
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MAX_LENGTH_LESS_MIN_LENGTH
setPreventionOfSimultaneousLogins($value)
Enable/Disable prevention of simultaneous logins with the same account.
getPasswordMaxAge()
get the maximum password age
const DEFAULT_PASSWORD_CHANGE_ON_FIRST_LOGIN_ENABLED
setPasswordNumberOfLowercaseChars($password_lcase_chars_num)
Set number of lowercase characters required.
setPasswordMinLength($a_password_min_length)
set the minimum length for passwords
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN1
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH
static $SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE
static _getInstance()
Get instance of ilSecuritySettings.
getPasswordNumberOfLowercaseChars()
Returns number of lowercase characters required.
__construct()
Private constructor: use _getInstance()
$code
Definition: example_050.php:99
global $ilSetting
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
global $ilDB