ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLDAPRoleGroupMapping Class Reference
+ Collaboration diagram for ilLDAPRoleGroupMapping:

Public Member Functions

 getInfoStrings (int $a_obj_id, bool $a_check_type=false)
 Get info string for object If check info type is enabled this function will check if the info string is visible in the repository. More...
 
 assign ($a_role_id, $a_usr_id)
 This method is typically called from class RbacAdmin::assignUser() It checks if there is a role mapping and if the user has auth mode LDAP After these checks the user is assigned to the LDAP group. More...
 
 deleteRole (int $a_role_id)
 Delete role. More...
 
 deassign ($a_role_id, $a_usr_id)
 This method is typically called from class RbacAdmin::deassignUser() It checks if there is a role mapping and if the user has auth mode LDAP After these checks the user is deassigned from the LDAP group. More...
 
 deleteUser ($a_usr_id)
 Delete user => deassign from all ldap groups. More...
 

Static Public Member Functions

static _getInstance ()
 Get singleton instance of this class. More...
 

Private Member Functions

 __construct ()
 Singleton contructor. More...
 
 initServers ()
 Check if there is any active server with. More...
 
 isHandledRole ($a_role_id)
 
 isHandledUser ($a_usr_id)
 Check if user is ldap user. More...
 
 assignToGroup ($a_role_id, $a_usr_id)
 Assign user to group. More...
 
 deassignFromGroup ($a_role_id, $a_usr_id)
 Deassign user from group. More...
 
 checkOtherMembership (int $a_usr_id, int $a_role_id, array $a_data)
 Check other membership. More...
 
 readDN (int $a_usr_id, int $a_server_id)
 Read DN of user. More...
 
 getLDAPQueryInstance ($a_server_id, $a_url)
 Get LDAPQueryInstance. More...
 

Private Attributes

ilLogger $log
 
ilRbacReview $rbacreview
 
ilObjectDataCache $ilObjDataCache
 
array $servers
 
array $mappings
 
array $mapping_members
 
array $mapping_info
 
array $mapping_info_strict
 
array $query
 
array $users
 
array $user_dns
 
bool $active_servers = false
 

Static Private Attributes

static ilLDAPRoleGroupMapping $instance = null
 

Detailed Description

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

Definition at line 24 of file class.ilLDAPRoleGroupMapping.php.

Constructor & Destructor Documentation

◆ __construct()

ilLDAPRoleGroupMapping::__construct ( )
private

Singleton contructor.

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

References $DIC, and initServers().

45  {
46  global $DIC;
47 
48  $this->log = $DIC->logger()->auth();
49  $this->rbacreview = $DIC->rbac()->review();
50  $this->ilObjDataCache = $DIC['ilObjDataCache'];
51 
52  $this->initServers();
53  }
initServers()
Check if there is any active server with.
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

static ilLDAPRoleGroupMapping::_getInstance ( )
static

Get singleton instance of this class.

Definition at line 58 of file class.ilLDAPRoleGroupMapping.php.

Referenced by ilRbacAdmin\assignUser(), ilRbacAdmin\assignUserLimited(), ilRbacAdmin\deassignUser(), ilObjUser\delete(), ilRbacAdmin\deleteRole(), and ilInfoScreenGUI\showLDAPRoleGroupMappingInfo().

59  {
60  if (is_object(self::$instance)) {
61  return self::$instance;
62  }
63  return self::$instance = new ilLDAPRoleGroupMapping();
64  }
+ Here is the caller graph for this function:

◆ assign()

ilLDAPRoleGroupMapping::assign (   $a_role_id,
  $a_usr_id 
)

This method is typically called from class RbacAdmin::assignUser() It checks if there is a role mapping and if the user has auth mode LDAP After these checks the user is assigned to the LDAP group.

Definition at line 97 of file class.ilLDAPRoleGroupMapping.php.

References assignToGroup(), isHandledRole(), and isHandledUser().

