Hello all,

I've been using CAS on my site for a little while now successfully. I have the "Automatically create Drupal accounts" setting checked which is working good.

Now I'm trying to import some users using the User Import module which also works good.

THE PROBLEM
If I'm importing users who will also be using the CAS login, when they try to login they get this error message..."A new account could not be created for . The username is already in use on this site."

It seems like CAS is trying to create the username when it already exists. Is it possible to put a check in so that if the username already exists and has the proper @domain.com email address for a CAS login it will let the person login via CAS?

I'm basically trying to import a bunch of CAS users and assign them a role using the User Import module. Which again works fine, it's just that now CAS won't let them login using the CAS login even though they have the correct @domain.com email address.

Thanks for reading,
-Tim

Comments

TimG1’s picture

Hello again,

So it seems that the import module doesn't add the "cas username" to the user account. So, I need to figure out how to do that. I'm guessing that this is the problem and if I can figure this out then this won't be an issue.

-Tim

TimG1’s picture

Hi again,

I thought maybe I could get around this by adding a Views Bulk Operation to copy the username field to the cas username field using a token after my initial import. But it doesn't seem that Views Bulk Operations has access to modify the cas username field.

-Tim

TimG1’s picture

Title: A new account could not be created for <username>. The username is already in use on this site. » Integrate with User Import module.

Me again,

Well I think I have a work around figured out.

  1. Import users using import user module
  2. Make a view of Users and use the "Execute arbitrary PHP" operation in Views Bulk Operation.
  3. Use this as the "arbitrary PHP" to execute.
    db_insert('cas_user')
    ->fields(array(
      'cas_name' => $entity->name,
      'uid' => $entity->uid
    ))
    ->execute();

The above seems to be working okay so far. Does anyone know if there is anything else I should be updating/doing in my PHP in step 3?

Leaving this open and changing the title.

Many thanks,
-Tim

bfroehle’s picture

Hi TimG1:

It sounds like you figured it out!

As you discovered, the key is the {cas_user} table which maps CAS usernames to Drupal user IDs.

Another good way to populate the {cas_user} table is with a bulk SQL command. For example (as taken from the comments in cas.install):

    // Create a mapping in {cas_user} for each current Drupal user.
    //   INSERT INTO cas_user (uid, cas_name)
    //   SELECT u.uid AS uid, u.name as cas_name
    //   FROM users u
    //   WHERE uid <> 0 AND NOT EXISTS (SELECT cas_name FROM cas_user c WHERE c.cas_name = u.name);
bkosborne’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Sounds like the real feature request here is the ability to automatically associate existing users with CAS users. Seems like sort of an edge case that can be solved by just running a query like above. Otherwise, I think it would be best to have someone who wants that to open a new feature request for it.

kcolwell’s picture

Happy to see these examples of how to get this to work if you already have users.

I'm in the process of switching from just using ldap logins to using CAS and it would have been really cool if this had been some kind of option on install or a configuration option.

Thanks,
Ken Colwell