ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilAuthProviderLDAP Class Reference

Description of class class. More...

+ Inheritance diagram for ilAuthProviderLDAP:
+ Collaboration diagram for ilAuthProviderLDAP:

Public Member Functions

 __construct (\ilAuthCredentials $credentials, $a_server_id=0)
 Constructor. More...
 
 getServer ()
 Get server. More...
 
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 
 createNewAccount (ilAuthStatus $status)
 Create new ILIAS account for external_account.
Parameters
ilAuthStatus
More...
 
 migrateAccount (ilAuthStatus $status)
 Create new account.
Parameters
ilAuthStatus
More...
 
 getTriggerAuthMode ()
 Get trigger auth mode. More...
 
 getUserAuthModeName ()
 Get user auth mode name. More...
 
 getExternalAccountName ()
 Get external account name. More...
 
 setExternalAccountName ($a_name)
 Set external account name. More...
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 
 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...
 
 getExternalAccountName ()
 Get external account name. More...
 
 migrateAccount (ilAuthStatus $status)
 Create new account. More...
 
 createNewAccount (ilAuthStatus $status)
 Create new ILIAS account for external_account. More...
 

Protected Member Functions

 updateAccount (ilAuthStatus $status, array $user)
 Update Account. More...
 
 initServer ($a_server_id)
 Init Server. More...
 
 changeKeyCase ($a_string)
 Change case similar to array_change_key_case, to avoid further encoding problems. More...
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, $a_reason)
 Handle failed authentication. More...
 

Private Attributes

 $server = null
 
 $migration_account = ''
 
 $force_new_account = false
 

Additional Inherited Members

- Data Fields inherited from ilAuthProvider
const STATUS_UNDEFINED = 0
 
const STATUS_AUTHENTICATION_SUCCESS = 1
 
const STATUS_AUTHENTICATION_FAILED = 2
 
const STATUS_MIGRATION = 3
 

Detailed Description

Description of class class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 15 of file class.ilAuthProviderLDAP.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderLDAP::__construct ( \ilAuthCredentials  $credentials,
  $a_server_id = 0 
)

Constructor.

Parameters
\ilAuthCredentials$credentials

Definition at line 25 of file class.ilAuthProviderLDAP.php.

26 {
28 $this->initServer($a_server_id);
29 }
initServer($a_server_id)
Init Server.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ilAuthProvider\$credentials, ILIAS\GlobalScreen\Provider\__construct(), and initServer().

+ Here is the call graph for this function:

Member Function Documentation

◆ changeKeyCase()

ilAuthProviderLDAP::changeKeyCase (   $a_string)
protected

Change case similar to array_change_key_case, to avoid further encoding problems.

Parameters
string$a_string
Returns
string

Definition at line 260 of file class.ilAuthProviderLDAP.php.

261 {
262 $as_array = array_change_key_case(array($a_string => $a_string));
263 foreach ($as_array as $key => $string) {
264 return $key;
265 }
266 }

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

+ Here is the caller graph for this function:

◆ createNewAccount()

ilAuthProviderLDAP::createNewAccount ( ilAuthStatus  $status)

Create new ILIAS account for external_account.

Parameters
ilAuthStatus

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 161 of file class.ilAuthProviderLDAP.php.

162 {
163 $this->force_new_account = true;
164
165 try {
166 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
167 $query = new ilLDAPQuery($this->getServer());
169 } catch (ilLDAPQueryException $e) {
170 $this->getLogger()->error('Cannot bind to LDAP server... ' . $e->getMessage());
171 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
172 return false;
173 }
174 try {
175 // fetch user
176 $users = $query->fetchUser(
177 $this->getCredentials()->getUsername()
178 );
179 if (!$users) {
180 $this->handleAuthenticationFail($status, 'err_wrong_login');
181 return false;
182 }
183 if (!array_key_exists($this->changeKeyCase($this->getCredentials()->getUsername()), $users)) {
184 $this->handleAuthenticationFail($status, 'err_wrong_login');
185 return false;
186 }
187 } catch (ilLDAPQueryException $e) {
188 $this->getLogger()->error('Cannot fetch LDAP user data... ' . $e->getMessage());
189 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
190 return false;
191 }
192
193 // authentication success update profile
194 $this->updateAccount($status, $users[$this->changeKeyCase($this->getCredentials()->getUsername())]);
195 }
const IL_LDAP_BIND_DEFAULT
updateAccount(ilAuthStatus $status, array $user)
Update Account.
changeKeyCase($a_string)
Change case similar to array_change_key_case, to avoid further encoding problems.
getLogger()
Get logger.
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
$query

