ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAuthProviderECS Class Reference

Auth prvider for ecs auth. More...

+ Inheritance diagram for ilAuthProviderECS:
+ Collaboration diagram for ilAuthProviderECS:

Public Member Functions

 __construct (\ilAuthCredentials $credentials)
 Constructor. More...
 
 getAbreviation ()
 get abbreviation More...
 
 getMID ()
 get mid More...
 
 setMID ($a_mid)
 
 setCurrentServer (ilECSSetting $server=null)
 Set current server. More...
 
 getCurrentServer ()
 Get current server. More...
 
 getServerSettings ()
 Get server settings. More...
 
 doAuthentication (\ilAuthStatus $status)
 Tra ecs authentication. More...
 
 handleLogin ()
 Called from base class after successful login. More...
 
 validateHash ()
 Validate ECS hash. More...
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 

Protected Member Functions

 createUser (ilECSUser $user)
 create new user More...
 
 updateUser (ilECSUser $user, $a_local_user_id)
 update existing user More...
 
 resetMailOptions ($a_usr_id)
 Reset mail options to "local only". More...
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, $a_reason)
 Handle failed authentication. More...
 

Protected Attributes

 $mid = null
 
 $abreviation = null
 
 $currentServer = null
 
 $servers = null
 

Private Member Functions

 initECSServices ()
 Init ECS Services @access private. More...
 

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

Auth prvider for ecs auth.

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

Definition at line 14 of file class.ilAuthProviderECS.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderECS::__construct ( \ilAuthCredentials  $credentials)

Constructor.

Parameters
\ilAuthCredentials$credentials

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

28 {
29 parent::__construct($credentials);
30
31 $this->initECSServices();
32 }
initECSServices()
Init ECS Services @access private.

References ilAuthProvider\$credentials, and initECSServices().

+ Here is the call graph for this function:

Member Function Documentation

◆ createUser()

ilAuthProviderECS::createUser ( ilECSUser  $user)
protected

create new user

@access protected

Definition at line 258 of file class.ilAuthProviderECS.php.

259 {
260 global $DIC;
261
262 $ilClientIniFile = $DIC['ilClientIniFile'];
263 $ilSetting = $DIC['ilSetting'];
264 $rbacadmin = $DIC['rbacadmin'];
265 $ilLog = $DIC['ilLog'];
266
267 $userObj = new ilObjUser();
268 $userObj->setOwner(SYSTEM_USER_ID);
269
270 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
271 $local_user = ilAuthUtils::_generateLogin($this->getAbreviation() . '_' . $user->getLogin());
272
273 $newUser["login"] = $local_user;
274 $newUser["firstname"] = $user->getFirstname();
275 $newUser["lastname"] = $user->getLastname();
276 $newUser['email'] = $user->getEmail();
277 $newUser['institution'] = $user->getInstitution();
278
279 // set "plain md5" password (= no valid password)
280 $newUser["passwd"] = "";
281 $newUser["passwd_type"] = IL_PASSWD_CRYPTED;
282
283 $newUser["auth_mode"] = "ecs";
284 $newUser["profile_incomplete"] = 0;
285
286 // system data
287 $userObj->assignData($newUser);
288 $userObj->setTitle($userObj->getFullname());
289 $userObj->setDescription($userObj->getEmail());
290
291 // set user language to system language
292 $userObj->setLanguage($ilSetting->get("language"));
293
294 // Time limit
295 $userObj->setTimeLimitOwner(7);
296 $userObj->setTimeLimitUnlimited(0);
297 $userObj->setTimeLimitFrom(time() - 5);
298 $userObj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session", "expire"));
299
300 #$now = new ilDateTime(time(), IL_CAL_UNIX);
301 #$userObj->setAgreeDate($now->get(IL_CAL_DATETIME));
302
303 // Create user in DB
304 $userObj->setOwner(6);
305 $userObj->create();
306 $userObj->setActive(1);
307 $userObj->updateOwner();
308 $userObj->saveAsNew();
309 $userObj->writePrefs();
310
311 if ($global_role = $this->getCurrentServer()->getGlobalRole()) {
312 $rbacadmin->assignUser($this->getCurrentServer()->getGlobalRole(), $userObj->getId(), true);
313 }
314 ilObject::_writeImportId($userObj->getId(), $user->getImportId());
315
316 $this->getLogger()->info('Created new remote user with usr_id: ' . $user->getImportId());
317
318 // Send Mail
319 #$this->sendNotification($userObj);
320 $this->resetMailOptions($userObj->getId());
321
322 return $userObj->getLogin();
323 }
const IL_PASSWD_CRYPTED
getAbreviation()
get abbreviation
getCurrentServer()
Get current server.
resetMailOptions($a_usr_id)
Reset mail options to "local only".
getLogger()
Get logger.
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
getLogin()
get login
getImportId()
get Email
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
$user
Definition: migrateto20.php:57
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7

References $DIC, $ilLog, $ilSetting, $user, ilAuthUtils\_generateLogin(), ilObject\_writeImportId(), getAbreviation(), getCurrentServer(), ilECSUser\getImportId(), ilAuthProvider\getLogger(), ilECSUser\getLogin(), IL_PASSWD_CRYPTED, and resetMailOptions().

Referenced by handleLogin().

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

◆ doAuthentication()

ilAuthProviderECS::doAuthentication ( \ilAuthStatus  $status)

Tra ecs authentication.

Parameters
\ilAuthStatus$status
Returns
boolean

Implements ilAuthProviderInterface.

Definition at line 94 of file class.ilAuthProviderECS.php.

95 {
96 $this->getLogger()->debug('Starting ECS authentication');
97 if (!$this->getServerSettings()->activeServerExists()) {
98 $this->getLogger()->warning('No active ecs server found. Aborting');
99 $this->handleAuthenticationFail($status, 'err_wrong_login');
100 return false;
101 }
102
103 // Iterate through all active ecs instances
104 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
105 foreach ($this->getServerSettings()->getServers() as $server) {
106 $this->setCurrentServer($server);
107 if ($this->validateHash()) {
108 // handle successful authentication
109 $new_usr_id = $this->handleLogin();
110 $this->getLogger()->info('ECS authentication successful.');
112 $status->setAuthenticatedUserId($new_usr_id);
113 return true;
114 }
115 }
116
117 $this->getLogger()->warning('Could not validate ecs hash for any active server.');
118 $this->handleAuthenticationFail($status, 'err_wrong_login');
119 return false;
120 }
getServerSettings()
Get server settings.
handleLogin()
Called from base class after successful login.
validateHash()
Validate ECS hash.
setCurrentServer(ilECSSetting $server=null)
Set current server.
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
$server
Definition: sabredav.php:48

References $server, ilAuthProvider\$status, ilAuthProvider\getLogger(), getServerSettings(), ilAuthProvider\handleAuthenticationFail(), handleLogin(), setCurrentServer(), ilAuthStatus\setStatus(), ilAuthStatus\STATUS_AUTHENTICATED, and validateHash().

+ Here is the call graph for this function:

◆ getAbreviation()

ilAuthProviderECS::getAbreviation ( )

get abbreviation

@access public

Parameters

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

References $abreviation.

Referenced by createUser().

+ Here is the caller graph for this function:

◆ getCurrentServer()

ilAuthProviderECS::getCurrentServer ( )

Get current server.

Returns
ilECSSetting

Definition at line 74 of file class.ilAuthProviderECS.php.

References $currentServer.

Referenced by createUser(), handleLogin(), updateUser(), and validateHash().

+ Here is the caller graph for this function:

◆ getMID()

ilAuthProviderECS::getMID ( )

get mid

@access public

Definition at line 51 of file class.ilAuthProviderECS.php.

References $mid.

Referenced by handleLogin().

+ Here is the caller graph for this function:

◆ getServerSettings()

ilAuthProviderECS::getServerSettings ( )

Get server settings.

Returns
ilECSServerSettings

Definition at line 83 of file class.ilAuthProviderECS.php.

References $servers.

Referenced by doAuthentication().

+ Here is the caller graph for this function:

◆ handleLogin()

ilAuthProviderECS::handleLogin ( )

Called from base class after successful login.

Parameters
stringusername

Definition at line 128 of file class.ilAuthProviderECS.php.

