ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilLDAPAttributeToUser Class Reference

Update/create ILIAS user account by given LDAP attributes according to user attribute mapping settings. More...

+ Collaboration diagram for ilLDAPAttributeToUser:

Public Member Functions

 __construct (ilLDAPServer $a_server)
 Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes. More...
 
 getServer ()
 Get server settings. More...
 
 setUserData ($a_data)
 Set user data received from pear auth or by ldap_search. More...
 
 setNewUserAuthMode ($a_authmode)
 Set auth mode for new users. More...
 
 getNewUserAuthMode ()
 Get auth mode for new users. More...
 
 addMode ($a_mode)
 Add import mode. More...
 
 isModeActive ($a_mode)
 Check if mode is active. More...
 
 refresh ()
 Create/Update non existing users. More...
 

Data Fields

const MODE_INITIALIZE_ROLES = 1
 

Protected Member Functions

 parseRoleAssignmentsForUpdate ($a_usr_id, $a_external_account, $user)
 Parse role assignments for update of user account. More...
 
 parseRoleAssignmentsForCreation ($a_external_account, $a_user)
 Parse role assignments for update of user account. More...
 

Private Member Functions

 usersToXML ()
 Create xml string of user according to mapping rules. More...
 
 convertInput ($a_value)
 A value can be an array or a string This function converts arrays to strings. More...
 
 doMapping ($user, $rule)
 doMapping More...
 
 initLDAPAttributeMapping ()
 
 initUserDefinedFields ()
 

Private Attributes

 $modes = []
 
 $server_settings = null
 
 $role_assignment = null
 
 $db = null
 
 $user_data = array()
 
 $setting = null
 
 $mapping = null
 
 $new_user_auth_mode = 'ldap'
 

Detailed Description

Update/create ILIAS user account by given LDAP attributes according to user attribute mapping settings.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilLDAPAttributeToUser::__construct ( ilLDAPServer  $a_server)

Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.

Parameters
objectil

Definition at line 57 of file class.ilLDAPAttributeToUser.php.

58 {
60
61 // Initialise language object
62 if (!is_object($lng)) {
63 include_once './Services/Language/classes/class.ilLanguage.php';
64 $lng = new ilLanguage('en');
65 }
66
67 $this->log = $ilLog;
68
69 $this->server_settings = $a_server;
70 $this->setting = $ilSetting;
71
73 }
language handling
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
global $ilDB

References $ilDB, $ilLog, $ilSetting, $lng, and initLDAPAttributeMapping().

+ Here is the call graph for this function:

Member Function Documentation

◆ addMode()

ilLDAPAttributeToUser::addMode (   $a_mode)

Add import mode.

Parameters
$a_mode

Definition at line 120 of file class.ilLDAPAttributeToUser.php.

121 {
122 if (is_array($this->modes) && !in_array($a_mode, $this->modes)) {
123 $this->modes[] = $a_mode;
124 }
125 }

◆ convertInput()

ilLDAPAttributeToUser::convertInput (   $a_value)
private

A value can be an array or a string This function converts arrays to strings.

@access private

Parameters
arrayor string value
Returns
string

Definition at line 417 of file class.ilLDAPAttributeToUser.php.

418 {
419 if (is_array($a_value)) {
420 return $a_value[0];
421 } else {
422 return $a_value;
423 }
424 }

Referenced by doMapping().

+ Here is the caller graph for this function:

◆ doMapping()

ilLDAPAttributeToUser::doMapping (   $user,
  $rule 
)
private

doMapping

@access private

Definition at line 432 of file class.ilLDAPAttributeToUser.php.

433 {
434 $mapping = trim(strtolower($rule['value']));
435
436 if (strpos($mapping, ',') === false) {
437 return $this->convertInput($user[$mapping]);
438 }
439 // Is multiple mapping
440
441 $fields = explode(',', $mapping);
442 $value = '';
443 foreach ($fields as $field) {
444 if (strlen($value)) {
445 $value .= ' ';
446 }
447 $value .= ($this->convertInput($user[trim($field)]));
448 }
449 return $value ? $value : '';
450 }
convertInput($a_value)
A value can be an array or a string This function converts arrays to strings.
$rule
Definition: showstats.php:43

References $mapping, $rule, and convertInput().

Referenced by usersToXML().

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

◆ getNewUserAuthMode()

ilLDAPAttributeToUser::getNewUserAuthMode ( )

Get auth mode for new users.

Definition at line 111 of file class.ilLDAPAttributeToUser.php.

References $new_user_auth_mode.

Referenced by usersToXML().

+ Here is the caller graph for this function:

◆ getServer()

ilLDAPAttributeToUser::getServer ( )

