ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 setUserData ($a_data)
 Set user data received from pear auth or by ldap_search.
 refresh ()
 Create/Update non existing users.

Private Member Functions

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

Private Attributes

 $server_settings = null
 $role_assignment = null
 $db = null
 $user_data = array()
 $setting = null
 $mapping = null

Detailed Description

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

Author
Stefan Meyer smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
$Id$

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

Constructor & Destructor Documentation

ilLDAPAttributeToUser::__construct ( ilLDAPServer  $a_server)

Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.

Parameters
objectil

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

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

{
global $ilDB,$ilSetting,$lng,$ilLog;
// Initialise language object
if(!is_object($lng))
{
$lng = new ilLanguage('en');
}
$this->log = $ilLog;
$this->server_settings = $a_server;
$this->setting = $ilSetting;
}

+ Here is the call graph for this function:

Member Function Documentation

ilLDAPAttributeToUser::convertInput (   $a_value)
private

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

private

Parameters
arrayor string value
Returns
string

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

Referenced by doMapping().

{
if(is_array($a_value))
{
return $a_value[0];
}
else
{
return $a_value;
}
}

+ Here is the caller graph for this function:

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

doMapping

private

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

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

Referenced by usersToXML().

{
$mapping = trim(strtolower($rule['value']));
if(strpos($mapping,',') === false)
{
return $this->convertInput($user[$mapping]);
}
// Is multiple mapping
$fields = explode(',',$mapping);
$value = '';
foreach($fields as $field)
{
if(strlen($value))
{
$value .= ' ';
}
$value .= ($this->convertInput($user[trim($field)]));
}
return $value ? $value : '';
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLDAPAttributeToUser::initLDAPAttributeMapping ( )
private

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

References ilLDAPAttributeMapping\_getInstanceByServerId().

Referenced by __construct().

{
include_once('Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
$this->mapping = ilLDAPAttributeMapping::_getInstanceByServerId($this->server_settings->getServerId());
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLDAPAttributeToUser::initLDAPRoleAssignments ( )
private

Init LDAP role assignment object.

private

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

References ilLDAPRoleAssignments\_getInstanceByServer().

Referenced by __construct().

{
include_once('Services/LDAP/classes/class.ilLDAPRoleAssignments.php');
$this->role_assignment = ilLDAPRoleAssignments::_getInstanceByServer($this->server_settings);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLDAPAttributeToUser::initUserDefinedFields ( )
private

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

References ilUserDefinedFields\_getInstance().

Referenced by usersToXML().

{
include_once('Services/User/classes/class.ilUserDefinedFields.php');
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilLDAPAttributeToUser::refresh ( )

Create/Update non existing users.

public

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

References usersToXML().

{
global $rbacadmin;
$this->usersToXML();
include_once './Services/User/classes/class.ilUserImportParser.php';
$importParser = new ilUserImportParser();
$importParser->setXMLContent($this->writer->xmlDumpMem(false));
$importParser->setRoleAssignment($this->role_assignment->getPossibleRoles());
$importParser->setFolderId(7);
$importParser->startParsing();
$debug = $importParser->getProtocol();
#var_dump("<pre>",$this->writer->xmlDumpMem(),"</pre>");
return true;
}

+ Here is the call graph for this function:

ilLDAPAttributeToUser::setUserData (   $a_data)

Set user data received from pear auth or by ldap_search.

public @ param array array of auth data. array('ilias_account1' => array(firstname => 'Stefan',...),...)

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

{
$this->user_data = $a_data;
}
ilLDAPAttributeToUser::usersToXML ( )
private

Create xml string of user according to mapping rules.

private

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

References $data, $user, ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), doMapping(), and initUserDefinedFields().

Referenced by refresh().

{
include_once('classes/class.ilXmlWriter.php');
$this->writer = new ilXmlWriter();
$this->writer->xmlStartTag('Users');
$cnt_update = 0;
$cnt_create = 0;
// Single users
foreach($this->user_data as $external_account => $user)
{
// Required fields
if($user['ilInternalAccount'])
{
$usr_id = ilObjUser::_lookupId($user['ilInternalAccount']);
++$cnt_update;
// User exists
$this->writer->xmlStartTag('User',array('Id' => $usr_id,'Action' => 'Update'));
$this->writer->xmlElement('Login',array(),$user['ilInternalAccount']);
$this->writer->xmlElement('ExternalAccount',array(),$external_account);
$this->writer->xmlElement('AuthMode',array(type =>'ldap'),null);
$rules = $this->mapping->getRulesForUpdate();
}
else
{
++$cnt_create;
// Create user
$this->writer->xmlStartTag('User',array('Action' => 'Insert'));
$this->writer->xmlElement('Login',array(),ilAuthUtils::_generateLogin($external_account));
$rules = $this->mapping->getRules();
// Assign to role only for new users
$roles = $this->role_assignment->assignedRoles($external_account,$user);
foreach($roles as $role_data)
{
$this->writer->xmlElement('Role',
array('Id' => $role_data['id'],
'Type' => $role_data['type'],
'Action' => $role_data['action']),'');
}
}
$this->writer->xmlElement('Active',array(),"true");
$this->writer->xmlElement('TimeLimitOwner',array(),7);
$this->writer->xmlElement('TimeLimitUnlimited',array(),1);
$this->writer->xmlElement('TimeLimitFrom',array(),time());
$this->writer->xmlElement('TimeLimitUntil',array(),time());
// only for new users.
// If auth_mode is 'default' (ldap) this status should remain.
if(!$user['ilInternalAccount'])
{
$this->writer->xmlElement('AuthMode',array('type' => 'ldap'),'ldap');
$this->writer->xmlElement('ExternalAccount',array(),$external_account);
}
foreach($rules as $field => $data)
{
// Do Mapping: it is possible to assign multiple ldap attribute to one user data field
if(!($value = $this->doMapping($user,$data)))
{
continue;
}
switch($field)
{
case 'gender':
switch(strtolower($value))
{
case 'm':
case 'male':
$this->writer->xmlElement('Gender',array(),'m');
break;
case 'f':
case 'female':
default:
$this->writer->xmlElement('Gender',array(),'f');
break;
}
break;
case 'firstname':
$this->writer->xmlElement('Firstname',array(),$value);
break;
case 'lastname':
$this->writer->xmlElement('Lastname',array(),$value);
break;
case 'hobby':
$this->writer->xmlElement('Hobby',array(),$value);
break;
case 'title':
$this->writer->xmlElement('Title',array(),$value);
break;
case 'institution':
$this->writer->xmlElement('Institution',array(),$value);
break;
case 'department':
$this->writer->xmlElement('Department',array(),$value);
break;
case 'street':
$this->writer->xmlElement('Street',array(),$value);
break;
case 'city':
$this->writer->xmlElement('City',array(),$value);
break;
case 'zipcode':
$this->writer->xmlElement('PostalCode',array(),$value);
break;
case 'country':
$this->writer->xmlElement('Country',array(),$value);
break;
case 'phone_office':
$this->writer->xmlElement('PhoneOffice',array(),$value);
break;
case 'phone_home':
$this->writer->xmlElement('PhoneHome',array(),$value);
break;
case 'phone_mobile':
$this->writer->xmlElement('PhoneMobile',array(),$value);
break;
case 'fax':
$this->writer->xmlElement('Fax',array(),$value);
break;
case 'email':
$this->writer->xmlElement('Email',array(),$value);
break;
case 'matriculation':
$this->writer->xmlElement('Matriculation',array(),$value);
break;
/*
case 'photo':
$this->writer->xmlElement('PersonalPicture',array('encoding' => 'Base64','imagetype' => 'image/jpeg'),
base64_encode($this->convertInput($user[$value])));
break;
*/
default:
// Handle user defined fields
if(substr($field,0,4) != 'udf_')
{
continue;
}
$id_data = explode('_',$field);
if(!isset($id_data[1]))
{
continue;
}
$definition = $this->udf->getDefinition($id_data[1]);
$this->writer->xmlElement('UserDefinedField',array('Id' => $definition['il_id'],
'Name' => $definition['field_name']),
$value);
break;
}
}
$this->writer->xmlEndTag('User');
}
if($cnt_create)
{
$this->log->write('LDAP: Started creation of '.$cnt_create.' users.');
}
if($cnt_update)
{
$this->log->write('LDAP: Started update of '.$cnt_update.' users.');
}
$this->writer->xmlEndTag('Users');
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilLDAPAttributeToUser::$db = null
private

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

ilLDAPAttributeToUser::$mapping = null
private

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

Referenced by doMapping().

ilLDAPAttributeToUser::$role_assignment = null
private

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

ilLDAPAttributeToUser::$server_settings = null
private

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

ilLDAPAttributeToUser::$setting = null
private

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

ilLDAPAttributeToUser::$user_data = array()
private

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


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