97  : bool
98  {
99  // return if there nothing to do
100  if (!$this->active_servers) {
101  return false;
102  }
103 
104  if (!$this->isHandledRole($a_role_id)) {
105  return false;
106  }
107  if (!$this->isHandledUser($a_usr_id)) {
108  $this->log->write('LDAP assign: User ID: ' . $a_usr_id . ' has no LDAP account');
109  return false;
110  }
111  $this->log->write('LDAP assign: User ID: ' . $a_usr_id . ' Role Id: ' . $a_role_id);
112  $this->assignToGroup($a_role_id, $a_usr_id);
113 
114  return true;
115  }
assignToGroup($a_role_id, $a_usr_id)
Assign user to group.
isHandledUser($a_usr_id)
Check if user is ldap user.
+ Here is the call graph for this function:

◆ assignToGroup()

ilLDAPRoleGroupMapping::assignToGroup (   $a_role_id,
  $a_usr_id 
)
private

Assign user to group.

Parameters
introle_id
intuser_id

Definition at line 245 of file class.ilLDAPRoleGroupMapping.php.

References $data, getLDAPQueryInstance(), and readDN().

Referenced by assign().

245  : void
246  {
247  foreach ($this->mappings[$a_role_id] as $data) {
248  try {
249  if ($data['isdn']) {
250  $external_account = $this->readDN($a_usr_id, $data['server_id']);
251  } else {
252  $external_account = $this->users[$a_usr_id];
253  }
254 
255  // Forcing modAdd since Active directory is too slow and i cannot check if a user is member or not.
256  #if($this->isMember($external_account,$data))
257  #{
258  # $this->log->write("LDAP assign: User already assigned to group '".$data['dn']."'");
259  #}
260  #else
261  {
262  // Add user
263  $query_obj = $this->getLDAPQueryInstance($data['server_id'], $data['url']);
264  $query_obj->modAdd($data['dn'], array($data['member'] => $external_account));
265  $this->log->write('LDAP assign: Assigned ' . $external_account . ' to group ' . $data['dn']);
266  }
267  } catch (ilLDAPQueryException $exc) {
268  $this->log->write($exc->getMessage());
269  // try next mapping
270  continue;
271  }
272  }
273  }
getLDAPQueryInstance($a_server_id, $a_url)
Get LDAPQueryInstance.
readDN(int $a_usr_id, int $a_server_id)
Read DN of user.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkOtherMembership()

ilLDAPRoleGroupMapping::checkOtherMembership ( int  $a_usr_id,
int  $a_role_id,
array  $a_data 
)
private

Check other membership.

Returns
string|false role name

Definition at line 330 of file class.ilLDAPRoleGroupMapping.php.

References $data.

Referenced by deassignFromGroup().

331  {
332  foreach ($this->mappings as $role_id => $tmp_data) {
333  foreach ($tmp_data as $data) {
334  if ($role_id === $a_role_id) {
335  continue;
336  }
337  if ($data['server_id'] !== $a_data['server_id']) {
338  continue;
339  }
340  if ($data['dn'] !== $a_data['dn']) {
341  continue;
342  }
343  if ($this->rbacreview->isAssigned($a_usr_id, $role_id)) {
344  return $this->ilObjDataCache->lookupTitle((int) $role_id);
345  }
346  }
347  }
348  return false;
349  }
+ Here is the caller graph for this function:

◆ deassign()

ilLDAPRoleGroupMapping::deassign (   $a_role_id,
  $a_usr_id 
)

This method is typically called from class RbacAdmin::deassignUser() It checks if there is a role mapping and if the user has auth mode LDAP After these checks the user is deassigned from the LDAP group.

Definition at line 148 of file class.ilLDAPRoleGroupMapping.php.

References deassignFromGroup(), isHandledRole(), and isHandledUser().

Referenced by deleteRole(), and deleteUser().

148  : bool
149  {
150  // return if there notzing to do
151  if (!$this->active_servers) {
152  return false;
153  }
154  if (!$this->isHandledRole($a_role_id)) {
155  return false;
156  }
157  if (!$this->isHandledUser($a_usr_id)) {
158  return false;
159  }
160  $this->log->write('LDAP deassign: User ID: ' . $a_usr_id . ' Role Id: ' . $a_role_id);
161  $this->deassignFromGroup($a_role_id, $a_usr_id);
162 
163  return true;
164  }
isHandledUser($a_usr_id)
Check if user is ldap user.
deassignFromGroup($a_role_id, $a_usr_id)
Deassign user from group.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deassignFromGroup()

