ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 
 $logger
 

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 36 of file class.ilLDAPUserSynchronisation.php.

References $DIC, and initServer().

37  {
38  global $DIC;
39 
40  $this->logger = $DIC->logger()->auth();
41  $this->initServer($a_authmode, $a_server_id);
42  }
initServer($a_auth_mode, $a_server_id)
Init LDAP server.
$DIC
Definition: xapitoken.php:46
+ 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 93 of file class.ilLDAPUserSynchronisation.php.

94  {
95  $this->force_creation = $a_force;
96  }

◆ forceReadLdapData()

ilLDAPUserSynchronisation::forceReadLdapData (   $a_status)

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

99  {
100  $this->force_read_ldap_data = $a_status;
101  }

◆ getAuthMode()

ilLDAPUserSynchronisation::getAuthMode ( )

Get Auth Mode.

Returns
int authmode

Definition at line 57 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 75 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 84 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 48 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 116 of file class.ilLDAPUserSynchronisation.php.

References $user_data.

Referenced by performUpdate().

117  {
118  return (array) $this->user_data;
119  }
+ Here is the caller graph for this function:

◆ handleCreation()

ilLDAPUserSynchronisation::handleCreation ( )
protected

Handle creation of user accounts.

Exceptions
ilLDAPSynchronisationForbiddenException
ilLDAPAccountMigrationRequiredException

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

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

Referenced by sync().

166  {
167  // Disabled sync on login
168  if (!$this->getServer()->enabledSyncOnLogin()) {
169  throw new ilLDAPSynchronisationForbiddenException('User synchronisation forbidden.');
170  }
171  // Account migration
172  if ($this->getServer()->isAccountMigrationEnabled() and !$this->isCreationForced()) {
173  $this->readUserData();
174  throw new ilLDAPAccountMigrationRequiredException('Account migration check required.');
175  }
176  }
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 281 of file class.ilLDAPUserSynchronisation.php.

References ilLDAPServer\getInstanceByServerId().

Referenced by __construct().

282  {
283  $this->authmode = $a_auth_mode;
284  $this->server = ilLDAPServer::getInstanceByServerId($a_server_id);
285  }
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 107 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  return true;
257  }
258  if (!$this->getInternalAccount()) {
259  return true;
260  }
261 
262  // Check attribute mapping on login
263  include_once './Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
264  if (ilLDAPAttributeMapping::hasRulesForUpdate($this->getServer()->getServerId())) {
265  return true;
266  }
267 
268  // Check if there is any change in role assignments
269  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
271  return true;
272  }
273  return false;
274  }
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 182 of file class.ilLDAPUserSynchronisation.php.

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

Referenced by sync().

183  {
184  include_once './Services/User/classes/class.ilUserCreationContext.php';
186 
187  include_once 'Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
188  $update = new ilLDAPAttributeToUser($this->getServer());
189  if ($this->isCreationForced()) {
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)
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 238 of file class.ilLDAPUserSynchronisation.php.

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

Referenced by performUpdate(), and sync().

239  {
240  if (!$this->getExternalAccount()) {
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, $tryFallback=true)
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

Exceptions
ilLDAPSynchronisationFailedException

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

References Vendor\Package\$e, $query, ilLogLevel\DEBUG, getAuthMode(), getExternalAccount(), getInternalAccount(), getServer(), and ilLDAPQuery\LDAP_BIND_DEFAULT.

Referenced by handleCreation(), and sync().

211  : bool
212  {
213  // Add internal account to user data
214  $this->user_data['ilInternalAccount'] = $this->getInternalAccount();
215  if (!$this->force_read_ldap_data && strpos($this->getAuthMode(), 'ldap') === 0) {
216  return true;
217  }
218 
219  try {
220  $query = new ilLDAPQuery($this->getServer());
222  $user = $query->fetchUser($this->getExternalAccount());
223  $this->logger->dump($user, ilLogLevel::DEBUG);
224  $this->user_data = (array) $user[$this->getExternalAccount()];
225  } catch (ilLDAPQueryException $e) {
226  $this->logger->error('LDAP bind failed with message: ' . $e->getMessage());
227  throw new ilLDAPSynchronisationFailedException($e->getMessage());
228  }
229 
230  return true;
231  }
Thrown in case of failed synchronisation settings.
getInternalAccount()
Get ILIAS unique internal account name.
$query
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 66 of file class.ilLDAPUserSynchronisation.php.

Referenced by ilAuthProviderCAS\handleLDAPDataSource(), and ilAuthProviderApache\handleLDAPDataSource().

67  {
68  $this->extaccount = $a_ext;
69  }
+ Here is the caller graph for this function:

◆ setUserData()

ilLDAPUserSynchronisation::setUserData (   $a_data)

Set user data.

Parameters
array$a_data

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

126  {
127  $this->user_data = (array) $a_data;
128  }

◆ 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
ilLDAPSynchronisationFailedExceptionbind failure

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

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

138  {
139  $this->readInternalAccount();
140 
141  if (!$this->getInternalAccount()) {
142  ilLoggerFactory::getLogger('auth')->debug('Creating new account');
143  $this->handleCreation();
144  }
145 
146  // Nothing to do if sync on login is disabled
147  if (!$this->getServer()->enabledSyncOnLogin()) {
148  return $this->getInternalAccount();
149  }
150 
151  // For performance reasons, check if (an update is required)
152  if ($this->isUpdateRequired()) {
153  ilLoggerFactory::getLogger('auth')->debug('Perform update of user data');
154  $this->readUserData();
155  $this->performUpdate();
156  }
157  return $this->getInternalAccount();
158  }
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().

◆ $logger

ilLDAPUserSynchronisation::$logger
private

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

◆ $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: