ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilAuthProviderApache Class Reference

Apache auth provider. More...

+ Inheritance diagram for ilAuthProviderApache:
+ Collaboration diagram for ilAuthProviderApache:

Public Member Functions

 __construct (ilAuthCredentials $credentials)
 
 doAuthentication (ilAuthStatus $status)
 
 migrateAccount (ilAuthStatus $status)
 Create new account. More...
 
 createNewAccount (ilAuthStatus $status)
 Create new ILIAS account for external_account. More...
 
 getExternalAccountName ()
 Get external account name. More...
 
 setExternalAccountName (string $name)
 
 getTriggerAuthMode ()
 Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 11 for apache auth. More...
 
 getUserAuthModeName ()
 Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth. More...
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
- Public Member Functions inherited from ilAuthProviderInterface
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 

Data Fields

const APACHE_AUTH_TYPE_DIRECT_MAPPING = 1
 
const APACHE_AUTH_TYPE_EXTENDED_MAPPING = 2
 
const APACHE_AUTH_TYPE_BY_FUNCTION = 3
 

Private Member Functions

 handleLDAPDataSource (ilAuthStatus $status)
 

Private Attributes

const ENV_APACHE_AUTH_INDICATOR_NAME = 'apache_auth_indicator_name'
 
const ERR_WRONG_LOGIN = 'err_wrong_login'
 
const APACHE_ENABLE_LDAP = 'apache_enable_ldap'
 
const APACHE_LDAP_SID = 'apache_ldap_sid'
 
ilSetting $settings
 
string $migration_account = ''
 
bool $force_new_account = false
 

Additional Inherited Members

- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, string $a_reason)
 Handle failed authentication. More...
 

Detailed Description

Apache auth provider.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 24 of file class.ilAuthProviderApache.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderApache::__construct ( ilAuthCredentials  $credentials)

Definition at line 41 of file class.ilAuthProviderApache.php.

References ILIAS\MetaData\Repository\Validation\Data\__construct(), and ILIAS\Repository\settings().

42  {
43  parent::__construct($credentials);
44  $this->settings = new ilSetting('apache_auth');
45  }
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ createNewAccount()

ilAuthProviderApache::createNewAccount ( ilAuthStatus  $status)

Create new ILIAS account for external_account.

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 116 of file class.ilAuthProviderApache.php.

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

116  : void
117  {
118  $this->force_new_account = true;
119  if ($this->settings->get(self::APACHE_ENABLE_LDAP, '0')) {
120  $this->handleLDAPDataSource($status);
121  }
122  }
handleLDAPDataSource(ilAuthStatus $status)
+ Here is the call graph for this function:

◆ doAuthentication()

ilAuthProviderApache::doAuthentication ( ilAuthStatus  $status)

Definition at line 47 of file class.ilAuthProviderApache.php.

References $_SERVER, ilObjUser\_checkExternalAuthAccount(), ilObjUser\_lookupId(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), ilAuthProvider\handleAuthenticationFail(), handleLDAPDataSource(), ilUtil\isLogin(), ilAuthStatus\setAuthenticatedUserId(), ilAuthStatus\setStatus(), ILIAS\Repository\settings(), and ilAuthStatus\STATUS_AUTHENTICATED.