Get server settings.

Returns
ilLDAPServer

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

References $server_settings.

Referenced by parseRoleAssignmentsForCreation(), parseRoleAssignmentsForUpdate(), and refresh().

+ Here is the caller graph for this function:

◆ initLDAPAttributeMapping()

ilLDAPAttributeToUser::initLDAPAttributeMapping ( )
private

Definition at line 454 of file class.ilLDAPAttributeToUser.php.

455 {
456 include_once('Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
457 $this->mapping = ilLDAPAttributeMapping::_getInstanceByServerId($this->server_settings->getServerId());
458 }
static _getInstanceByServerId($a_server_id)
Get instance of class.

References ilLDAPAttributeMapping\_getInstanceByServerId().

Referenced by __construct().

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

◆ initUserDefinedFields()

ilLDAPAttributeToUser::initUserDefinedFields ( )
private

Definition at line 460 of file class.ilLDAPAttributeToUser.php.

461 {
462 include_once('Services/User/classes/class.ilUserDefinedFields.php');
464 }
static _getInstance()
Get instance.

References ilUserDefinedFields\_getInstance().

Referenced by usersToXML().

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

◆ isModeActive()

ilLDAPAttributeToUser::isModeActive (   $a_mode)

Check if mode is active.

Parameters
int$a_mode
Returns
bool

Definition at line 132 of file class.ilLDAPAttributeToUser.php.

133 {
134 return is_array($this->modes) && in_array($a_mode, $this->modes);
135 }

Referenced by usersToXML().

+ Here is the caller graph for this function:

◆ parseRoleAssignmentsForCreation()

ilLDAPAttributeToUser::parseRoleAssignmentsForCreation (   $a_external_account,
  $a_user 
)
protected

Parse role assignments for update of user account.

Parameters
string$a_external_account
array$a_user

Definition at line 197 of file class.ilLDAPAttributeToUser.php.

198 {
199 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
201 $this->getServer()->getServerId(),
202 $a_external_account,
203 $a_user
204 ) as $role_data) {
205 $this->writer->xmlElement(
206 'Role',
207 array('Id' => $role_data['id'],
208 'Type' => $role_data['type'],
209 'Action' => $role_data['action']),
210 ''
211 );
212 }
213 }
static getAssignmentsForCreation($a_server_id, $a_usr_name, $a_usr_data)

References ilLDAPRoleAssignmentRules\getAssignmentsForCreation(), and getServer().

Referenced by usersToXML().

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

◆ parseRoleAssignmentsForUpdate()

ilLDAPAttributeToUser::parseRoleAssignmentsForUpdate (   $a_usr_id,
  $a_external_account,
  $user 
)
protected

Parse role assignments for update of user account.

Parameters
int$a_usr_id
string$a_external_account
array$user

Definition at line 171 of file class.ilLDAPAttributeToUser.php.

172 {
173 $rules = $this->mapping->getRulesForUpdate();
174
175 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
177 $this->getServer()->getServerId(),
178 $a_usr_id,
179 $a_external_account,
180 $user
181 ) as $role_data) {
182 $this->writer->xmlElement(
183 'Role',
184 array('Id' => $role_data['id'],
185 'Type' => $role_data['type'],
186 'Action' => $role_data['action']),
187 ''
188 );
189 }
190 }
static getAssignmentsForUpdate($a_server_id, $a_usr_id, $a_usr_name, $a_usr_data)
@global type $ilDB @global type $rbacadmin @global type $rbacreview @global type $ilSetting @global t...

References ilLDAPRoleAssignmentRules\getAssignmentsForUpdate(), and getServer().

Referenced by usersToXML().

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

◆ refresh()

ilLDAPAttributeToUser::refresh ( )

Create/Update non existing users.

@access public

Definition at line 144 of file class.ilLDAPAttributeToUser.php.

145 {
146 global $rbacadmin;
147
148 $this->usersToXML();
149
150 include_once './Services/User/classes/class.ilUserImportParser.php';
151 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
152
153 $importParser = new ilUserImportParser();
154 $importParser->setXMLContent($this->writer->xmlDumpMem(false));
155 $importParser->setRoleAssignment(ilLDAPRoleAssignmentRules::getAllPossibleRoles($this->getServer()->getServerId()));
156 $importParser->setFolderId(7);
157 $importParser->startParsing();
158 $debug = $importParser->getProtocol();
159 #var_dump("<pre>",$this->writer->xmlDumpMem(),"</pre>");
160 #print_r($this->writer->xmlDumpMem($format));
161
162 return true;
163 }
usersToXML()
Create xml string of user according to mapping rules.
static getAllPossibleRoles($a_server_id)
Get all assignable roles (used for import parser)
$debug
Definition: loganalyzer.php:16