References Vendor\Package\$e, $query, changeKeyCase(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), getServer(), ilAuthProvider\handleAuthenticationFail(), IL_LDAP_BIND_DEFAULT, and updateAccount().

+ Here is the call graph for this function:

◆ doAuthentication()

ilAuthProviderLDAP::doAuthentication ( \ilAuthStatus  $status)

Do authentication.

Parameters
\ilAuthStatus$status

Implements ilAuthProviderInterface.

Definition at line 45 of file class.ilAuthProviderLDAP.php.

46 {
47 try {
48 // bind
49 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
50 $query = new ilLDAPQuery($this->getServer());
52 } catch (ilLDAPQueryException $e) {
53 $this->getLogger()->error('Cannot bind to LDAP server... ' . $e->getMessage());
54 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
55 return false;
56 }
57 try {
58 // Read user data, which does ensure a sucessful authentication.
59 $users = $query->fetchUser(
60 $this->getCredentials()->getUsername()
61 );
62
63 if (!$users) {
64 $this->handleAuthenticationFail($status, 'err_wrong_login');
65 return false;
66 }
67 if (!trim($this->getCredentials()->getPassword())) {
68 $this->handleAuthenticationFail($status, 'err_wrong_login');
69 return false;
70 }
71 if (!array_key_exists($this->changeKeyCase($this->getCredentials()->getUsername()), $users)) {
72 $this->getLogger()->warning('Cannot find user: ' . $this->changeKeyCase($this->getCredentials()->getUsername()));
73 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
74 return false;
75 }
76
77 // check group membership
78 if (!$query->checkGroupMembership(
79 $this->getCredentials()->getUsername(),
80 $users[$this->changeKeyCase($this->getCredentials()->getUsername())]
81 )) {
82 $this->handleAuthenticationFail($status, 'err_wrong_login');
83 return false;
84 }
85 } catch (ilLDAPQueryException $e) {
86 $this->getLogger()->error('Cannot fetch LDAP user data... ' . $e->getMessage());
87 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
88 return false;
89 }
90 try {
91 // now bind with login credentials
92 $query->bind(IL_LDAP_BIND_AUTH, $users[$this->changeKeyCase($this->getCredentials()->getUsername())]['dn'], $this->getCredentials()->getPassword());
93 } catch (ilLDAPQueryException $e) {
94 $this->handleAuthenticationFail($status, 'err_wrong_login');
95 return false;
96 }
97
98 // authentication success update profile
99 return $this->updateAccount($status, $users[$this->changeKeyCase($this->getCredentials()->getUsername())]);
100 }
const IL_LDAP_BIND_AUTH

References Vendor\Package\$e, $query, changeKeyCase(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), getServer(), ilAuthProvider\handleAuthenticationFail(), IL_LDAP_BIND_AUTH, IL_LDAP_BIND_DEFAULT, and updateAccount().

+ Here is the call graph for this function:

◆ getExternalAccountName()

ilAuthProviderLDAP::getExternalAccountName ( )

Get external account name.

Returns
string

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 241 of file class.ilAuthProviderLDAP.php.

References $migration_account.

◆ getServer()

ilAuthProviderLDAP::getServer ( )

Get server.

Returns
\ilLDAPServer

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

References $server.

Referenced by createNewAccount(), doAuthentication(), getTriggerAuthMode(), getUserAuthModeName(), migrateAccount(), and updateAccount().

+ Here is the caller graph for this function:

◆ getTriggerAuthMode()

ilAuthProviderLDAP::getTriggerAuthMode ( )

Get trigger auth mode.

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 224 of file class.ilAuthProviderLDAP.php.

225 {
226 return AUTH_LDAP . '_' . $this->getServer()->getServerId();
227 }
const AUTH_LDAP

References AUTH_LDAP, and getServer().

+ Here is the call graph for this function:

◆ getUserAuthModeName()

ilAuthProviderLDAP::getUserAuthModeName ( )

Get user auth mode name.

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 232 of file class.ilAuthProviderLDAP.php.

233 {
234 return 'ldap_' . $this->getServer()->getServerId();
235 }

References getServer().

+ Here is the call graph for this function:

◆ initServer()

ilAuthProviderLDAP::initServer (   $a_server_id)
protected

Init Server.

Definition at line 150 of file class.ilAuthProviderLDAP.php.

