Closed (fixed)
Project:
CAS
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Feb 2011 at 23:46 UTC
Updated:
7 Jun 2014 at 20:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
bfroehle commentedI'd like to hammer this out as well. If we can establish the desired behavior, I can implement this using some test driven development (via #1011848: Add Testing Routines).
Here's what I think we'd need to test for:
cas:useroruser/login:In general, I guess the code flow should be this:
This is pretty similar to what already exists...
What sort of change did you have in mind?
Comment #2
bfroehle commentedCurrently in cas_save_page() we never overwrite $_SESSION['cas_goto']. This means that if we are on page A, click on a link to authenticate, change our minds and go back, navigate to page B, click on a link to authenticate, and log in, we'll be redirected back to A.
A more robust check might be to set $_SESSION['cas_goto'] only if $_GET['ticket'] is not present.
Comment #3
metzlerd commentedI'm wondering if we can rip out all of the cas save page logic. That was what I was going to try next. If phpCAS is managing this, and we have "destination" support for the login screens, maybe that is enough? I wasn't sure if we should be holding up release for this though.
Comment #4
bfroehle commentedYes, this all sounds good to me.
Comment #5
bfroehle commentedAs noted in #1011848-5: Add Testing Routines, several login redirection tests are failing.
Comment #6
bfroehle commentedHere's the 7.x-1.x code for
cas_save_page():If I'm reading this right, 'cas_goto' will never be saved as it is by default empty so the first if statement will never evaluate to TRUE....
Comment #7
bfroehle commentedFeeling a little confident with the CAS test routines, I have attached a patch which rips out the cas_goto code completely.
The login mechanism works like this:
- A user visits a CAS protected page or clicks on the 'CAS login' link.
- We look to see if $_REQUEST['destination'] is already set. If so, we keep it. If not, we generate the destination by looking for the HTTP Referrer (if provided) or by defaulting on the site frontpage.
- We set the phpCAS service URL (that is, the URL the CAS server returns to after login, to http://example.com/cas?destination=....
- We use drupal_goto to redirect to the destination provided in the URL.
Weaknesses:
- drupal_goto in D6 (but not D7, I think) will not allow redirecting to external URLs using the destination parameter. So in cas_login_destination(), we have to convert the HTTP Referrer URI to its Drupal path. This is non-trivial, and the attached code, likely does not account for a few edge cases (like SSL sites, for example).
Comment #8
bfroehle commentedTriggering the test bot.
Comment #9
bfroehle commentedAnd it failed.
Comment #10
bfroehle commentedI've rethought out the login destination logic, and present the following patch for 7.x-1.x
(1): We use hook_menu_link_alter() and hook_translated_menu_link_alter() to set the destination query string on all CAS login/logout links. This means that the links turn into things like "/cas?destination=node/5"
(2): The cas_phpcas_init() routine sets the "service URL" -- that is, the URL to return to after the user logs in with CAS to 'http://.../cas?destination=node/5'. After logging in, we use drupal_goto() to automatically redirect to the specified destination.
(3): This allows us to completely remove all $SESSION['cas_goto'] logic and the entire cas_save_page() function.
This is reasonably well tested for basic configurations, but I haven't tested the interaction with CAS gateway ('check to see if the user is already logged in') or with cas_pages ('Require CAS login for specific pages').
Comment #11
bfroehle commentedHere's the 6.x-3.x port of the patch in #10.
Comment #12
bfroehle commentedOne issue is that the necessary changes to the menu items ("CAS Login" and "CAS Logout") won't be picked up unless the menu item is deliberately resaved. (i.e., resetting the cache is insufficient).
That is, for testing you will need to visit Admin > Site Building > Menus > ... > CAS Login (edit) and choose "Save." Ditto for "CAS Logout."
Eventually we'll need to provide a cas_update_6304() that does:
Comment #13
bfroehle commentedAdded the cas_update_6305() function in 7.x-1.x. Working on writing tests for CAS gateway and cas_pages before I commit this.
Comment #14
bfroehle commentedRerolled the patch in #13 to account for additional tests (single sign out, and gateway).
Comment #15
bfroehle commentedI've done some pretty thorough testing and have committed this to 6.x-3.x and 7.x-1.x. There might be a few remaining bugs, but overall I think it is pretty solid.