ilLDAPRoleGroupMapping::deassignFromGroup (   $a_role_id,
  $a_usr_id 
)
private

Deassign user from group.

Parameters
introle_id
intuser_id

Definition at line 282 of file class.ilLDAPRoleGroupMapping.php.

References $data, checkOtherMembership(), getLDAPQueryInstance(), and readDN().

Referenced by deassign().

282  : void
283  {
284  foreach ($this->mappings[$a_role_id] as $data) {
285  try {
286  if ($data['isdn']) {
287  $external_account = $this->readDN($a_usr_id, $data['server_id']);
288  } else {
289  $external_account = $this->users[$a_usr_id];
290  }
291 
292  // Check for other role membership
293  if ($role_id = $this->checkOtherMembership($a_usr_id, $a_role_id, $data)) {
294  $this->log->write('LDAP deassign: User is still assigned to role "' . $role_id . '".');
295  continue;
296  }
297  /*
298  if(!$this->isMember($external_account,$data))
299  {
300  $this->log->write("LDAP deassign: User not assigned to group '".$data['dn']."'");
301  continue;
302  }
303  */
304  // Deassign user
305  $query_obj = $this->getLDAPQueryInstance($data['server_id'], $data['url']);
306  $query_obj->modDelete($data['dn'], array($data['member'] => $external_account));
307  $this->log->write('LDAP deassign: Deassigned ' . $external_account . ' from group ' . $data['dn']);
308 
309  // Delete from cache
310  if (is_array($this->mapping_members[$data['mapping_id']])) {
311  $key = array_search($external_account, $this->mapping_members[$data['mapping_id']], true);
312  if ($key || $key === 0) {
313  unset($this->mapping_members[$data['mapping_id']]);
314  }
315  }
316  } catch (ilLDAPQueryException $exc) {
317  $this->log->write($exc->getMessage());
318  // try next mapping
319  continue;
320  }
321  }
322  }
checkOtherMembership(int $a_usr_id, int $a_role_id, array $a_data)
Check other membership.
getLDAPQueryInstance($a_server_id, $a_url)
Get LDAPQueryInstance.
readDN(int $a_usr_id, int $a_server_id)
Read DN of user.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteRole()

ilLDAPRoleGroupMapping::deleteRole ( int  $a_role_id)

Delete role.

This function triggered from ilRbacAdmin::deleteRole It deassigns all user from the mapped ldap group.

Parameters
introle id

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

References deassign(), and isHandledRole().

125  : bool
126  {
127  // return if there nothing to do
128  if (!$this->active_servers) {
129  return false;
130  }
131 
132  if (!$this->isHandledRole($a_role_id)) {
133  return false;
134  }
135 
136  foreach ($this->rbacreview->assignedUsers($a_role_id) as $usr_id) {
137  $this->deassign($a_role_id, $usr_id);
138  }
139  return true;
140  }
deassign($a_role_id, $a_usr_id)
This method is typically called from class RbacAdmin::deassignUser() It checks if there is a role map...
+ Here is the call graph for this function:

◆ deleteUser()

ilLDAPRoleGroupMapping::deleteUser (   $a_usr_id)

Delete user => deassign from all ldap groups.

Parameters
intuser id

Definition at line 171 of file class.ilLDAPRoleGroupMapping.php.

References deassign().

171  : bool
172  {
173  if (!$this->active_servers) {
174  return false;
175  }
176 
177  foreach ($this->mappings as $role_id) {
178  $this->deassign($role_id, $a_usr_id);
179  }
180  return true;
181  }
deassign($a_role_id, $a_usr_id)
This method is typically called from class RbacAdmin::deassignUser() It checks if there is a role map...
+ Here is the call graph for this function:

◆ getInfoStrings()

ilLDAPRoleGroupMapping::getInfoStrings ( int  $a_obj_id,
bool  $a_check_type = false 
)

Get info string for object If check info type is enabled this function will check if the info string is visible in the repository.

Parameters
intobject id
boolcheck info type
Returns
string[]

Definition at line 74 of file class.ilLDAPRoleGroupMapping.php.

