Here's a quick patch to make the CAS module interface with the LDAP integration module (in fact Ldapauth and Ldapgroups) : http://drupal.org/project/ldap_integration .

The LDAP mail attribute is defined in the CAS module settings, but that is temporary as the Ldapdata module (which will provide mapping between Drupal and LDAP attributes) will soon be included in the LDAP integration module.

I also allowed automatic account creation for CAS users, even if auto-registration is disabled in Drupal (see http://drupal.org/node/85163).

Comments

metzlerd’s picture

Status: Needs review » Needs work

Thanks for a great patch. Glad too see LDAP integration done in a nice optional way.

Regarding user registration, there are people out there who use this module in such a way that only users who are manually created in drupal can CAS_AUTH. They do this currently by turning off the ability of users to auto register. I didn't want to remove the ability to control who in a CAS domain could access a drupal site, but rather invent a setting to replace user_register. So that in rare cases, users could either register via user_login, or auto_register via cas.

So if you wouldn't mind rerolling this either without the removal of the user_register test, or with a new setting, then I think we're ready to commit.

This is a patch against head right? I do all my development there first.

metzlerd’s picture

I had another idea too. Don't feel obligated to try to code this, but I've been thinking that we may want to consider calling the group and/or email stuff via a hook (either inventing one or using one of the user hooks). That way other modules could control group/role membership without having to modify the SSO module all the time.

I've already coded some modules that find out membership based on rest web service calls.

Ideas on how to implement this?

deelight’s picture

I chose to bypass the user_register setting because I get an error if I try to log in a user who doesn't have a drupal account (user_register is disabled, cas_authmap false, cas_hijack_user true) :

* warning: array_keys() [function.array-keys]: The first argument should be an array in /web/drupal/modules/user/user.module on line 361.
* warning: implode() [function.implode]: Bad arguments. in /web/drupal/modules/user/user.module on line 361.
* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /web/drupal/includes/database.mysql.inc on line 172.

I worked on this problem, and I managed to solve like this :

Change :

     // try to log into Drupal
     if($cas_authmap) { // users are coming from Drupal; no need to use the external_load and the authmap
         $user = user_load(array("name" => $cas_name));
     } else {
         // users are external; use authmap table for associating external users
        $user = user_external_load($cas_name);
        if (!$user->uid && variable_get('cas_hijack_user',0))
        {
          $user = user_load(array("name" => $cas_name));
          if ($user->uid)
            user_set_authmaps($user,array('authname_cas' => $cas_name));
        }
     }

To :

     // try to log into Drupal
     if($cas_authmap) { // users are coming from Drupal; no need to use the external_load and the authmap
         $user = user_load(array("name" => $cas_name));
     } else {
         // users are external; use authmap table for associating external users
        $user = user_external_load($cas_name);
        if (!$user->uid && variable_get('cas_hijack_user',0))
        {
          $user = user_load(array("name" => $cas_name));
          if ($user->uid)
            user_set_authmaps($user,array('authname_cas' => $cas_name));
          else
          {
            session_destroy();
            $user = drupal_anonymous_user();
          }
        }
     }

As you can see, I forced the user to be considered as anonymous if there's no account to hijack and it now works well (it also still works if auto-registration is enabled). Without this, the $user variable was containing "0" at the end of the cas_init() function (if auto-registration was disabled), which I guess Drupal didn't like very much. I also called the session_destroy() function so that the CAS login is not kept in session (we can't log out of Drupal to flush it we're not logged in).

However, it might still confuse the user because there's no message telling him why he's not logged in on Drupal, and I didn't manage to display one.

This means that my little trick to force auto-registration is not needed anymore. Indeed, I think a cas_user_register setting (idenpendent from user_register) would be great, and I'm ready to implement it and generate a new patch (my previous patches were against the latest module stable release, but i'm now working with the HEAD revision).

Concerning the group/email stuff, I also think the best solution would be to call a hook instead of directly calling Ldapauth/Ldapgroup functions, but the LDAP integration module doesn't seem to be really "hookable" at the moment. It would be great we could just call some sort of update_user_data() and update_user_group_memberships() when needed, and Drupal would forward this to the right module (not necessarily the LDAP integration module), but I have no idea how it can be done at the moment.

deelight’s picture

StatusFileSize
new8.18 KB

Here's a new patch against the HEAD version (i moved a bit the drupal_anonymous_user() stuff I talked about before)

CHANGES :
- Added a cas_user_register parameter (drupal account creation upon successful CAS login, user_register independent)
- LDAP groups -> Drupal roles mapping (using ldapgroups module)
- Changed "cas settings" label to "CAS settings"
- User email LDAP extraction (using ldapauth module)
- "Login" string translation (wasn't encapsulated in t())
- No more error if user didn't have a Drupal account and auto-creation was disabled

deelight’s picture

StatusFileSize
new9.27 KB

Damn, I attached the wrong patch, sorry.

metzlerd’s picture

Status: Needs work » Fixed

Nice, Tested all but the LDAP config. Can't do this from home.

Committed in HEAD.

I'm working on a separate patch to add a cas logout menu item for hitting the cas URL. Once that is complete, I'll roll another release.

Thanks again,

Dave

Anonymous’s picture

Status: Fixed » Closed (fixed)