ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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...
 
 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...
 
 handleAccountMigration ()
 Handle account migration. 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
 

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

34 {
35 $this->initServer($a_authmode,$a_server_id);
36 }
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 87 of file class.ilLDAPUserSynchronisation.php.

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

◆ getAuthMode()

ilLDAPUserSynchronisation::getAuthMode ( )

Get Auth Mode.

Returns
int authmode

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

References $authmode.

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

+ Here is the caller graph for this function:

◆ getExternalAccount()

ilLDAPUserSynchronisation::getExternalAccount ( )

Get external accocunt.

Returns
<type>

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

References $extaccount.

Referenced by handleAccountMigration(), 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 78 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 42 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 105 of file class.ilLDAPUserSynchronisation.php.

References $user_data.

Referenced by handleAccountMigration(), and performUpdate().

+ Here is the caller graph for this function:

◆ handleAccountMigration()

ilLDAPUserSynchronisation::handleAccountMigration ( )
protected

Handle account migration.

Todo:
to much session based handling

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

176 {
177 // TODO: handle multiple ldap server
178
179 $_SESSION['tmp_auth_mode'] = $this->getAuthMode();
180 $_SESSION['tmp_external_account'] = $this->getExternalAccount();
181 $_SESSION['tmp_pass'] = $_POST['password'];
182
183 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
185 $this->getExternalAccount(),
186 $this->getUserData()
187 );
188
189 $_SESSION['tmp_roles'] = array();
190 foreach($roles as $info)
191 {
193 {
194 $_SESSION['tmp_roles'][] = $info['id'];
195 }
196 }
197 return true;
198 }
static getAssignmentsForCreation($a_usr_name, $a_usr_data)
$_POST['username']
Definition: cron.php:12
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']

References $_POST, $_SESSION, ilLDAPRoleAssignmentRules\getAssignmentsForCreation(), getAuthMode(), getExternalAccount(), getUserData(), and ilLDAPRoleAssignmentRules\ROLE_ACTION_ASSIGN.

Referenced by handleCreation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleCreation()

ilLDAPUserSynchronisation::handleCreation ( )
protected

Handle creation of user accounts.

Exceptions
ilLDAPSynchronisationForbiddenException
ilLDAPAccountMigrationRequiredException

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

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

References getServer(), handleAccountMigration(), 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 295 of file class.ilLDAPUserSynchronisation.php.

296 {
297 $this->authmode = $a_auth_mode;
298 $this->server = ilLDAPServer::getInstanceByServerId($a_server_id);
299 }
static getInstanceByServerId($a_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 96 of file class.ilLDAPUserSynchronisation.php.

References $force_creation.

Referenced by handleCreation().

+ Here is the caller graph for this function:

◆ isUpdateRequired()

ilLDAPUserSynchronisation::isUpdateRequired ( )
protected

Check if an update is required.

Returns
bool

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

268 {
269 if(!$this->getInternalAccount())
270 {
271 return true;
272 }
273
274 // Check attribute mapping on login
275 include_once './Services/LDAP/classes/class.ilLDAPAttributeMapping.php';
276 if(ilLDAPAttributeMapping::hasRulesForUpdate($this->getServer()->getServerId()))
277 {
278 return true;
279 }
280
281 // Check if there is any change in role assignments
282 include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRule.php';
284 {
285 return true;
286 }
287 return false;
288 }
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(), and ilLDAPRoleAssignmentRule\hasRulesForUpdate().

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

205 {
206 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($this->getUserData(),true));
207
208 include_once './Services/User/classes/class.ilUserCreationContext.php';
210
211 include_once 'Services/LDAP/classes/class.ilLDAPAttributeToUser.php';
212 $update = new ilLDAPAttributeToUser($this->getServer());
213 $update->setNewUserAuthMode($this->getAuthMode());
214 $update->setUserData(
215 array(
216 $this->getExternalAccount() => $this->getUserData()
217 )
218 );
219 $update->refresh();
220
221 // User has been created, now read internal account again
222 $this->readInternalAccount();
223 return true;
224 }
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(), 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 251 of file class.ilLDAPUserSynchronisation.php.

252 {
253 if(!$this->getExternalAccount())
254 {
255 throw new UnexpectedValueException('No external account given.');
256 }
257 $this->intaccount = ilObjUser::_checkExternalAuthAccount(
258 $this->getAuthMode(),
259 $this->getExternalAccount()
260 );
261 }
static _checkExternalAuthAccount($a_auth, $a_account)
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 230 of file class.ilLDAPUserSynchronisation.php.

231 {
232 // Add internal account to user data
233 $this->user_data['ilInternalAccount'] = $this->getInternalAccount();
234
235 if(substr($this->getAuthMode(),0,4) == 'ldap')
236 {
237 return true;
238 }
239 include_once './Services/LDAP/classes/class.ilLDAPQuery.php';
240 $query = new ilLDAPQuery($this->getServer());
241 $user = $query->fetchUser($this->getExternalAccount());
242
243 $this->user_data = (array) $user[$this->getExternalAccount()];
244 }

References $query, getAuthMode(), getExternalAccount(), getInternalAccount(), 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 60 of file class.ilLDAPUserSynchronisation.php.

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

◆ setUserData()

ilLDAPUserSynchronisation::setUserData (   $a_data)

Set user data.

Parameters
array$a_data

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

115 {
116 $this->user_data = (array) $a_data;
117 }

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

126 {
127 $this->readInternalAccount();
128
129 if(!$this->getInternalAccount())
130 {
131 #$GLOBALS['ilLog']->write(__METHOD__.'Creating new account');
132 $this->handleCreation();
133 }
134
135 // Nothing to if sync on login is disabled
136 if(!$this->getServer()->enabledSyncOnLogin())
137 {
138 return $this->getInternalAccount();
139 }
140
141 // For performance reasons, check if (an update is required)
142 if($this->isUpdateRequired())
143 {
144 $this->readUserData();
145 $this->performUpdate();
146 }
147 return $this->getInternalAccount();
148 }
performUpdate()
Update user account and role assignments.
isUpdateRequired()
Check if an update is required.
handleCreation()
Handle creation of user accounts.

References getInternalAccount(), 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().

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