129 {
130 include_once('./Services/WebServices/ECS/classes/class.ilECSUser.php');
131
132 $user = new ilECSUser($_GET);
133
134 if (!$usr_id = ilObject::_lookupObjIdByImportId($user->getImportId())) {
135 $username = $this->createUser($user);
136 } else {
137 $username = $this->updateUser($user, $usr_id);
138 }
139
140 // set user imported
141 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
142 $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
143 $import->save();
144
145 // Store remote user data
146 include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
147 $remote = new ilECSRemoteUser();
148 $remote->setServerId($this->getCurrentServer()->getServerId());
149 $remote->setMid($this->getMID());
150 $remote->setRemoteUserId($user->getImportId());
151 $remote->setUserId(ilObjUser::_lookupId($username));
152
153 $this->getLogger()->info('Current user is: ' . $username);
154
155 if (!$remote->exists()) {
156 $remote->create();
157 }
158 return ilObjUser::_lookupId($username);
159 }
$_GET["client_id"]
createUser(ilECSUser $user)
create new user
updateUser(ilECSUser $user, $a_local_user_id)
update existing user
Storage of ECS imported objects.
Storage of ecs remote user.
Stores relevant user data.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjIdByImportId($a_import_id)

References $_GET, $user, ilObjUser\_lookupId(), ilObject\_lookupObjIdByImportId(), createUser(), getCurrentServer(), ilAuthProvider\getLogger(), getMID(), and updateUser().

Referenced by doAuthentication().

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

◆ initECSServices()

ilAuthProviderECS::initECSServices ( )
private

Init ECS Services @access private.

Parameters

Definition at line 247 of file class.ilAuthProviderECS.php.

248 {
249 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
250 $this->servers = ilECSServerSettings::getInstance();
251 }
static getInstance()
Get singleton instance.

References ilECSServerSettings\getInstance().

Referenced by __construct().

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

◆ resetMailOptions()

ilAuthProviderECS::resetMailOptions (   $a_usr_id)
protected

Reset mail options to "local only".

Definition at line 372 of file class.ilAuthProviderECS.php.

373 {
374 include_once './Services/Mail/classes/class.ilMailOptions.php';
375 $options = new ilMailOptions($a_usr_id);
376 $options->setIncomingType(ilMailOptions::INCOMING_LOCAL);
377 $options->updateOptions();
378 }
Class ilMailOptions this class handles user mails.

References PHPMailer\PHPMailer\$options, and ilMailOptions\INCOMING_LOCAL.

Referenced by createUser(), and updateUser().

+ Here is the caller graph for this function:

◆ setCurrentServer()

ilAuthProviderECS::setCurrentServer ( ilECSSetting  $server = null)

Set current server.

Parameters
ilECSSetting$server

Definition at line 65 of file class.ilAuthProviderECS.php.

66 {
67 $this->currentServer = $server;
68 }

References $server.

Referenced by doAuthentication().

+ Here is the caller graph for this function:

◆ setMID()

ilAuthProviderECS::setMID (   $a_mid)

Definition at line 56 of file class.ilAuthProviderECS.php.

57 {
58 $this->mid = $a_mid;
59 }

Referenced by validateHash().

+ Here is the caller graph for this function:

◆ updateUser()

ilAuthProviderECS::updateUser ( ilECSUser  $user,
  $a_local_user_id 
)
protected

update existing user

@access protected

Definition at line 330 of file class.ilAuthProviderECS.php.

331 {
332 global $DIC;
333
334 $ilClientIniFile = $DIC['ilClientIniFile'];
335 $ilLog = $DIC['ilLog'];
336 $rbacadmin = $DIC['rbacadmin'];
337
338 $user_obj = new ilObjUser($a_local_user_id);
339 $user_obj->setFirstname($user->getFirstname());
340 $user_obj->setLastname($user->getLastname());
341 $user_obj->setEmail($user->getEmail());
342 $user_obj->setInstitution($user->getInstitution());
343 $user_obj->setActive(true);
344
345 $until = $user_obj->getTimeLimitUntil();
346
347 if ($until < (time() + $ilClientIniFile->readVariable('session', 'expire'))) {
348 $user_obj->setTimeLimitFrom(time() - 60);
349 $user_obj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session", "expire"));
350 }
351 $user_obj->update();
352 $user_obj->refreshLogin();
353
354 if ($global_role = $this->getCurrentServer()->getGlobalRole()) {
355 $rbacadmin->assignUser(
356 $this->getCurrentServer()->getGlobalRole(),
357 $user_obj->getId(),
358 true
359 );
360 }
361
362 $this->resetMailOptions($a_local_user_id);
363
364 $this->getLogger()->debug('Finished update of remote user with usr_id: ' . $user->getImportId());
365 return $user_obj->getLogin();
366 }

