Extension talk:SSL authentication

Working on integrating this into the LDAP Authentication plugin
This plugin is great, and exactly what I was looking for. I'll be integrating this into my LDAP Authentication plugin. I've been looking for documentation on how to do this for the past couple of weeks, but this plugin fits my need perfectly.

Thanks for the great work!

-- Ryan Lane

Little bug
Great work :), but when I enter my site first time in browsers session - I am not logged. The problem is probably in file SSLAuthPlugin.php in function SSLAuth:

SEARCH: //If exists, log them in   if($tmpuser->getID != 0) {       $wgUser = &$tmpuser; $wgUser->setCookies; $wgUser->setupSession; return; } REPLACE WITH: //If exists, log them in   if($tmpuser->getID != 0) {       $wgUser = &$tmpuser; $wgUser->setupSession; // Before cookies! $wgUser->setCookies; return; }

-- Krzysztof Kozlowski

tested with mediawiki 1.9?
Anyone else tried this out? I'm having a hell of a time getting it to work out.

Re - MediaWiki 1.9
Tested, but following changes were needed in SSLAuthPlugin.php: FIND: $tmpuser = User::LoadFromSession; REPLACE WITH: $tmpuser = new User ; $tmpuser->LoadFromSession; FIND: $tmpuser = User::newFromName($ssl_UN); REPLACE WITH: unset($tmpuser) ; $tmpuser = new User ; $tmpuser = $tmpuser->newFromName($ssl_UN);

And works OK

-- Krzysztof Kozlowski (kozik [some special char] kozik.net.pl)

1.9 better, but new error
Original exception: exception 'MWException' with message 'Unstub loop detected on call of $wgUser->getOption from StubUserLang::_newObject ' in /var/www/wiki/includes/StubObject.php:54

Note: Tested with 1.9.3
Succeded in integrating SSL authentication with the following SSLAuthPlugin.php:

