ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilAuthModeDetermination Class Reference
+ Collaboration diagram for ilAuthModeDetermination:

Public Member Functions

 isManualSelection ()
 
 getKind ()
 
 setKind (int $a_kind)
 
 getAuthModeSequence (string $a_username='')
 
 getCountActiveAuthModes ()
 
 setAuthModeSequence (array $a_pos)
 
 save ()
 

Static Public Member Functions

static _getInstance ()
 

Data Fields

const int TYPE_MANUAL = 0
 
const int TYPE_AUTOMATIC = 1
 

Private Member Functions

 __construct ()
 
 read ()
 

Private Attributes

ilLogger $logger
 
ilSetting $settings
 
ilSetting $commonSettings
 
int $kind = self::TYPE_MANUAL
 
array $position = []
 

Static Private Attributes

static ilAuthModeDetermination $instance = null
 

Detailed Description

Definition at line 21 of file class.ilAuthModeDetermination.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthModeDetermination::__construct ( )
private

Definition at line 35 of file class.ilAuthModeDetermination.php.

References $DIC, ILIAS\Repository\logger(), read(), and ILIAS\Repository\settings().

36  {
37  global $DIC;
38 
39  $this->logger = $DIC->logger()->auth();
40 
41  $this->commonSettings = $DIC->settings();
42 
43  $this->settings = new ilSetting('auth_mode_determination');
44  $this->read();
45  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

◆ getAuthModeSequence()

ilAuthModeDetermination::getAuthModeSequence ( string  $a_username = '')
Returns
list<numeric-string|int|string>

Definition at line 80 of file class.ilAuthModeDetermination.php.

References $message, $position, $server, ilLDAPServer\getInstanceByServerId(), ilLDAPServer\getServerIdByAuthMode(), ILIAS\Repository\logger(), and ilAuthUtils\REGEX_DELIMITERS.

80  : array
81  {
82  if ($a_username === '') {
83  return $this->position;
84  }
85 
86  $sorted = [];
87  foreach ($this->position as $auth_key) {
88  $sid = ilLDAPServer::getServerIdByAuthMode((string) $auth_key);
89  if ($sid) {
91  $this->logger->debug('Validating username filter for ' . $server->getName());
92  if ($server->getUsernameFilter() !== '') {
93  //#17731
94  $pattern = str_replace('*', '.*?', $server->getUsernameFilter());
95 
96  foreach (ilAuthUtils::REGEX_DELIMITERS as $delimiter) {
97  $this->logger->debug('Trying pattern to match username:' . $pattern . ' => ' . $a_username);
98  set_error_handler(static function (int $severity, string $message, string $file, int $line): never {
99  throw new ErrorException($message, $severity, $severity, $file, $line);
100  });
101 
102  try {
103  if (preg_match($delimiter . '^' . $pattern . '$' . $delimiter . 'i', $a_username) === 1) {
104  $this->logger->debug('Filter matches for ' . $a_username);
105  array_unshift($sorted, $auth_key);
106  continue 2;
107  }
108  break;
109  } catch (Exception $ex) {
110  $this->logger->warning('Error occurred in preg_match Ex.: ' . $ex->getMessage());
111  } finally {
112  restore_error_handler();
113  }
114  }
115 
116  $this->logger->debug('Filter matches not for ' . $a_username . ' <-> ' . $server->getUsernameFilter());
117  }
118  }
119  $sorted[] = $auth_key;
120  }
121 
122  return $sorted;
123  }
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
const array REGEX_DELIMITERS
static getServerIdByAuthMode(string $a_auth_mode)
Get auth id by auth mode.
$message
Definition: xapiexit.php:31
$server
Definition: shib_login.php:28
+ Here is the call graph for this function:

◆ getCountActiveAuthModes()

ilAuthModeDetermination::getCountActiveAuthModes ( )

Definition at line 125 of file class.ilAuthModeDetermination.php.

125  : int
126  {
127  return count($this->position);
128  }

◆ getKind()

ilAuthModeDetermination::getKind ( )
Returns
int<self::TYPE_MANUAL|self::TYPE_AUTOMATIC>

Definition at line 60 of file class.ilAuthModeDetermination.php.

References $kind.

Referenced by save().

60  : int
61  {
62  return $this->kind;
63  }
+ Here is the caller graph for this function:

◆ isManualSelection()

ilAuthModeDetermination::isManualSelection ( )

Definition at line 52 of file class.ilAuthModeDetermination.php.

52  : bool
53  {
54  return $this->kind === self::TYPE_MANUAL;
55  }

◆ read()

ilAuthModeDetermination::read ( )
private

Definition at line 152 of file class.ilAuthModeDetermination.php.

References $server, ilLDAPServer\_getActiveServerList(), ilAuthUtils\AUTH_APACHE, ilAuthUtils\AUTH_LDAP, ilAuthUtils\AUTH_LOCAL, ilAuthUtils\AUTH_SOAP, ilAuthUtils\getAuthPlugins(), ilLDAPServer\getInstanceByServerId(), ilLDAPServer\getServerIdByAuthMode(), ILIAS\Repository\int(), null, and ILIAS\Repository\settings().

Referenced by __construct().

152  : void
153  {
154  $this->kind = (int) $this->settings->get('kind', (string) self::TYPE_MANUAL);
155 
156  $soap_active = (bool) $this->commonSettings->get('soap_auth_active', '');
157 
158  $apache_settings = new ilSetting('apache_auth');
159  $apache_active = $apache_settings->get('apache_enable_auth');
160 
161  // Check if active
162  $i = 0;
163  while (true) {
164  $auth_mode = $this->settings->get((string) $i++, null);
165  if ($auth_mode === null) {
166  break;
167  }
168 
169  if ($auth_mode) {
170  switch ((int) $auth_mode) {
172  $this->position[] = (int) $auth_mode;
173  break;
174 
176  $auth_id = ilLDAPServer::getServerIdByAuthMode($auth_mode);
177  if ($auth_id === null) {
178  break;
179  }
180 
182  if ($server->isActive()) {
183  $this->position[] = $auth_mode;
184  }
185  break;
186 
188  if ($soap_active) {
189  $this->position[] = (int) $auth_mode;
190  }
191  break;
192 
194  if ($apache_active) {
195  $this->position[] = (int) $auth_mode;
196  }
197  break;
198 
199  default:
200  foreach (ilAuthUtils::getAuthPlugins() as $pl) {
201  if ($pl->isAuthActive((int) $auth_mode)) {
202  $this->position[] = (int) $auth_mode;
203  }
204  }
205  break;
206  }
207  }
208  }
209 
210  // Append missing active auth modes
211  if (!in_array(ilAuthUtils::AUTH_LOCAL, $this->position, true)) {
212  $this->position[] = ilAuthUtils::AUTH_LOCAL;
213  }
214  // begin-patch ldap_multiple
215  foreach (ilLDAPServer::_getActiveServerList() as $sid) {
217  if ($server->isActive() && !in_array(ilAuthUtils::AUTH_LDAP . '_' . $sid, $this->position, true)) {
218  $this->position[] = ilAuthUtils::AUTH_LDAP . '_' . $sid;
219  }
220  }
221  // end-patch ldap_multiple
222  if ($soap_active && !in_array(ilAuthUtils::AUTH_SOAP, $this->position, true)) {
223  $this->position[] = ilAuthUtils::AUTH_SOAP;
224  }
225  if ($apache_active && !in_array(ilAuthUtils::AUTH_APACHE, $this->position, true)) {
226  $this->position[] = ilAuthUtils::AUTH_APACHE;
227  }
228  // begin-patch auth_plugin
229  foreach (ilAuthUtils::getAuthPlugins() as $pl) {
230  foreach ($pl->getAuthIds() as $auth_id) {
231  if ($pl->isAuthActive($auth_id) && !in_array($auth_id, $this->position, true)) {
232  $this->position[] = $auth_id;
233  }
234  }
235  }
236  // end-patch auth_plugin
237  }
const int AUTH_SOAP
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
const int AUTH_APACHE
static _getActiveServerList()
Get active server list.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getServerIdByAuthMode(string $a_auth_mode)
Get auth id by auth mode.
static getAuthPlugins()
const int AUTH_LOCAL
const int AUTH_LDAP
$server
Definition: shib_login.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilAuthModeDetermination::save ( )

Definition at line 139 of file class.ilAuthModeDetermination.php.

References getKind(), and ILIAS\Repository\settings().

139  : void
140  {
141  $this->settings->deleteAll();
142 
143  $this->settings->set('kind', (string) $this->getKind());
144 
145  $counter = 0;
146  foreach ($this->position as $auth_mode) {
147  $this->settings->set((string) $counter++, (string) $auth_mode);
148  }
149  }
+ Here is the call graph for this function:

◆ setAuthModeSequence()

ilAuthModeDetermination::setAuthModeSequence ( array  $a_pos)
Parameters
list<numeric-string|int|string>$a_pos position => AUTH_MODE

Definition at line 134 of file class.ilAuthModeDetermination.php.

134  : void
135  {
136  $this->position = $a_pos;
137  }

◆ setKind()

ilAuthModeDetermination::setKind ( int  $a_kind)
Parameters
int<self::TYPE_MANUAL|self::TYPE_AUTOMATIC>$a_kind

Definition at line 68 of file class.ilAuthModeDetermination.php.

68  : void
69  {
70  if (!in_array($a_kind, [self::TYPE_MANUAL, self::TYPE_AUTOMATIC], true)) {
71  throw new InvalidArgumentException('Invalid kind given');
72  }
73 
74  $this->kind = $a_kind;
75  }

Field Documentation

◆ $commonSettings

ilSetting ilAuthModeDetermination::$commonSettings
private

Definition at line 30 of file class.ilAuthModeDetermination.php.

◆ $instance

ilAuthModeDetermination ilAuthModeDetermination::$instance = null
staticprivate

Definition at line 26 of file class.ilAuthModeDetermination.php.

◆ $kind

int ilAuthModeDetermination::$kind = self::TYPE_MANUAL
private

Definition at line 31 of file class.ilAuthModeDetermination.php.

Referenced by getKind().

◆ $logger

ilLogger ilAuthModeDetermination::$logger
private

Definition at line 28 of file class.ilAuthModeDetermination.php.

◆ $position

array ilAuthModeDetermination::$position = []
private

Definition at line 33 of file class.ilAuthModeDetermination.php.

Referenced by getAuthModeSequence().

◆ $settings

ilSetting ilAuthModeDetermination::$settings
private

Definition at line 29 of file class.ilAuthModeDetermination.php.

◆ TYPE_AUTOMATIC

const int ilAuthModeDetermination::TYPE_AUTOMATIC = 1

◆ TYPE_MANUAL

const int ilAuthModeDetermination::TYPE_MANUAL = 0

The documentation for this class was generated from the following file: