The attached patch splits cas_logout() into two functions. The effect of calling cas_logout() is unchanged. The split creates a new function, cas_logout_do_logout(), which does the actual logout. This call be called from a hook_user_logout() implementation to ensure that all Drupal logouts cause a CAS logout.

This is a simple change that may help with the issues in #1018904: Remind users to log out of CAS after /logout.

Comments

bfroehle’s picture

+++ b/cas.moduleundefined
@@ -634,11 +634,26 @@ function cas_login_page($cas_first_login = FALSE) {
+ * This is safe to call from hook_user_logout() to ensure all Drupal logouts also logout CAS.

This is not technically safe to call from hook_user_logout(), as it does a drupal_goto() which will prevent later modules' hook_user_logout() from firing. :/

Not really sure if there is a way to get around this limitation.

liam morland’s picture

Yes, it would have to be called last. If I understand correctly, a module name far down the alphabet would be run later.

bfroehle’s picture

From module_list():

By default, modules are ordered by weight and module name.

In Drupal 7, we have hook_module_implements_alter() which could be used to move a particular implementation of hook_user_logout to the very end...

liam morland’s picture

Perhaps the "This is safe" comment should have a note about that. Or perhaps that comment should be removed, since it is just describing one possible use of the function.

bfroehle’s picture

Is the issue that we cannot call cas_logout from hook_user_logout because it'd become recursive? If this is the case, I think it'd be cleaner to have

function cas_logout($flag = TRUE) {
  // ...
  if ($flag) {
    module_invoke_all('user_logout', $user);
  }
  // ...
}

We'd have to choose an appropriate name for $flag, of course.

liam morland’s picture

StatusFileSize
new1.51 KB

Yes, as well, cas_logout() calls watchdog(). If that also went inside the if, that would work. Patch attached.

bfroehle’s picture

StatusFileSize
new1.46 KB

Thanks. I've attempted to clean up your patch to avoid extra noise and add some comments.

Out of curiosity, why is the watchdog message problematic?

liam morland’s picture

Title: Split cas_logout() » Allow cas_logout() to be called from hook_user_logout()

Thanks very much. That will do it.

Watchdog would be run twice if it is not inside the if statement.

bfroehle’s picture

Status: Needs review » Fixed

Committed to 6.x-3.x and 7.x-1.x. Thanks for the original patch!

Status: Fixed » Closed (fixed)

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

  • Commit 8377fd2 on 7.x-1.x, 8.x-1.x by bfroehle:
    Issue #1454682 by Liam Morland, bfroehle: Added Allow cas_logout() to be...