References $debug, ilLDAPRoleAssignmentRules\getAllPossibleRoles(), getServer(), and usersToXML().

+ Here is the call graph for this function:

◆ setNewUserAuthMode()

ilLDAPAttributeToUser::setNewUserAuthMode (   $a_authmode)

Set auth mode for new users.

E.g. radius for radius authenticated user with ldap data source

Parameters
string$a_authmode

Definition at line 103 of file class.ilLDAPAttributeToUser.php.

104 {
105 $this->new_user_auth_mode = $a_authmode;
106 }

◆ setUserData()

ilLDAPAttributeToUser::setUserData (   $a_data)

Set user data received from pear auth or by ldap_search.

@access public

Parameters
arrayarray of auth data. array('ilias_account1' => array(firstname => 'Stefan',...),...)

Definition at line 93 of file class.ilLDAPAttributeToUser.php.

94 {
95 $this->user_data = $a_data;
96 }

◆ usersToXML()

ilLDAPAttributeToUser::usersToXML ( )
private

Create xml string of user according to mapping rules.

@access private

Definition at line 221 of file class.ilLDAPAttributeToUser.php.

222 {
223 include_once('./Services/Xml/classes/class.ilXmlWriter.php');
224 $this->writer = new ilXmlWriter();
225 $this->writer->xmlStartTag('Users');
226
227 $cnt_update = 0;
228 $cnt_create = 0;
229
230 // Single users
231 foreach ($this->user_data as $external_account => $user) {
232 $user['ilExternalAccount'] = $external_account;
233
234 // Required fields
235 if ($user['ilInternalAccount']) {
236 $usr_id = ilObjUser::_lookupId($user['ilInternalAccount']);
237
238 ++$cnt_update;
239 // User exists
240 $this->writer->xmlStartTag('User', array('Id' => $usr_id,'Action' => 'Update'));
241 $this->writer->xmlElement('Login', array(), $user['ilInternalAccount']);
242 $this->writer->xmlElement('ExternalAccount', array(), $external_account);
243 $this->writer->xmlElement('AuthMode', array('type' => $this->getNewUserAuthMode()), null);
244
245 if ($this->isModeActive(self::MODE_INITIALIZE_ROLES)) {
246 $this->parseRoleAssignmentsForCreation($external_account, $user);
247 } else {
248 $this->parseRoleAssignmentsForUpdate($usr_id, $external_account, $user);
249 }
250 $rules = $this->mapping->getRulesForUpdate();
251 } else {
252 ++$cnt_create;
253 // Create user
254 $this->writer->xmlStartTag('User', array('Action' => 'Insert'));
255 $this->writer->xmlElement('Login', array(), ilAuthUtils::_generateLogin($external_account));
256
257 $this->parseRoleAssignmentsForCreation($external_account, $user);
258 $rules = $this->mapping->getRules();
259 }
260
261 $this->writer->xmlElement('Active', array(), "true");
262 $this->writer->xmlElement('TimeLimitOwner', array(), 7);
263 $this->writer->xmlElement('TimeLimitUnlimited', array(), 1);
264 $this->writer->xmlElement('TimeLimitFrom', array(), time());
265 $this->writer->xmlElement('TimeLimitUntil', array(), time());
266
267 // only for new users.
268 // If auth_mode is 'default' (ldap) this status should remain.
269 if (!$user['ilInternalAccount']) {
270 $this->writer->xmlElement(
271 'AuthMode',
272 array('type' => $this->getNewUserAuthMode()),
273 $this->getNewUserAuthMode()
274 );
275 $this->writer->xmlElement('ExternalAccount', array(), $external_account);
276 }
277 foreach ($rules as $field => $data) {
278 // Do Mapping: it is possible to assign multiple ldap attribute to one user data field
279 if (!($value = $this->doMapping($user, $data))) {
280 continue;
281 }
282
283 switch ($field) {
284 case 'gender':
285 switch (strtolower($value)) {
286 case 'n':
287 case 'neutral':
288 $this->writer->xmlElement('Gender', array(), 'n');
289 break;
290
291 case 'm':
292 case 'male':
293 $this->writer->xmlElement('Gender', array(), 'm');
294 break;
295
296 case 'f':
297 case 'female':
298 default:
299 $this->writer->xmlElement('Gender', array(), 'f');
300 break;
301
302 }
303 break;
304
305 case 'firstname':
306 $this->writer->xmlElement('Firstname', array(), $value);
307 break;
308
309 case 'lastname':
310 $this->writer->xmlElement('Lastname', array(), $value);
311 break;
312
313 case 'hobby':
314 $this->writer->xmlElement('Hobby', array(), $value);
315 break;
316
317 case 'title':
318 $this->writer->xmlElement('Title', array(), $value);
319 break;
320
321 case 'institution':
322 $this->writer->xmlElement('Institution', array(), $value);
323 break;
324
325 case 'department':
326 $this->writer->xmlElement('Department', array(), $value);
327 break;
328
329 case 'street':
330 $this->writer->xmlElement('Street', array(), $value);
331 break;
332
333 case 'city':
334 $this->writer->xmlElement('City', array(), $value);
335 break;
336
337 case 'zipcode':
338 $this->writer->xmlElement('PostalCode', array(), $value);
339 break;
340
341 case 'country':
342 $this->writer->xmlElement('Country', array(), $value);
343 break;
344
345 case 'phone_office':
346 $this->writer->xmlElement('PhoneOffice', array(), $value);
347 break;
348
349 case 'phone_home':
350 $this->writer->xmlElement('PhoneHome', array(), $value);
351 break;
352
353 case 'phone_mobile':
354 $this->writer->xmlElement('PhoneMobile', array(), $value);
355 break;
356
357 case 'fax':
358 $this->writer->xmlElement('Fax', array(), $value);
359 break;
360
361 case 'email':
362 $this->writer->xmlElement('Email', array(), $value);
363 break;
364
365 case 'matriculation':
366 $this->writer->xmlElement('Matriculation', array(), $value);
367 break;
368
369 /*
370 case 'photo':
371 $this->writer->xmlElement('PersonalPicture',array('encoding' => 'Base64','imagetype' => 'image/jpeg'),
372 base64_encode($this->convertInput($user[$value])));
373 break;
374 */
375 default:
376 // Handle user defined fields
377 if (substr($field, 0, 4) != 'udf_') {
378 continue;
379 }
380 $id_data = explode('_', $field);
381 if (!isset($id_data[1])) {
382 continue;
383 }
384 $this->initUserDefinedFields();
385 $definition = $this->udf->getDefinition($id_data[1]);
386 $this->writer->xmlElement(
387 'UserDefinedField',
388 array('Id' => $definition['il_id'],
389 'Name' => $definition['field_name']),
390 $value
391 );
392 break;
393
394
395 }
396 }
397 $this->writer->xmlEndTag('User');
398 }
399
400 if ($cnt_create) {
401 $this->log->write('LDAP: Started creation of ' . $cnt_create . ' users.');
402 }
403 if ($cnt_update) {
404 $this->log->write('LDAP: Started update of ' . $cnt_update . ' users.');
405 }
406 $this->writer->xmlEndTag('Users');
407 }
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
isModeActive($a_mode)
Check if mode is active.
parseRoleAssignmentsForCreation($a_external_account, $a_user)
Parse role assignments for update of user account.
getNewUserAuthMode()
Get auth mode for new users.
parseRoleAssignmentsForUpdate($a_usr_id, $a_external_account, $user)
Parse role assignments for update of user account.
doMapping($user, $rule)
doMapping
static _lookupId($a_user_str)
Lookup id by login.
XML writer class.