References $DIC, $ilLog, $user, getCurrentServer(), ilECSUser\getImportId(), ilAuthProvider\getLogger(), and resetMailOptions().

Referenced by handleLogin().

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

◆ validateHash()

ilAuthProviderECS::validateHash ( )

Validate ECS hash.

@access public

Parameters
stringusername
stringpass

Definition at line 170 of file class.ilAuthProviderECS.php.

171 {
172 global $DIC;
173
174 $ilLog = $DIC['ilLog'];
175
176 // fetch hash
177 if (isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash'])) {
178 $hash = $_GET['ecs_hash'];
179 }
180 if (isset($_GET['ecs_hash_url'])) {
181 $hashurl = urldecode($_GET['ecs_hash_url']);
182 $hash = basename(parse_url($hashurl, PHP_URL_PATH));
183 //$hash = urldecode($_GET['ecs_hash_url']);
184 }
185
186 $this->getLogger()->info('Using ecs hash: ' . $hash);
187 // Check if hash is valid ...
188 try {
189 include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
190 $connector = new ilECSConnector($this->getCurrentServer());
191 $res = $connector->getAuth($hash);
192 $auths = $res->getResult();
193
194 $this->getLogger()->dump($auths, ilLogLevel::DEBUG);
195
196 if ($auths->pid) {
197 try {
198 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
200 foreach ($reader->getParticipantsByPid($auths->pid) as $participant) {
201 if ($participant->getOrganisation() instanceof \ilECSOrganisation) {
202 $this->abreviation = $participant->getOrganisation()->getAbbreviation();
203 break;
204 }
205 }
206 if (!$this->abreviation) {
207 $this->abreviation = $auths->abbr;
208 }
209 } catch (Exception $e) {
210 $this->getLogger()->warning('Authentication failed with message: ' . $e->getMessage());
211 return false;
212 }
213 } else {
214 $this->abreviation = $auths->abbr;
215 }
216
217 $this->getLogger()->debug('Got abbreviation: ' . $this->abreviation);
218 } catch (ilECSConnectorException $e) {
219 $this->getLogger()->warning('Authentication failed with message: ' . $e->getMessage());
220 return false;
221 }
222
223 // read current mid
224 try {
225 include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
226 $connector = new ilECSConnector($this->getCurrentServer());
227 $details = $connector->getAuth($hash, true);
228
229 $this->getLogger()->dump($details, ilLogLevel::DEBUG);
230 $this->getLogger()->debug('Token create for mid: ' . $details->getFirstSender());
231
232 $this->setMID($details->getFirstSender());
233 } catch (ilECSConnectorException $e) {
234 $this->getLogger()->warning('Receiving mid failed with message: ' . $e->getMessage());
235 return false;
236 }
237 return true;
238 }
static getInstanceByServerId($a_server_id)
Get instance by server id.
foreach($_POST as $key=> $value) $res

References $_GET, $DIC, $ilLog, $reader, $res, ilLogLevel\DEBUG, getCurrentServer(), ilECSCommunityReader\getInstanceByServerId(), ilAuthProvider\getLogger(), and setMID().

Referenced by doAuthentication().

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

Field Documentation

◆ $abreviation

ilAuthProviderECS::$abreviation = null
protected

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

Referenced by getAbreviation().

◆ $currentServer

ilAuthProviderECS::$currentServer = null
protected

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

Referenced by getCurrentServer().

◆ $mid

ilAuthProviderECS::$mid = null
protected

Definition at line 16 of file class.ilAuthProviderECS.php.

Referenced by getMID().

◆ $servers

ilAuthProviderECS::$servers = null
protected

Definition at line 20 of file class.ilAuthProviderECS.php.

Referenced by getServerSettings().


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