<?php /** * Version 1.0.2 (Works out of box with MW 1.7.1 and up) * * Authentication Plugin for Apache2 mod_ssl * Derived from AuthPlugin.php and * http://meta.wikimedia.org/wiki/Shibboleth_Authentication * * Much of the commenting comes straight from AuthPlugin.php * * Portions Copyright 2006 Martin Johnson * Portions Copyright 2006, 2007 Regents of the University of California * Portions Copyright 2007 Steven Langenaken * Released under the GNU General Public License * * Changes between 1.0.2 and 1.0.1: * = Merge changes from Shibboleth Authentication: (By DJC) * == More 1.9 compatibility fixes and less ugly code * * Changes between 1.0.1 and 1.0: * = Merge changes from Shibboleth Authentication: (By DJC) * == Compatible with MW 1.9+ again (By DJC) * == Minor fix in loginform handling (By Steven Langenaken) * * Documentation at http://www.mediawiki.org/wiki/Extension:SSL_authentication */ require_once('AuthPlugin.php'); class SSLAuthPlugin extends AuthPlugin { /**     * See AuthPlugin.php for specific information */    function userExists( $username ) { return true; }    /**      * See AuthPlugin.php for specific information */    function authenticate( $username, $password ) { global $ssl_UN; if($username == $ssl_UN) return true; else return false; }    /**      * See AuthPlugin.php for specific information */    function modifyUITemplate( &$template ) { $template->set( 'usedomain', false ); }    /**      * See AuthPlugin.php for specific information */    function setDomain( $domain ) { $this->domain = $domain; }    /**      * See AuthPlugin.php for specific information */    function validDomain( $domain ) { return true; }    /**      * See AuthPlugin.php for specific information */    function updateUser( &$user ) { global $ssl_map_info; global $ssl_email; global $ssl_RN; //Map extra info or not? if($ssl_map_info != true) {                    //If Email, set info in MW             if($ssl_email != null) $user->setEmail($ssl_email); //If realName, set info in MW            if($ssl_RN != null) $user->setRealName($ssl_RN); }       //For security, set password to a non-existant hash. $user->load; if($user->mPassword != "nologin") {           $user->mPassword = "nologin"; $user->saveSettings; }        return true; }    /**      * See AuthPlugin.php for specific information */    function autoCreate { return true; }    /**      * See AuthPlugin.php for specific information */   //function allowPasswordChange { //   return false; //}

function allowPasswordChange { return true; // KK - bug: password-change-forbidden }

/**     * See AuthPlugin.php for specific information */   function setPassword( $password ) { return false; }    /**      * See AuthPlugin.php for specific information */    function updateExternalDB( $user ) { //Not really, but wiki thinks we did... return true; }    /**      * See AuthPlugin.php for specific information */    function canCreateAccounts { return false; }    /**      * See AuthPlugin.php for specific information */    function addUser( $user, $password ) { return false; }    /**      * See AuthPlugin.php for specific information */    function strict { return false; }    /**      * See AuthPlugin.php for specific information */    function initUser( &$user ) { //Update MW with new user information $this->updateUser($user); }    /**      * See AuthPlugin.php for specific information */    function getCanonicalName( $username ) { return $username; } } /** * End of AuthPlugin Code, beginning of hook code and auth functions */ /** * Some extension information init */ $wgExtensionFunctions[] = 'SSLAuthSetup'; $wgExtensionCredits['other'][] = array(   'name' => 'SSLAuth',    'version' => '1.0.2',    'author' => 'Martin Johnson',    'description' => 'Automagic login with certificates using Apache2 mod_ssl clientside',    'url' => 'http://www.mediawiki.org/wiki/Extension:SSL_authentication' ); /** * Setup extensionfunctions */ function SSLAuthSetup {    global $ssl_UN; global $wgHooks; global $wgAuth; if($ssl_UN != null) {        $wgHooks['AutoAuthenticate'][] = 'SSLAuth'; /* Hook for magical authN */ $wgHooks['PersonalUrls'][] = 'NoLogout'; /* Disallow logout link */ $wgAuth = new SSLAuthPlugin; } /** * Hooks looks funny in Special:Version * Written twice. Whats wrong with this code? */ } /* No logout link in MW */ function NoLogout(&$personal_urls, $title) {    $personal_urls['logout'] = null; } /* Tries to be magical about when to log in users and when not to. */ function SSLAuth(&$user) {    global $ssl_UN; global $wgUser; global $wgContLang; global $wgHooks;

//Give us a user, see if we're around //$tmpuser = User::LoadFromSession; // Pre MediaWiki 1.10 $tmpuser = new User ; $tmpuser->LoadFromSession;

//$tmpuser = User::newFromSession; // For MediaWiki 1.10.0 and up    //They already with us? If so, quit this function. if($tmpuser->isLoggedIn) return; //Is the user already in the database? //$tmpuser = User::newFromName($ssl_UN); unset($tmpuser) ; $tmpuser = new User ; $tmpuser = $tmpuser->newFromName($ssl_UN);

//If exists, log them in    if($tmpuser->getID != 0) {        $wgUser = &$tmpuser; $wgUser->setupSession; $wgUser->setCookies; return; }    //Okay, kick this up a notch then... //$wgUser = &$tmpuser; $wgUser = new User;

$wgUser->setName($wgContLang->ucfirst($ssl_UN)); /*     * Some magic that Shibboleth Authentication does and I just copy */     require_once('SpecialUserlogin.php'); //This section contains a silly hack for MW     global $wgLang; global $wgContLang; global $wgRequest; if(!isset($wgLang)) {         $wgLang = $wgContLang; $wgLangUnset = true; }     //Temporarily kill The AutoAuth Hook to prevent recursion foreach ($wgHooks['AutoAuthenticate'] as $key => $value) {           if($value == 'AutoAuth') $wgHooks['AutoAuthenticate'][$key] = 'BringBackAA'; }     //This creates our form that'll do black magic $lf = new LoginForm($wgRequest);

//Place the hook back (Not strictly necessarily MW Ver >= 1.9) BringBackAA;

//And now we clean up our hack if($wgLangUnset == true) {           unset($wgLang); unset($wgLangUnset); }

//Now we _do_ the black magic $lf->mRemember = false; $lf->initUser($wgUser); //Finish it off $wgUser->saveSettings; $wgUser->setupSession; $wgUser->setCookies; }

/* Puts the auto-auth hook back into the hooks array */ function BringBackAA {       global $wgHooks;

foreach ($wgHooks['AutoAuthenticate'] as $key => $value) {           if($value == 'BringBackAA') $wgHooks['AutoAuthenticate'][$key] = 'AutoAuth'; } }

?>

Regards

Markus

gridsitewiki
Is it worth investigating if the work done for x509 integration with 1.4.x tree as part of GridSiteWiki can be reused?