You are here

public function LdapAuthorizationConsumerDrupalRole::grantSingleAuthorization in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php \LdapAuthorizationConsumerDrupalRole::grantSingleAuthorization()
  2. 7.2 ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php \LdapAuthorizationConsumerDrupalRole::grantSingleAuthorization()

extends grantSingleAuthorization()

File

ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php, line 135

Class

LdapAuthorizationConsumerDrupalRole

Code

public function grantSingleAuthorization(&$user, $role_name, &$user_auth_data) {
  if (is_null($this
    ->getDrupalRoleByName($role_name))) {
    watchdog('ldap_authorization', 'LdapAuthorizationConsumerDrupalRole.grantSingleAuthorization()
        failed to grant %username the role %role_name because role does not exist', array(
      '%role_name' => $role_name,
      '%username' => $user->name,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  $new_roles = $user->roles + array(
    $this
      ->getDrupalRoleByName($role_name) => $role_name,
  );
  $user_edit = array(
    'roles' => $new_roles,
  );
  if ($this->detailedWatchdogLog) {
    watchdog('ldap_authorization', 'grantSingleAuthorization in drupal rold' . print_r($user, TRUE), array(), WATCHDOG_DEBUG);
  }
  $account = user_load($user->uid);
  $user = user_save($account, $user_edit);
  $result = $user && isset($user->roles[$this->drupalRolesByName[drupal_strtolower($role_name)]]);
  if ($this->detailedWatchdogLog) {
    watchdog('ldap_authorization', 'LdapAuthorizationConsumerDrupalRole.grantSingleAuthorization()
        granted: rid=%rid, role_name=%role_name for username=%username, result=%result', array(
      '%rid' => $this
        ->getDrupalRoleByName($role_name),
      '%role_name' => $role_name,
      '%username' => $user->name,
      '%result' => $result,
    ), WATCHDOG_DEBUG);
  }
  return $result;
}