ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

35 {
36 $this->initServer($a_authmode, $a_server_id);
37 }
initServer($a_auth_mode, $a_server_id)
Init LDAP server.

References initServer().

+ 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.

Referenced by performUpdate().

+ Here is the caller graph for this function:

◆ handleCreation()

ilLDAPUserSynchronisation::handleCreation ( )
protected

Handle creation of user accounts.

Exceptions
ilLDAPSynchronisationForbiddenException
ilLDAPAccountMigrationRequiredException

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

160 {
161 // Disabled sync on login
162 if (!$this->getServer()->enabledSyncOnLogin()) {
163 throw new ilLDAPSynchronisationForbiddenException('User synchronisation forbidden.');
164 }
165 // Account migration
166 if ($this->getServer()->isAccountMigrationEnabled() and !$this->isCreationForced()) {
167 $this->readUserData();
168 throw new ilLDAPAccountMigrationRequiredException('Account migration check required.');
169 }
170 }
Description of ilLDAPAccountMigrationRequiredException.
isCreationForced()
Check if creation of user account is forced (account migration)

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

Referenced by sync().

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

273 {
274 $this->authmode = $a_auth_mode;
275 $this->server = ilLDAPServer::getInstanceByServerId($a_server_id);
276 }
static getInstanceByServerId($a_server_id)
Get instance by server id.

References ilLDAPServer\getInstanceByServerId().

Referenced by __construct().

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

245 {
246 if ($this->isCreationForced()) {
247 return true;
248 }
249 if (!$this->getInternalAccount()) {
250 return true;
251 }
252
253 // Check attribute mapping on login
254 include_once './Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
255 if (ilLDAPAttributeMapping::hasRulesForUpdate($this->getServer()->getServerId())) {
256 return true;
257 }
258
259 // Check if there is any change in role assignments
260 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
262 return true;
263 }
264 return false;
265 }
static hasRulesForUpdate($a_server_id)
Check if there is ldap attribute -> user data mapping which which is updated on login.
static hasRulesForUpdate()
Check if there any rule for updates.
getInternalAccount()
Get ILIAS unique internal account name.

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

Referenced by sync().

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

177 {
178 include_once './Services/User/classes/class.ilUserCreationContext.php';
180
181 include_once 'Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
182 $update = new ilLDAPAttributeToUser($this->getServer());
183 if ($this->isCreationForced()) {
185 }
186 $update->setNewUserAuthMode($this->getAuthMode());
187 $update->setUserData(
188 array(
189 $this->getExternalAccount() => $this->getUserData()
190 )
191 );
192
193 $update->refresh();
194
195 // User has been created, now read internal account again
196 $this->readInternalAccount();
197 return true;
198 }
Update/create ILIAS user account by given LDAP attributes according to user attribute mapping setting...
readInternalAccount()
Read internal account of user.
static getInstance()
Get instance.

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

Referenced by sync().

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

230 {
231 if (!$this->getExternalAccount()) {
232 throw new UnexpectedValueException('No external account given.');
233 }
234 $this->intaccount = ilObjUser::_checkExternalAuthAccount(
235 $this->getAuthMode(),
236 $this->getExternalAccount()
237 );
238 }
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user

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

Referenced by performUpdate(), and sync().

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

205 {
206 // Add internal account to user data
207 $this->user_data['ilInternalAccount'] = $this->getInternalAccount();
208
209 if (!$this->force_read_ldap_data) {
210 if (substr($this->getAuthMode(), 0, 4) == 'ldap') {
211 return true;
212 }
213 }
214
215 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
216 $query = new ilLDAPQuery($this->getServer());
217 $user = $query->fetchUser($this->getExternalAccount());
218
219 ilLoggerFactory::getLogger('auth')->dump($user, ilLogLevel::DEBUG);
220
221 $this->user_data = (array) $user[$this->getExternalAccount()];
222 }
static getLogger($a_component_id)
Get component logger.
$query

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

Referenced by handleCreation(), and sync().

+ 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.

62 {
63 $this->extaccount = $a_ext;
64 }

◆ setUserData()

ilLDAPUserSynchronisation::setUserData (   $a_data)

Set user data.

Parameters
array$a_data

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

121 {
122 $this->user_data = (array) $a_data;
123 }

◆ 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.

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

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

+ 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: