===========================================
Pluggable Authentication Service for Xoops2
===========================================
1. Introduction
---------------
Just like XOOPS templates are a great way to personnalize XOOPS installations, Authentication Service mechanism aims to provide the same level of flexibility for the XOOPS authentication process. This hack only deal with authentication and NOT with authorisation (modules, function or page ACLs for instance)
Simply said, for each authentication mechanism you want to support, you have to write one and only one file with an implementation of the following methods (see sample implementations for more details):
function &loginUser($uname, $pwd)
function &loginUserMd5($uname, $pwd)
function logoutUser()
function loginPage()
function checkLogin()
Save this file under /include/authentication_services/, reference it in mainfile.php and apply the hack to system files (cfr. section "How to use the apply the hack")
I provide 3 different implementations:
1. The standard XOOPS implementation
2. LDAP implementation: user are authenticated against a standard LDAP directory and stored in the XOOPS DB. User's data are updated at each new user authentication
3. Central Authentication Service (CAS -
http://www.yale.edu/tp/auth/) from the Yale University. One of the most clever and secure way to authenticate users of Web applications. It requires a running CAS server
The LDAP implementation could be very easily adapted to suit your specifics needs (LDAP structure/fields) and could even be used to authenticate users against Microsoft Active Directory.
IMHO this hack would deserve to be included in the next XOOPS (even minor) release
It would allow to upgrade XOOPS without to have to re-apply authentication hacks everytime... Minus hack = smooth upgrades...
2. What has been done ?
-----------------------
4 new Files
/kernel/authenticationservice.php
/include/authenticationservices/xoops.php
/include/authenticationservices/ldap.php
/include/authenticationservices/cas.php
4 modified System files
/mainfile.php
/user.php
/kernel/member.php
/include/common.php
Click here to get the files3. How to apply the hack ?
--------------------------
1. Copy the 4 new files (+ 1 new directory) to their final destination (on Unix/Linux, make sure that the new directory is accessible => chmod o+x authenticationservices/ )
2. Add the following line to /mainfile.php
define('XOOPS_AUTHENTICATION_SERVICE', 'xoops');
Note: later you simply have to replace 'xoops' by 'ldap', 'cas' or 'my_own_implementation' to dynamically switch the Authentication Service
3. Modify the three following "if" statement in /user.php
if ($op == 'main') {
if ( !$xoopsUser ) {
$authentication_service =& xoops_gethandler('authenticationservice');
$authentication_service->loginPage();
} elseif ( $xoopsUser ) {
header('Location: '.XOOPS_URL.'/userinfo.php?uid='.$xoopsUser->getVar('uid'));
}
exit();
}
if ($op == 'login') {
$authentication_service =& xoops_gethandler('authenticationservice');
$authentication_service->checkLogin();
exit();
}
if ($op == 'logout') {
$authentication_service =& xoops_gethandler('authenticationservice');
$authentication_service->logoutUser();
}
4. Modify /include/common.php
- Add the following line to auto-login code (around line 165)
// $authentication_service =& xoops_gethandler('authenticationservice');
- Modify this line in the auto-login code (around line 167)
// $user =& $authentication_service->loginUserMd5(addslashes($uname), addslashes($pass));
- Modify the elseif condition around line 215
} elseif (!empty($_POST['xoops_login'])) {
$authentication_service =& xoops_gethandler('authenticationservice');
$authentication_service->checkLogin();
exit();
}
5. (Optional) Delete the 2 following functions in /kernel/member.php (XoopsMemberHandler class)
function &loginUser($uname, $md5pwd) (standard XOOPS login function)
function &loginUserMd5($uname, $md5pwd) (used only by the auto-login feature)
6. (Optional) Delete the following system file
/include/checklogin.php
4. Current problems
-------------------
The only problem known today is related to the CAS Authentication Service when the XOOPS site is turned off: it prevents all users to login ! But I am confident: I should quickly find a solution. The problem could be partly due to our CAS server implementation. In fact I do already have a dirty work-around... Modify the elseif condition around line 215 in /include/common.php to match
} elseif (!empty($_REQUEST['xoops_login']) || !empty($_REQUEST['ticket'])) {
But this is really dirty since specific code to CAS service is added to generic code
5. Conclusion
-------------
This hack has been developed (I think/hope) in the "Xoops way of doing things" and with the KISS principle in mind (Keep It Simple Stupid). It does exactly what is supposed to do, not more, not less.
It is very flexible and you could imagine a lot of combination to authenticate your users: from another database, another corporate security&identy management system, https login page (alternative to the current option), etc.
And you can simply fall back to a working solution in less than 5 seconds in case of trouble by modifying your mainfile.php
Furthermore: it works ! I have been using it (the 3 implementations) for about one week on my production sites (about 100 users authenticate daily), without any trouble.
I hope you will find it useful.
Benoit
benoit.mercier@users.sourceforge.net