74  : array
75  {
76  if (!$this->active_servers) {
77  return [];
78  }
79 
80  if ($a_check_type) {
81  if (isset($this->mapping_info_strict[$a_obj_id]) && is_array($this->mapping_info_strict[$a_obj_id])) {
82  return $this->mapping_info_strict[$a_obj_id];
83  }
84  } elseif (isset($this->mapping_info[$a_obj_id]) && is_array($this->mapping_info[$a_obj_id])) {
85  return $this->mapping_info[$a_obj_id];
86  }
87 
88  return [];
89  }

◆ getLDAPQueryInstance()

ilLDAPRoleGroupMapping::getLDAPQueryInstance (   $a_server_id,
  $a_url 
)
private

Get LDAPQueryInstance.

Exceptions
ilLDAPQueryException

Definition at line 410 of file class.ilLDAPRoleGroupMapping.php.

References ilLDAPQuery\LDAP_BIND_ADMIN.

Referenced by assignToGroup(), deassignFromGroup(), and readDN().

411  {
412  if (array_key_exists($a_server_id, $this->query) &&
413  array_key_exists($a_url, $this->query[$a_server_id]) &&
414  is_object($this->query[$a_server_id][$a_url])) {
415  return $this->query[$a_server_id][$a_url];
416  }
417  $tmp_query = new ilLDAPQuery($this->servers[$a_server_id], $a_url);
418  $tmp_query->bind(ilLDAPQuery::LDAP_BIND_ADMIN);
419 
420  return $this->query[$a_server_id][$a_url] = $tmp_query;
421  }
+ Here is the caller graph for this function:

◆ initServers()

ilLDAPRoleGroupMapping::initServers ( )
private

Check if there is any active server with.

Definition at line 187 of file class.ilLDAPRoleGroupMapping.php.

References $data, ilObjUser\_getExternalAccountsByAuthMode(), ilLDAPServer\_getRoleSyncServerIds(), and ilLDAPRoleGroupMappingSettings\MAPPING_INFO_ALL.

Referenced by __construct().

