ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilLDAPUserSynchronisation Class Reference

Synchronization of user accounts used in auth container ldap, radius , cas,... More...

+ Collaboration diagram for ilLDAPUserSynchronisation:

Public Member Functions

 __construct ($a_authmode, $a_server_id)
 Constructor. More...
 
 getServer ()
 Get current ldap server. More...
 
 getAuthMode ()
 Get Auth Mode. More...
 
 setExternalAccount ($a_ext)
 Set external account (unique for each auth mode) More...
 
 getExternalAccount ()
 Get external accocunt. More...
 
 getInternalAccount ()
 Get ILIAS unique internal account name. More...
 
 forceCreation ($a_force)
 Force cration of user accounts (Account migration enabled) More...
 
 forceReadLdapData ($a_status)
 
 isCreationForced ()
 Check if creation of user account is forced (account migration) More...
 
 getUserData ()
 Get user data. More...
 
 setUserData ($a_data)
 Set user data. More...
 
 sync ()
 Synchronize user account. More...
 

Protected Member Functions

 handleCreation ()
 Handle creation of user accounts. More...
 
 performUpdate ()
 Update user account and role assignments. More...
 
 readUserData ()
 Read user data. More...
 
 readInternalAccount ()
 Read internal account of user. More...
 
 isUpdateRequired ()
 Check if an update is required. More...
 
 initServer ($a_auth_mode, $a_server_id)
 Init LDAP server. More...
 

Private Attributes

 $authmode = 0
 
 $server = null
 
 $extaccount = ''
 
 $intaccount = ''
 
 $user_data = array()
 
 $force_creation = false
 
 $force_read_ldap_data = false
 

Detailed Description

Synchronization of user accounts used in auth container ldap, radius , cas,...

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

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

Constructor & Destructor Documentation

◆ __construct()

ilLDAPUserSynchronisation::__construct (   $a_authmode,
  $a_server_id 
)

Constructor.

Parameters
string$a_auth_mode

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

References initServer().

35  {
36  $this->initServer($a_authmode,$a_server_id);
37  }
initServer($a_auth_mode, $a_server_id)
Init LDAP server.
+ Here is the call graph for this function:

Member Function Documentation

◆ forceCreation()

ilLDAPUserSynchronisation::forceCreation (   $a_force)

Force cration of user accounts (Account migration enabled)

Parameters
bool$a_force

Definition at line 88 of file class.ilLDAPUserSynchronisation.php.

89  {
90  $this->force_creation = $a_force;
91  }

◆ forceReadLdapData()

ilLDAPUserSynchronisation::forceReadLdapData (   $a_status)

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

94  {
95  $this->force_read_ldap_data = $a_status;
96  }

◆ getAuthMode()

ilLDAPUserSynchronisation::getAuthMode ( )

Get Auth Mode.

Returns
int authmode

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

References $authmode.

Referenced by performUpdate(), readInternalAccount(), and readUserData().

+ Here is the caller graph for this function:

◆ getExternalAccount()

ilLDAPUserSynchronisation::getExternalAccount ( )

Get external accocunt.

Returns
<type>

Definition at line 70 of file class.ilLDAPUserSynchronisation.php.

References $extaccount.

Referenced by performUpdate(), readInternalAccount(), and readUserData().

+ Here is the caller graph for this function:

◆ getInternalAccount()

ilLDAPUserSynchronisation::getInternalAccount ( )

Get ILIAS unique internal account name.

Returns
string internal account

Definition at line 79 of file class.ilLDAPUserSynchronisation.php.

References $intaccount.

Referenced by isUpdateRequired(), readUserData(), and sync().

+ Here is the caller graph for this function:

◆ getServer()

ilLDAPUserSynchronisation::getServer ( )

Get current ldap server.

Returns
ilLDAPServer $server

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

References $server.

Referenced by handleCreation(), isUpdateRequired(), performUpdate(), readUserData(), and sync().

+ Here is the caller graph for this function:

◆ getUserData()

ilLDAPUserSynchronisation::getUserData ( )

Get user data.

Returns
array $user_data

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

References $user_data, and array.

Referenced by performUpdate().