151 {
152 include_once './Services/LDAP/classes/class.ilLDAPServer.php';
153 $this->server = new ilLDAPServer($a_server_id);
154 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ migrateAccount()

ilAuthProviderLDAP::migrateAccount ( ilAuthStatus  $status)

Create new account.

Parameters
ilAuthStatus

Implements ilAuthProviderAccountMigrationInterface.

Definition at line 202 of file class.ilAuthProviderLDAP.php.

203 {
204 $this->force_new_account = true;
205
206 try {
207 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
208 $query = new ilLDAPQuery($this->getServer());
210 } catch (ilLDAPQueryException $e) {
211 $this->getLogger()->error('Cannot bind to LDAP server... ' . $e->getMessage());
212 $this->handleAuthenticationFail($status, 'auth_err_ldap_exception');
213 return false;
214 }
215
216 $users = $query->fetchUser($this->getCredentials()->getUsername());
217 $this->updateAccount($status, $users[$this->changeKeyCase($this->getCredentials()->getUsername())]);
218 return true;
219 }

References Vendor\Package\$e, $query, changeKeyCase(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), getServer(), ilAuthProvider\handleAuthenticationFail(), IL_LDAP_BIND_DEFAULT, and updateAccount().

+ Here is the call graph for this function:

◆ setExternalAccountName()

ilAuthProviderLDAP::setExternalAccountName (   $a_name)

Set external account name.

Parameters
string$a_name

Definition at line 250 of file class.ilAuthProviderLDAP.php.

251 {
252 $this->migration_account = $a_name;
253 }

Referenced by updateAccount().

+ Here is the caller graph for this function:

◆ updateAccount()

ilAuthProviderLDAP::updateAccount ( ilAuthStatus  $status,
array  $user 
)
protected

Update Account.

Parameters
array$user
Returns
bool

Definition at line 107 of file class.ilAuthProviderLDAP.php.

108 {
109 $user = array_change_key_case($user, CASE_LOWER);
110 $this->getLogger()->dump($user, ilLogLevel::DEBUG);
111
112 include_once './Services/LDAP/classes/class.ilLDAPUserSynchronisation.php';
113 $sync = new ilLDAPUserSynchronisation('ldap_' . $this->getServer()->getServerId(), $this->getServer()->getServerId());
114 $sync->setExternalAccount($this->getCredentials()->getUsername());
115 $sync->setUserData($user);
116 $sync->forceCreation($this->force_new_account);
117
118 try {
119 $internal_account = $sync->sync();
120 $this->getLogger()->debug('Internal account: ' . $internal_account);
121 } catch (UnexpectedValueException $e) {
122 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
123 $this->handleAuthenticationFail($status, 'err_wrong_login');
124 return false;
126 $this->handleAuthenticationFail($status, 'err_auth_ldap_failed');
127 return false;
129 // No syncronisation allowed => create Error
130 $this->getLogger()->info('Login failed with message: ' . $e->getMessage());
131 $this->handleAuthenticationFail($status, 'err_auth_ldap_no_ilias_user');
132 return false;
134 // Account migration required
135 $this->setExternalAccountName($this->getCredentials()->getUsername());
136 $this->getLogger()->info('Authentication failed: account migration required for external account: ' . $this->getCredentials()->getUsername());
138 return false;
139 }
141 $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_account));
142 return true;
143 }
setExternalAccountName($a_name)
Set external account name.
const STATUS_ACCOUNT_MIGRATION_REQUIRED
Description of ilLDAPAccountMigrationRequiredException.
Thrown in case of failed synchronisation settings.
Synchronization of user accounts used in auth container ldap, radius , cas,...
static _lookupId($a_user_str)
Lookup id by login.

References Vendor\Package\$e, ilAuthProvider\$status, ilObjUser\_lookupId(), ilLogLevel\DEBUG, ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), getServer(), ilAuthProvider\handleAuthenticationFail(), setExternalAccountName(), ilAuthStatus\STATUS_ACCOUNT_MIGRATION_REQUIRED, and ilAuthStatus\STATUS_AUTHENTICATED.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $force_new_account

ilAuthProviderLDAP::$force_new_account = false
private

Definition at line 19 of file class.ilAuthProviderLDAP.php.

◆ $migration_account

ilAuthProviderLDAP::$migration_account = ''
private

Definition at line 18 of file class.ilAuthProviderLDAP.php.

Referenced by getExternalAccountName().

◆ $server

ilAuthProviderLDAP::$server = null
private

Definition at line 17 of file class.ilAuthProviderLDAP.php.

Referenced by getServer().


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