You are here

function hook_ldap_user_roles_alter in LDAP integration 6

Allows the roles an ldap user will be assigned to be altered.

This hook is called after the mapping defined in the admin ui has been performed but before the user has been granted a role.

Parameters

Array $roles An array who's values are role names.:

Object $account The user object:

String $dn The user's ldap dn.:

Array $groups All of the user's ldap groups found:

Array $filtered_groups The user's groups after filtered by mapping rules.:

2 invocations of hook_ldap_user_roles_alter()
ldapgroups_user_login in ./ldapgroups.inc
Implements hook_user() login operation.
ldapgroups_user_test_output in ./ldapgroups.admin.inc
Generate the test results for the user and ldap settings.

File

./ldapgroups.api.php, line 40
LDAPGroups API function documentation

Code

function hook_ldap_user_roles_alter(&$roles, $account, $dn, $groups, $filtered_groups) {

  // Some example code to add a role if the user is in two groups
  if (in_array("cn=Joplin Fans,ou=Groups,dc=myorg", $groups) && in_array("cn=Morton Fans,ou=Groups,dc=myorg", $groups)) {
    if (!in_array("Ragtime", $roles)) {
      $roles[] = "Ragtime";
    }
  }
}