47  : bool
48  {
49  if (!$this->settings->get('apache_enable_auth', '0')) {
50  $this->getLogger()->info('Apache auth disabled.');
51  $this->handleAuthenticationFail($status, 'apache_auth_err_disabled');
52  return false;
53  }
54 
55  if (
56  !$this->settings->get(self::ENV_APACHE_AUTH_INDICATOR_NAME, '') ||
57  !$this->settings->get('apache_auth_indicator_value', '')
58  ) {
59  $this->getLogger()->warning('Apache auth indicator match failure.');
60  $this->handleAuthenticationFail($status, 'apache_auth_err_indicator_match_failure');
61  return false;
62  }
63 
64  $validIndicatorValues = array_filter(array_map(
65  'trim',
66  str_getcsv($this->settings->get('apache_auth_indicator_value', ''))
67  ));
68  //TODO PHP8-REVIEW: $DIC->http()->request()->getServerParams()['apache_auth_indicator_name']
69  if (
70  !isset($_SERVER[$this->settings->get(self::ENV_APACHE_AUTH_INDICATOR_NAME, '')]) ||
71  !in_array($_SERVER[$this->settings->get(self::ENV_APACHE_AUTH_INDICATOR_NAME, '')], $validIndicatorValues, true)
72  ) {
73  $this->getLogger()->warning('Apache authentication failed (indicator name <-> value');
74  $this->handleAuthenticationFail($status, self::ERR_WRONG_LOGIN);
75  return false;
76  }
77 
78  if (!ilUtil::isLogin($this->getCredentials()->getUsername())) {
79  $this->getLogger()->warning('Invalid login name given: ' . $this->getCredentials()->getUsername());
80  $this->handleAuthenticationFail($status, 'apache_auth_err_invalid_login');
81  return false;
82  }
83 
84  if ($this->getCredentials()->getUsername() === '') {
85  $this->getLogger()->info('No username given');
86  $this->handleAuthenticationFail($status, self::ERR_WRONG_LOGIN);
87  return false;
88  }
89 
90  // Apache with ldap as data source
91  if ($this->settings->get(self::APACHE_ENABLE_LDAP, '0')) {
92  return $this->handleLDAPDataSource($status);
93  }
94 
95  $login = ilObjUser::_checkExternalAuthAccount('apache', $this->getCredentials()->getUsername());
96  $usr_id = ilObjUser::_lookupId($login);
97  if (!$usr_id) {
98  $this->getLogger()->info('Cannot find user id for external account: ' . $this->getCredentials()->getUsername());
99  $this->handleAuthenticationFail($status, self::ERR_WRONG_LOGIN);
100  return false;
101  }
102 
104  $status->setAuthenticatedUserId($usr_id);
105  return true;
106  }
handleLDAPDataSource(ilAuthStatus $status)
static _lookupId($a_user_str)
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
setStatus(int $a_status)
Set auth status.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
static isLogin(string $a_login)
getLogger()
Get logger.
setAuthenticatedUserId(int $a_id)
+ Here is the call graph for this function:

◆ getExternalAccountName()

ilAuthProviderApache::getExternalAccountName ( )

Get external account name.

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 124 of file class.ilAuthProviderApache.php.

References $migration_account.

124  : string
125  {
127  }

◆ getTriggerAuthMode()

ilAuthProviderApache::getTriggerAuthMode ( )

Get auth mode which triggered the account migration 2_1 for ldap account migration with server id 1 11 for apache auth.

See also
ilAuthUtils

Implements ilAuthProviderAccountMigrationInterface.

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

References ilAuthUtils\AUTH_APACHE.

134  : string
135  {
136  return (string) ilAuthUtils::AUTH_APACHE;
137  }

◆ getUserAuthModeName()

ilAuthProviderApache::getUserAuthModeName ( )

Get user auth mode name ldap_1 for ldap account migration with server id 1 apache for apache auth.

Implements ilAuthProviderAccountMigrationInterface.

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

References ILIAS\Repository\settings().

139  : string
140  {
141  if ($this->settings->get(self::APACHE_LDAP_SID, '0')) {
142  return 'ldap_' . $this->settings->get(self::APACHE_LDAP_SID, '');
143  }
144 
145  return 'apache';
146  }
+ Here is the call graph for this function:

◆ handleLDAPDataSource()

ilAuthProviderApache::handleLDAPDataSource ( ilAuthStatus  $status)
private

Definition at line 148 of file class.ilAuthProviderApache.php.

References Vendor\Package\$e, $server, ilObjUser\_lookupId(), ilAuthProvider\getCredentials(), ilLDAPServer\getInstanceByServerId(), ilAuthProvider\getLogger(), ilAuthProvider\handleAuthenticationFail(), ilAuthStatus\setAuthenticatedUserId(), ilLDAPUserSynchronisation\setExternalAccount(), setExternalAccountName(), ilAuthStatus\setStatus(), ILIAS\Repository\settings(), ilAuthStatus\STATUS_ACCOUNT_MIGRATION_REQUIRED, and ilAuthStatus\STATUS_AUTHENTICATED.

Referenced by createNewAccount(), doAuthentication(), and migrateAccount().

