Using a SSO in eZ Publish

This kind of tools is quite common on the web; Google or MSN use it (one authentication for all their applications). Of course, there are many ways to interface with a SSO, depending on the CMS or on the framework you use. eZ Publish, since version 3.8, allows to develop SSO Handlers in a form of a plugin to authentication system. With this article, I will try to show you how it works.

Developping a SSO Handler

The principle of this kind of handler is quite simple, as you just need to develop, in an extension, a PHP class implementing handleSSOLogin() method. Please note that I assume you know how to develop a basic eZ Publish extension. If it's not the case, you may refer to this excellent article.

Handler declaration

In the settings/ folder of your extension (I'll name it jvsso), make an override of site.ini for your siteaccess. You can also make this override directly under settings/, that will make your SSO handler available for very siteaccesses of your eZ Publish instance.

In your site.ini.append.php override, make the following declaration :

<?php /* #?ini charset="utf-8"?

[UserSettings]
ExtensionDirectory[]=jvsso
SingleSignOnHandlerArray[]=Lolart

*/
?>

Here we declare that jvsso extension must be taken into account by eZ Publish authentication system, and that this extension contains a SingleSignOnHandler, called Lolart. Please note that the SSO handler name is contained in an array, which means that it is possible to declare several ones, successively called until an authentication succeeds (if you are curious, take a look at eZUser class - kernel/classes/datatypes/ezuser/ezuser.php - around line 1150 if you want to see how eZ Publish make these calls).

PHP class development

In your extension folder, create a sso_handler/ folder. This folder is aimed to contain the PHP class we'll develop. The name of the PHP file and the name of the class must follow the following specifications :

  • PHP file has to be named ez<handler_name_lowercase>ssohandler.php. It gives : ezlolartssohandler.php
  • PHP class has to be named eZ<handler_name>SSOHandler, which gives eZLolartSSOHandler.

Our PHP class must at least implement handleSSOLogin() method. This method must return a valid eZ Publish user (eZUser object) or false if it fails.

<?php
    class eZLolartSSOHandler
    {
        public function __construct()
        {
         // Here you can make initialization stuffs for your handler
        }

        /**
         * Return a eZUser PHP object to be logged in eZ Publish
         * If authentication fails, just return false
         */
        public function handleSSOLogin()
        {
            $currentUser = false; // Default falue that we return if authentication fails.
            
            // Here you can do everything you need to identify your user (interface with SSO, search the SSO database...)
            // In all cases, you must return a valid eZ Publish user or false
            // User must be created if needed
            
            return $currentUser;
        }
    }

Et voilĂ  ! Now we just have to activate our extension and clear our INI caches !

French translation of this article on the original author's blog.

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 02:19:21
Script start
Timing: Jan 18 2025 02:19:21
Module start 'layout'
Timing: Jan 18 2025 02:19:21
Module start 'content'
Timing: Jan 18 2025 02:19:21
Module end 'content'
Timing: Jan 18 2025 02:19:21
Script end

Main resources:

Total runtime0.0674 sec
Peak memory usage2,048.0000 KB
Database Queries24

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 587.9141152.6250
Module start 'layout' 0.00530.0040 740.539139.4453
Module start 'content' 0.00920.0570 779.9844453.0234
Module end 'content' 0.06630.0011 1,233.00788.8516
Script end 0.0674  1,241.8594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00314.5972150.0002
Check MTime0.00131.8941150.0001
Mysql Total
Database connection0.00081.142210.0008
Mysqli_queries0.024736.5687240.0010
Looping result0.00020.3204220.0000
Template Total0.035152.120.0176
Template load0.00213.071620.0010
Template processing0.033048.995720.0165
Template load and register function0.00010.161610.0001
states
state_id_array0.00060.869210.0006
state_identifier_array0.00101.457720.0005
Override
Cache load0.00182.7269450.0000
Sytem overhead
Fetch class attribute name0.00081.220710.0008
class_abstraction
Instantiating content class attribute0.00000.007410.0000
General
dbfile0.00091.3024100.0001
String conversion0.00000.014940.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.tplfull/article.tplextension/sevenx/design/simple/override/templates/full/article.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
9content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
6content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/header.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/header.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 39
 Number of unique templates used: 11

Time used to render debug report: 0.0001 secs