I'll give a little info about my setup before I go into depth about the bug

I have my CAS set up in the following way:

  • Make CAS login default on login forms
  • CAS login only
  • "Automatically create Drupal accounts" is disabled (therefore, I have drupal accounts for each "authorized" CAS user
  • Require CAS login for: all pages except specific pages

Here's my scenario/bug:

When a user logs in with an CAS username that DOES NOT have a Drupal account associated with it, it provides the error message "No account found for username" for every user, and it basically locks everyone out until I log in with a non-CAS account and clear the sites caches.

Comments

bfroehle’s picture

What is your cache/performance settings? Are you using varnish or anything like that?

bfroehle’s picture

Version: 6.x-3.0 » 6.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new753 bytes

If the attached patch passes the test bot, can you give it a try?

Status: Needs review » Needs work

The last submitted patch, 1259212-cas_boot-2.patch, failed testing.

bfroehle’s picture

Okay, so this approach won't work.

In the mean while I'd suggest turning caching off, if you can afford to do that.

bfroehle’s picture

Status: Needs work » Needs review
StatusFileSize
new455 bytes

Okay, here's another approach.

Status: Needs review » Needs work

The last submitted patch, 1259212-cas_cache-5.patch, failed testing.

bfroehle’s picture

Status: Needs work » Needs review
StatusFileSize
new389 bytes

Bah! Maybe I should actually test these ideas out.

nick123pig’s picture

My caching mode is normal, Page compression is enabled, CSS and Javascript optimization is enabled. I am not using varnish or anything like that.

bfroehle’s picture

Can you try out two different things:
(1): Turn cache mode to off.
(2): Try the patch in #7.

Please report back if either (or both) resolve your issue.

bfroehle’s picture

Status: Needs review » Postponed (maintainer needs more info)
bfroehle’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Marking as cannot reproduce since nobody else has reported this and the original poster has not responded with any new debugging information in 6 months.

calphoz’s picture

Version: 6.x-3.x-dev » 7.x-1.1
Status: Closed (cannot reproduce) » Needs work

I'm seeing this problem on version 7.x-1.1 as well. I do not think it is a drupal cache issue.

I have a page that requires cas, let say a page with url alias "login".

This page is set to require cas.
The problem exist only if "Automatically create Drupal accounts" is disabled.

When you first access this page, you're require to login with cas.
Login with a cas account that is not already in the drupal.

You'll receive a message stating that there is no account for that user, this is expected since automatically create account is turned off and this user is not in the drupal user table. Now logout of cas.

Go visit the same login page again, you should be presented with the cas login page again since you've logged out of cas but you're not. Somehow it continue to pickup the cas user id of your previous login, even after logging out of cas, and present you with the same "no account for that user" message.

I cleared the drupal cache, logged in from another computer, and refresh the login page on the computer that i'm testing this on but the message stays.

The message does go away when i clear the browser cache, specifically the cookie, and it give me the cas login screen again. Something is saved in the cookies and the previous cas user(the one without access to the drupal site) is being pickup automatically, even if you logout of cas.

When "Automatically create Drupal accounts" is disabled, and a cas user successfully login with cas but do not have an account on the drupal site, it should clear out its cookie or just not add anything to the cookie.

bfroehle’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new669 bytes

Hmm, sounds like a phpCAS session is persisting throughout the request. This should be easy to check...

Status: Needs review » Needs work

The last submitted patch, 1259212-13-test-only.patch, failed testing.

bfroehle’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB

This time with a potential fix.

bkosborne’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.12 KB

I was able to reproduce and the path addresses it. Makes sense - we need to remove the CAS session data if we reject the otherwise valid CAS login data.

Patch no longer applied, here's a new one.

bkosborne’s picture

For what it's worth, I'm pretty confused on the original request. The patch fixes what was described in #12, but the original request seems to imply some weird thing with caching happening (since ALL users were locked out). I don't see how that's possible, since when drupal_set_message() is called, the result of the page will NOT be cached.

I suggest that we get the patch in, consider this fixed, and have the OP re-open the ticket or new issue if still relevant afterwards.

yalet’s picture

Patch works for me, and I agree with #17.

bkosborne’s picture

Status: Reviewed & tested by the community » Fixed

Committed

  • Commit 1c414cb on 7.x-1.x:
    Issue #1259212 by bfroehle, bkosborne | nick123pig: Required CAS login...
bkosborne’s picture

(Note, I neglected to attribute authorship to @bfroehle on this. Sorry about that, will look out in the future)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

  • Commit 1c414cb on 7.x-1.x, 8.x-1.x:
    Issue #1259212 by bfroehle, bkosborne | nick123pig: Required CAS login...
emsearcy’s picture

StatusFileSize
new1.92 KB

This same problem still exists for a couple other cases where this function escapes out but leaves the phpCAS isSessionAuthenticated() info in place. Specifically, we were routinely hitting this for users without CAS associations (uid 1 admin wasn't linked to the client site uid 1 admin, and IT staff inadvertantly logged in as admin on cas_server would lock themselves out of CAS on the client even if they changed their cas_server user). But I believe the same applies for access checks or other modules blocking login.

Also, I think the prior patch (which was released in 1.4) should be unsetting $_SESSION['phpCAS']['user'] not the whole phpCAS array. In particular, this allows keeping the once-per-session gateway behavior. If an attempted gateway login fails and the user stays anonymous, the expected behavior for me with "once per session" would be to give up on gateway logins, not re-try every page request. Presumably any site with a gateway login also has an explicit login, which will still work because with $_SESSION['phpCAS']['user'] unset, isSessionAuthenticated fails and a forced login is attempted.

I believe $user = drupal_anonymous_user(); is not needed for these other instances because the user has not been overridden. If somebody could check my logic here I'd appreciate it.

EDIT: please disregard attached patch, fixed patch is below phpcas-user-unsets-1259212.patch

emsearcy’s picture

Status: Closed (fixed) » Needs review
emsearcy’s picture

emsearcy’s picture

StatusFileSize
new1.87 KB

Fixing typo in previous patch.

  • 1c414cb committed on 8.x-1.x-PROXY
    Issue #1259212 by bfroehle, bkosborne | nick123pig: Required CAS login...
bkosborne’s picture

Status: Needs review » Fixed

Looks like this issue was never closed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.