You are here

function shib_auth_save_roles in Shibboleth Authentication 7.4

Same name and namespace in other branches
  1. 6.4 shib_auth.module \shib_auth_save_roles()

Saves changes to users' roles.

Unfortunately if we called user_save() on updating roles, we would possibly lose profile fields. Therefore we hack with the {users_roles} table.

1 call to shib_auth_save_roles()
shib_auth_assignroles in ./shib_auth.module
Defines authorization rules for assigning roles to users.

File

./shib_auth.module, line 1376
Drupal Shibboleth authentication module.

Code

function shib_auth_save_roles() {
  global $user;

  // We won't modify system users.
  if ($user->uid <= 1) {
    return;
  }
  if (isset($user->roles)) {
    db_delete('users_roles')
      ->condition('uid', $user->uid)
      ->execute();
    foreach (array_keys($user->roles) as $rid) {
      if (!in_array($rid, array(
        DRUPAL_ANONYMOUS_RID,
        DRUPAL_AUTHENTICATED_RID,
      ))) {
        db_insert('users_roles')
          ->fields(array(
          'uid' => $user->uid,
          'rid' => $rid,
        ))
          ->execute();
      }
    }
  }
}