References $data, ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), doMapping(), getNewUserAuthMode(), initUserDefinedFields(), isModeActive(), parseRoleAssignmentsForCreation(), and parseRoleAssignmentsForUpdate().

Referenced by refresh().

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

Field Documentation

◆ $db

ilLDAPAttributeToUser::$db = null
private

Definition at line 43 of file class.ilLDAPAttributeToUser.php.

◆ $mapping

ilLDAPAttributeToUser::$mapping = null
private

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

Referenced by doMapping().

◆ $modes

ilLDAPAttributeToUser::$modes = []
private

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

◆ $new_user_auth_mode

ilLDAPAttributeToUser::$new_user_auth_mode = 'ldap'
private

Definition at line 49 of file class.ilLDAPAttributeToUser.php.

Referenced by getNewUserAuthMode().

◆ $role_assignment

ilLDAPAttributeToUser::$role_assignment = null
private

Definition at line 42 of file class.ilLDAPAttributeToUser.php.

◆ $server_settings

ilLDAPAttributeToUser::$server_settings = null
private

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

Referenced by getServer().

◆ $setting

ilLDAPAttributeToUser::$setting = null
private

Definition at line 46 of file class.ilLDAPAttributeToUser.php.

◆ $user_data

ilLDAPAttributeToUser::$user_data = array()
private

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

◆ MODE_INITIALIZE_ROLES

const ilLDAPAttributeToUser::MODE_INITIALIZE_ROLES = 1

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