ILIAS  release_4-3 Revision
 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.
 setNewUserAuthMode ($a_authmode)
 Set auth mode for new users.
 getNewUserAuthMode ()
 Get auth mode for new users.
 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
 initLDAPAttributeMapping ()
 initUserDefinedFields ()

Private Attributes

 $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

ilLDAPAttributeToUser::__construct ( ilLDAPServer  $a_server)

Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.

Parameters
objectil

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

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

{
global $ilDB,$ilSetting,$lng,$ilLog;
// Initialise language object
if(!is_object($lng))
{
include_once './Services/Language/classes/class.ilLanguage.php';
$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 347 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 365 of file class.ilLDAPAttributeToUser.php.

References $mapping, 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::getNewUserAuthMode ( )

Get auth mode for new users.

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

References $new_user_auth_mode.

Referenced by usersToXML().

+ Here is the caller graph for this function:

ilLDAPAttributeToUser::initLDAPAttributeMapping ( )
private

Definition at line 390 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::initUserDefinedFields ( )
private

Definition at line 396 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 108 of file class.ilLDAPAttributeToUser.php.

References ilLDAPRoleAssignmentRules\getAllPossibleRoles(), and usersToXML().

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

+ Here is the call graph for this function:

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 88 of file class.ilLDAPAttributeToUser.php.

{
$this->new_user_auth_mode = $a_authmode;
}
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 78 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 135 of file class.ilLDAPAttributeToUser.php.

References $data, $usr_id, ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), doMapping(), ilLDAPRoleAssignmentRules\getAssignmentsForCreation(), ilLDAPRoleAssignmentRules\getAssignmentsForUpdate(), getNewUserAuthMode(), and initUserDefinedFields().

Referenced by refresh().

{
include_once('./Services/Xml/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)
{
$user['ilExternalAccount'] = $external_account;
// 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 => $this->getNewUserAuthMode()),null);
$rules = $this->mapping->getRulesForUpdate();
include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
foreach(ilLDAPRoleAssignmentRules::getAssignmentsForUpdate($usr_id,$external_account, $user) as $role_data)
{
$this->writer->xmlElement('Role',
array('Id' => $role_data['id'],
'Type' => $role_data['type'],
'Action' => $role_data['action']),'');
}
}
else
{
++$cnt_create;
// Create user
$this->writer->xmlStartTag('User',array('Action' => 'Insert'));
$this->writer->xmlElement('Login',array(),ilAuthUtils::_generateLogin($external_account));
include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
foreach(ilLDAPRoleAssignmentRules::getAssignmentsForCreation($external_account, $user) as $role_data)
{
$this->writer->xmlElement('Role',
array('Id' => $role_data['id'],
'Type' => $role_data['type'],
'Action' => $role_data['action']),'');
}
$rules = $this->mapping->getRules();
}
$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' => $this->getNewUserAuthMode()),
);
$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 38 of file class.ilLDAPAttributeToUser.php.

ilLDAPAttributeToUser::$mapping = null
private

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

Referenced by doMapping().

ilLDAPAttributeToUser::$new_user_auth_mode = 'ldap'
private

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

Referenced by getNewUserAuthMode().

ilLDAPAttributeToUser::$role_assignment = null
private

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

ilLDAPAttributeToUser::$server_settings = null
private

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

ilLDAPAttributeToUser::$setting = null
private

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

ilLDAPAttributeToUser::$user_data = array()
private

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


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