112  {
113  return (array) $this->user_data;
114  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ handleCreation()

ilLDAPUserSynchronisation::handleCreation ( )
protected

Handle creation of user accounts.

Exceptions
ilLDAPSynchronisationForbiddenException
ilLDAPAccountMigrationRequiredException

Definition at line 162 of file class.ilLDAPUserSynchronisation.php.

References getServer(), isCreationForced(), and readUserData().

Referenced by sync().

163  {
164  // Disabled sync on login
165  if(!$this->getServer()->enabledSyncOnLogin())
166  {
167  throw new ilLDAPSynchronisationForbiddenException('User synchronisation forbidden.');
168  }
169  // Account migration
170  if($this->getServer()->isAccountMigrationEnabled() and !$this->isCreationForced())
171  {
172  $this->readUserData();
173  throw new ilLDAPAccountMigrationRequiredException('Account migration check required.');
174  }
175  }
isCreationForced()
Check if creation of user account is forced (account migration)
Description of ilLDAPAccountMigrationRequiredException.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initServer()

ilLDAPUserSynchronisation::initServer (   $a_auth_mode,
  $a_server_id 
)
protected

Init LDAP server.

Parameters
int$a_server_id

Definition at line 285 of file class.ilLDAPUserSynchronisation.php.

References ilLDAPServer\getInstanceByServerId().

Referenced by __construct().

286  {
287  $this->authmode = $a_auth_mode;
288  $this->server = ilLDAPServer::getInstanceByServerId($a_server_id);
289  }
static getInstanceByServerId($a_server_id)
Get instance by server id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCreationForced()

ilLDAPUserSynchronisation::isCreationForced ( )

Check if creation of user account is forced (account migration)

Returns
bool

Definition at line 102 of file class.ilLDAPUserSynchronisation.php.

References $force_creation.

Referenced by handleCreation(), isUpdateRequired(), and performUpdate().

+ Here is the caller graph for this function:

◆ isUpdateRequired()

ilLDAPUserSynchronisation::isUpdateRequired ( )
protected

Check if an update is required.

Returns
bool

Definition at line 253 of file class.ilLDAPUserSynchronisation.php.

References getInternalAccount(), getServer(), ilLDAPRoleAssignmentRule\hasRulesForUpdate(), ilLDAPAttributeMapping\hasRulesForUpdate(), and isCreationForced().

Referenced by sync().

254  {
255  if($this->isCreationForced())
256  {
257  return true;
258  }
259  if(!$this->getInternalAccount())
260  {
261  return true;
262  }
263 
264  // Check attribute mapping on login
265  include_once './Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
266  if(ilLDAPAttributeMapping::hasRulesForUpdate($this->getServer()->getServerId()))
267  {
268  return true;
269  }
270 
271  // Check if there is any change in role assignments
272  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
274  {
275  return true;
276  }
277  return false;
278  }
static hasRulesForUpdate()
Check if there any rule for updates.
static hasRulesForUpdate($a_server_id)
Check if there is ldap attribute -> user data mapping which which is updated on login.
isCreationForced()
Check if creation of user account is forced (account migration)
getInternalAccount()
Get ILIAS unique internal account name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ performUpdate()

ilLDAPUserSynchronisation::performUpdate ( )
protected

Update user account and role assignments.

Returns
bool

Definition at line 181 of file class.ilLDAPUserSynchronisation.php.

References array, ilUserCreationContext\CONTEXT_LDAP, getAuthMode(), getExternalAccount(), ilUserCreationContext\getInstance(), getServer(), getUserData(), isCreationForced(), ilLDAPAttributeToUser\MODE_INITIALIZE_ROLES, and readInternalAccount().

Referenced by sync().

182  {
183  include_once './Services/User/classes/class.ilUserCreationContext.php';
185 
186  include_once 'Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
187  $update = new ilLDAPAttributeToUser($this->getServer());
188  if($this->isCreationForced())
189  {
191  }
192  $update->setNewUserAuthMode($this->getAuthMode());
193  $update->setUserData(
194  array(
195  $this->getExternalAccount() => $this->getUserData()
196  )
197  );
198 
199  $update->refresh();
200 
201  // User has been created, now read internal account again
202  $this->readInternalAccount();
203  return true;
204  }
static getInstance()
Get instance.
isCreationForced()
Check if creation of user account is forced (account migration)
Create styles array
The data for the language used.
readInternalAccount()
Read internal account of user.
Update/create ILIAS user account by given LDAP attributes according to user attribute mapping setting...
getExternalAccount()
Get external accocunt.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readInternalAccount()

ilLDAPUserSynchronisation::readInternalAccount ( )
protected

Read internal account of user.

Exceptions
UnexpectedValueException

Definition at line 237 of file class.ilLDAPUserSynchronisation.php.

References ilObjUser\_checkExternalAuthAccount(), getAuthMode(), and getExternalAccount().

Referenced by performUpdate(), and sync().

238  {
239  if(!$this->getExternalAccount())
240  {
241  throw new UnexpectedValueException('No external account given.');
242  }
243  $this->intaccount = ilObjUser::_checkExternalAuthAccount(
244  $this->getAuthMode(),
245  $this->getExternalAccount()
246  );
247  }
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
getExternalAccount()
Get external accocunt.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readUserData()

ilLDAPUserSynchronisation::readUserData ( )
protected

Read user data.

In case of auth mode != 'ldap' start a query with external account name against ldap server

Definition at line 210 of file class.ilLDAPUserSynchronisation.php.

References $query, array, ilLogLevel\DEBUG, getAuthMode(), getExternalAccount(), getInternalAccount(), ilLoggerFactory\getLogger(), and getServer().

Referenced by handleCreation(), and sync().

211  {
212  // Add internal account to user data
213  $this->user_data['ilInternalAccount'] = $this->getInternalAccount();
214 
215  if(!$this->force_read_ldap_data)
216  {
217  if(substr($this->getAuthMode(),0,4) == 'ldap')
218  {
219  return true;
220  }
221  }
222 
223  include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
224  $query = new ilLDAPQuery($this->getServer());
225  $user = $query->fetchUser($this->getExternalAccount());
226 
227  ilLoggerFactory::getLogger('auth')->dump($user, ilLogLevel::DEBUG);
228 
229  $this->user_data = (array) $user[$this->getExternalAccount()];
230  }
getInternalAccount()
Get ILIAS unique internal account name.
Create styles array
The data for the language used.
static getLogger($a_component_id)
Get component logger.
getExternalAccount()
Get external accocunt.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setExternalAccount()

ilLDAPUserSynchronisation::setExternalAccount (   $a_ext)

Set external account (unique for each auth mode)

Parameters
string$a_ext

Definition at line 61 of file class.ilLDAPUserSynchronisation.php.

Referenced by ilAuthProviderCAS\handleLDAPDataSource(), ilAuthContainerCAS\handleLDAPDataSource(), ilAuthContainerRadius\handleLDAPDataSource(), ilAuthProviderApache\handleLDAPDataSource(), ilAuthContainerApache\handleLDAPDataSource(), and ilAuthContainerLDAP\loginObserver().

62  {
63  $this->extaccount = $a_ext;
64  }
+ Here is the caller graph for this function:

◆ setUserData()

ilLDAPUserSynchronisation::setUserData (   $a_data)

Set user data.

Parameters
array$a_data

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

References array.

121  {
122  $this->user_data = (array) $a_data;
123  }
Create styles array
The data for the language used.

◆ sync()

ilLDAPUserSynchronisation::sync ( )

Synchronize user account.

Todo:
Redirects to account migration if required
Exceptions
UnexpectedValueExceptionmissing or wrong external account given
ilLDAPSynchronisationForbiddenExceptionif user synchronisation is disabled

Definition at line 131 of file class.ilLDAPUserSynchronisation.php.

References getInternalAccount(), ilLoggerFactory\getLogger(), getServer(), handleCreation(), isUpdateRequired(), performUpdate(), readInternalAccount(), and readUserData().

132  {
133  $this->readInternalAccount();
134 
135  if(!$this->getInternalAccount())
136  {
137  ilLoggerFactory::getLogger('auth')->debug('Creating new account');
138  $this->handleCreation();
139  }
140 
141  // Nothing to do if sync on login is disabled
142  if(!$this->getServer()->enabledSyncOnLogin())
143  {
144  return $this->getInternalAccount();
145  }
146 
147  // For performance reasons, check if (an update is required)
148  if($this->isUpdateRequired())
149  {
150  ilLoggerFactory::getLogger('auth')->debug('Perform update of user data');
151  $this->readUserData();
152  $this->performUpdate();
153  }
154  return $this->getInternalAccount();
155  }
performUpdate()
Update user account and role assignments.
isUpdateRequired()
Check if an update is required.
getInternalAccount()
Get ILIAS unique internal account name.
handleCreation()
Handle creation of user accounts.
readInternalAccount()
Read internal account of user.
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

Field Documentation

◆ $authmode

ilLDAPUserSynchronisation::$authmode = 0
private

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

Referenced by getAuthMode().

◆ $extaccount

ilLDAPUserSynchronisation::$extaccount = ''
private

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

Referenced by getExternalAccount().

◆ $force_creation

ilLDAPUserSynchronisation::$force_creation = false
private

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

Referenced by isCreationForced().

◆ $force_read_ldap_data

ilLDAPUserSynchronisation::$force_read_ldap_data = false
private

Definition at line 26 of file class.ilLDAPUserSynchronisation.php.

◆ $intaccount

ilLDAPUserSynchronisation::$intaccount = ''
private

Definition at line 21 of file class.ilLDAPUserSynchronisation.php.

Referenced by getInternalAccount().

◆ $server

ilLDAPUserSynchronisation::$server = null
private

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

Referenced by getServer().

◆ $user_data

ilLDAPUserSynchronisation::$user_data = array()
private

Definition at line 23 of file class.ilLDAPUserSynchronisation.php.

Referenced by getUserData().


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