Handle logout hooks

Tuesday 30 November 2010 7:08:51 am

By : Jérôme Vieilledent

Sometimes you need to catch the user logout action, particularly when using an SSO.

Powerful login / poor logout features

eZ Publish has a powerful abstract authentication system. It means that you can virtually use any form of authentication through Login Handlers (LDAP handler is an implementation of it). It is even possible to authenticate an already-logged-in-user from an external application, through SSO Handlers (see my tutorial about SSO Handlers).

However, there is no "logout handler" system, so it is not currently possible to catch the logout process (eZ Publish version is 4.4 Fuji at the time of writing). That's a shame because it makes almost impossible to trigger an SSO logout for example.

This has been already logged as a feature request on issues.ez.no, but fortunately there is a workaround :).

The workaround

Digging into the kernel, I found that it was actually possible to configure the redirection on logout. By default, eZ Publish redirects to /user/login, as configured in site.ini.

Here's a code extract from kernel/user/logout.php (logout view of user module) :

$ini = eZINI::instance();
if ( $ini->variable( 'UserSettings', 'RedirectOnLogoutWithLastAccessURI' ) == 'enabled' && $http->hasSessionVariable( 'LastAccessesURI' ))
{
    $redirectURL = $http->sessionVariable( "LastAccessesURI" );
}
else
{
    $redirectURL = $http->postVariable( 'RedirectURI', $ini->variable( 'UserSettings', 'LogoutRedirect' ) );
}

return $Module->redirectTo( $redirectURL );

It means that if you don't use RedirectOnLogoutWithLastAccessURI, configured in site.ini, eZ Publish checks if a RedirectURI variable has been posted, and if not, takes the [UserSettings].LogoutRedirect in site.ini.

So the solution would consist in developing a module, let's say mysso/logout, and in configuring [UserSettings].LogoutRedirect to point on this module. In the logout view of this module, just do whatever you need to do to complete yout logout process and redirect the user to the homepage (this is an example).

Yes, sure it means one more HTTP 302 redirection, but well... This is IMHO the best solution until we have proper logout handlers and handleSSOLogout() in SSO handlers ;-). If you want such a feature, go vote for the associated request !

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 03:02:06
Script start
Timing: Jan 18 2025 03:02:06
Module start 'layout'
Timing: Jan 18 2025 03:02:06
Module start 'content'
Timing: Jan 18 2025 03:02:06
Module end 'content'
Timing: Jan 18 2025 03:02:06
Script end

Main resources:

Total runtime0.1198 sec
Peak memory usage6,144.0000 KB
Database Queries43

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0094 587.9141152.6250
Module start 'layout' 0.00940.0042 740.539139.4531
Module start 'content' 0.01360.1047 779.9922373.1641
Module end 'content' 0.11830.0014 1,153.156315.7031
Script end 0.1197  1,168.8594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00383.1387150.0003
Check MTime0.00121.0205150.0001
Mysql Total
Database connection0.00252.078910.0025
Mysqli_queries0.052944.1746430.0012
Looping result0.00030.2592410.0000
Template Total0.076764.120.0384
Template load0.00231.935420.0012
Template processing0.074462.125620.0372
Template load and register function0.00010.093610.0001
states
state_id_array0.00151.226410.0015
state_identifier_array0.00121.030320.0006
Override
Cache load0.00191.6145330.0001
Sytem overhead
Fetch class attribute name0.00312.604030.0010
class_abstraction
Instantiating content class attribute0.00000.008230.0000
General
dbfile0.00221.8205100.0002
String conversion0.00000.006640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplblog_entry/full.tplextension/community_design/design/suncana/override/templates/blog_entry/full.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/header.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/header.tplEdit templateOverride template
5content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
3content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezkeyword.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezkeyword.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 10

Time used to render debug report: 0.0001 secs