148  : bool
149  {
151  (int) $this->settings->get(self::APACHE_LDAP_SID, '0')
152  );
153 
154  $this->getLogger()->debug('Using ldap data source with server configuration: ' . $server->getName());
155 
156  $sync = new ilLDAPUserSynchronisation('ldap_' . $server->getServerId(), $server->getServerId());
157  $sync->setExternalAccount($this->getCredentials()->getUsername());
158  $sync->setUserData([]);
159  $sync->forceCreation($this->force_new_account);
160  $sync->forceReadLdapData(true);
161 
162  try {
163  $internal_account = $sync->sync();
164  $this->getLogger()->debug('Internal account: ' . $internal_account);
165  } catch (UnexpectedValueException $e) {
166  $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
167  $this->handleAuthenticationFail($status, self::ERR_WRONG_LOGIN);
168  return false;
170  $this->handleAuthenticationFail($status, 'err_auth_ldap_failed');
171  return false;
173  $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
174  $this->handleAuthenticationFail($status, 'err_auth_ldap_no_ilias_user');
175  return false;
177  $this->setExternalAccountName($this->getCredentials()->getUsername());
178  $this->getLogger()->info('Authentication failed: account migration required for external account: ' . $this->getCredentials()->getUsername());
180  return false;
181  }
182 
184  $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
185  return true;
186  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupId($a_user_str)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
setExternalAccount(string $a_ext)
Set external account (unique for each auth mode)
setStatus(int $a_status)
Set auth status.
getLogger()
Get logger.
$server
setAuthenticatedUserId(int $a_id)
const STATUS_ACCOUNT_MIGRATION_REQUIRED
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateAccount()

ilAuthProviderApache::migrateAccount ( ilAuthStatus  $status)

Create new account.

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 108 of file class.ilAuthProviderApache.php.

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

108  : void
109  {
110  $this->force_new_account = true;
111  if ($this->settings->get(self::APACHE_ENABLE_LDAP, '0')) {
112  $this->handleLDAPDataSource($status);
113  }
114  }
handleLDAPDataSource(ilAuthStatus $status)
+ Here is the call graph for this function:

◆ setExternalAccountName()

ilAuthProviderApache::setExternalAccountName ( string  $name)

Definition at line 129 of file class.ilAuthProviderApache.php.

Referenced by handleLDAPDataSource().

129  : void
130  {
131  $this->migration_account = $name;
132  }
+ Here is the caller graph for this function:

Field Documentation

◆ $force_new_account

bool ilAuthProviderApache::$force_new_account = false
private

Definition at line 39 of file class.ilAuthProviderApache.php.

◆ $migration_account

string ilAuthProviderApache::$migration_account = ''
private

Definition at line 38 of file class.ilAuthProviderApache.php.

Referenced by getExternalAccountName().

◆ $settings

ilSetting ilAuthProviderApache::$settings
private

Definition at line 37 of file class.ilAuthProviderApache.php.

◆ APACHE_AUTH_TYPE_BY_FUNCTION

const ilAuthProviderApache::APACHE_AUTH_TYPE_BY_FUNCTION = 3

◆ APACHE_AUTH_TYPE_DIRECT_MAPPING

const ilAuthProviderApache::APACHE_AUTH_TYPE_DIRECT_MAPPING = 1

◆ APACHE_AUTH_TYPE_EXTENDED_MAPPING

const ilAuthProviderApache::APACHE_AUTH_TYPE_EXTENDED_MAPPING = 2

Definition at line 27 of file class.ilAuthProviderApache.php.

◆ APACHE_ENABLE_LDAP

const ilAuthProviderApache::APACHE_ENABLE_LDAP = 'apache_enable_ldap'
private

Definition at line 34 of file class.ilAuthProviderApache.php.

◆ APACHE_LDAP_SID

const ilAuthProviderApache::APACHE_LDAP_SID = 'apache_ldap_sid'
private

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

◆ ENV_APACHE_AUTH_INDICATOR_NAME

const ilAuthProviderApache::ENV_APACHE_AUTH_INDICATOR_NAME = 'apache_auth_indicator_name'
private

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

◆ ERR_WRONG_LOGIN

const ilAuthProviderApache::ERR_WRONG_LOGIN = 'err_wrong_login'
private

Definition at line 32 of file class.ilAuthProviderApache.php.


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