You are here

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

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

extends grantSingleAuthorization()

Overrides LdapAuthorizationConsumerAbstract::grantSingleAuthorization

File

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

Class

LdapAuthorizationConsumerDrupalRole

Code

public function grantSingleAuthorization(&$user, $consumer_id, $consumer, &$user_auth_data, $user_save = FALSE, $reset = FALSE) {
  $role_name_lcase = $consumer_id;
  $role_name = empty($consumer['value']) ? $consumer_id : $consumer['value'];
  $rid = $this
    ->getDrupalRoleIdFromRoleName($role_name);
  if (is_null($rid)) {
    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;
  }
  $user->roles[$rid] = $role_name;
  $user_edit = array(
    'roles' => $user->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 && !empty($user->roles[$rid]);
  if ($this->detailedWatchdogLog) {
    watchdog('ldap_authorization', 'LdapAuthorizationConsumerDrupalRole.grantSingleAuthorization()
        granted: rid=%rid, role_name=%role_name for username=%username, result=%result', array(
      '%rid' => $rid,
      '%role_name' => $role_name,
      '%username' => $user->name,
      '%result' => $result,
    ), WATCHDOG_DEBUG);
  }
  return $result;
}