187  : void
188  {
189  $server_ids = ilLDAPServer::_getRoleSyncServerIds();
190 
191  if (!count($server_ids)) {
192  return;
193  }
194 
195  // Init servers
196  $this->active_servers = true;
197  $this->servers = [];
198  $this->mappings = [];
199  foreach ($server_ids as $server_id) {
200  $this->servers[$server_id] = new ilLDAPServer($server_id);
201  $this->mappings = ilLDAPRoleGroupMappingSettings::_getAllActiveMappings();
202  }
203  $this->mapping_info = [];
204  $this->mapping_info_strict = [];
205  foreach ($this->mappings as $mapping) {
206  foreach ($mapping as $data) {
207  if ($data['info'] !== '' && $data['object_id']) {
208  $this->mapping_info[$data['object_id']][] = $data['info'];
209  }
210  if ($data['info'] !== '' && ($data['info_type'] === ilLDAPRoleGroupMappingSettings::MAPPING_INFO_ALL)) {
211  $this->mapping_info_strict[$data['object_id']][] = $data['info'];
212  }
213  }
214  }
215  $this->users = ilObjUser::_getExternalAccountsByAuthMode('ldap', true);
216  }
static _getExternalAccountsByAuthMode(string $a_auth_mode, bool $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
static _getRoleSyncServerIds()
Check whether there if there is an active server with option role_sync_active.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isHandledRole()

ilLDAPRoleGroupMapping::isHandledRole (   $a_role_id)
private
Parameters
int | string | null$a_role_id

Definition at line 221 of file class.ilLDAPRoleGroupMapping.php.

Referenced by assign(), deassign(), and deleteRole().

221  : bool
222  {
223  if (!is_string($a_role_id) || !is_int($a_role_id)) {
224  return false;
225  }
226 
227  return array_key_exists($a_role_id, $this->mappings);
228  }
+ Here is the caller graph for this function:

◆ isHandledUser()

ilLDAPRoleGroupMapping::isHandledUser (   $a_usr_id)
private

Check if user is ldap user.

Definition at line 233 of file class.ilLDAPRoleGroupMapping.php.

Referenced by assign(), and deassign().

233  : bool
234  {
235  return array_key_exists($a_usr_id, $this->users);
236  }
+ Here is the caller graph for this function:

◆ readDN()

ilLDAPRoleGroupMapping::readDN ( int  $a_usr_id,
int  $a_server_id 
)
private

Read DN of user.

Parameters
intuser id
intserver id
Exceptions
ilLDAPQueryException

Definition at line 358 of file class.ilLDAPRoleGroupMapping.php.

References $data, $res, $server, getLDAPQueryInstance(), and null.

Referenced by assignToGroup(), and deassignFromGroup().

359  {
360  if ($this->user_dns === null) {
361  $this->user_dns = [];
362  }
363  if (isset($this->user_dns[$a_usr_id])) {
364  return $this->user_dns[$a_usr_id];
365  }
366 
367  $external_account = $this->users[$a_usr_id];
368 
369  $server = $this->servers[$a_server_id];
370  $query_obj = $this->getLDAPQueryInstance($a_server_id, $server->getUrl());
371 
372  if ($search_base = $server->getSearchBase()) {
373  $search_base .= ',';
374  }
375  $search_base .= $server->getBaseDN();
376 
377  // try optional group user filter first
378  if ($server->isMembershipOptional() && $server->getGroupUserFilter()) {
379  $userFilter = $server->getGroupUserFilter();
380  } else {
381  $userFilter = $server->getFilter();
382  }
383 
384  $filter = sprintf(
385  '(&(%s=%s)%s)',
386  $server->getUserAttribute(),
387  $external_account,
388  $userFilter
389  );
390 
391  $res = $query_obj->query($search_base, $filter, $server->getUserScope(), array('dn'));
392 
393  if (!$res->numRows()) {
394  throw new ilLDAPQueryException(__METHOD__ . ' cannot find dn for user ' . $external_account);
395  }
396  if ($res->numRows() > 1) {
397  throw new ilLDAPQueryException(__METHOD__ . ' found multiple distinguished name for: ' . $external_account);
398  }
399 
400  $data = $res->get();
401  $this->user_dns[$a_usr_id] = $data['dn'];
402  return $this->user_dns[$a_usr_id];
403  }
$res
Definition: ltiservices.php:66
getLDAPQueryInstance($a_server_id, $a_url)
Get LDAPQueryInstance.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$server
Definition: shib_login.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $active_servers

bool ilLDAPRoleGroupMapping::$active_servers = false
private

Definition at line 39 of file class.ilLDAPRoleGroupMapping.php.

◆ $ilObjDataCache

ilObjectDataCache ilLDAPRoleGroupMapping::$ilObjDataCache
private

Definition at line 29 of file class.ilLDAPRoleGroupMapping.php.

◆ $instance

ilLDAPRoleGroupMapping ilLDAPRoleGroupMapping::$instance = null
staticprivate

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

◆ $log

ilLogger ilLDAPRoleGroupMapping::$log
private

Definition at line 27 of file class.ilLDAPRoleGroupMapping.php.

◆ $mapping_info

array ilLDAPRoleGroupMapping::$mapping_info
private

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

◆ $mapping_info_strict

array ilLDAPRoleGroupMapping::$mapping_info_strict
private

Definition at line 35 of file class.ilLDAPRoleGroupMapping.php.

◆ $mapping_members

array ilLDAPRoleGroupMapping::$mapping_members
private

Definition at line 33 of file class.ilLDAPRoleGroupMapping.php.

◆ $mappings

array ilLDAPRoleGroupMapping::$mappings
private

Definition at line 32 of file class.ilLDAPRoleGroupMapping.php.

◆ $query

array ilLDAPRoleGroupMapping::$query
private

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

◆ $rbacreview

ilRbacReview ilLDAPRoleGroupMapping::$rbacreview
private

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

◆ $servers

array ilLDAPRoleGroupMapping::$servers
private

Definition at line 31 of file class.ilLDAPRoleGroupMapping.php.

◆ $user_dns

array ilLDAPRoleGroupMapping::$user_dns
private

Definition at line 38 of file class.ilLDAPRoleGroupMapping.php.

◆ $users

array ilLDAPRoleGroupMapping::$users
private

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


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