Problem/Motivation
Currently, the CAS module does not have a route requirement _user_is_logged_in: 'FALSE'. So if there is log in menu link that uses cas.login route, the link still be visible even if user is logged in. This causes confusion.
Proposed resolution
To address this issue, a condition "_user_is_logged_in" should be added to the cas.login router. This should effectively prevent access to the route for users that are already logged in.
Remaining tasks
User interface changes
Change Record Snippet
Authenticated users no longer have access to the /cas or /caslogin routes. This was done so that menu links to these paths (e.g., for a "log in" link) don't show up for already logged in users. This matches the behavior of login routes of core (/user/login) and other SSO contrib modules like simpleSAMLphp Authentication and SAML Authentication.
However, authenticated users that visit /cas or /caslogin will not be shown an access denied page. Instead, they'll be redirected to the homepage. If a destination parameter was present on the link (e.g., /cas?destination=/some/page), they'll be redirected to that destination instead.
Note that this also means that already authenticated users can no longer use /cas or /caslogin to re-authenticate their session with the CAS server. They must first log out then log back in again.
Issue fork cas-3446948
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3446948-prevent-auth-cas-login-route
changes, plain diff MR !37
- 2.x
changes, plain diff MR !32
Comments
Comment #2
Jaspreet Longia commentedComment #3
Jaspreet Longia commentedComment #4
Jaspreet Longia commentedComment #6
bkosborneGoing to make a new branch because this one was created with branch name 2.x and it's making it harder to review locally (I already have a branch with that name)
Comment #9
bkosborneRather than just issue an access denied error when an authenticated user accesses /cas to login, the merge request now redirects them to the homepage. This is the same behavior as if they did have a successful login via /cas. So users basically shouldn't notice any difference, other than they are not redirected to the CAS server to re-login again anymore. I think this makes the best UX. Someone may have /cas bookmarked and if they still have an active session, showing them an Access Denied error would be confusing. Just redirect them to the homepage as if they had logged in.
This is similar to what core does when an authenticated user tries accessing /user/login. It redirects them to the user profile page instead of showing an access denied.
Comment #10
bkosborneComment #11
bkosborneThanks for the review. I'll see about extending that base class!
Another thing I want to try and resolve here is this scenario:
We have at least one site that's using this workflow for links that this patch breaks.
Comment #12
claudiu.cristeaGiven #3463607: AccessDeniedSubscriber should extend HttpExceptionSubscriberBase is RTBC and most likely will me merged, I think we should do it also here.
i think #11 makes sense
Comment #13
bkosbornePushed an update that uses HttpExceptionSubscriberBase and preserves the destination parameter. Updated issue summary to describe the change.
Comment #14
bkosborneComment #15
bkosborneComment #16
bkosborneComment #17
bkosborneUpdated the MR to be based on 3.x
Comment #18
claudiu.cristeaUnfortunately tests are failing
Comment #19
bkosborneFixed the broken test
Comment #20
claudiu.cristeaGreat. You can merge and release 3.0.0.
I propose the following release notes:
Comment #22
bkosborne