/** * Does the SSL authentication piece of the LDAP plugin. * * @access public */ function SSLAuth(&$user) { global $LDAPSSLUsername; global $User; global $Auth; $Auth->printDebug("Entering SSLAuth.", 1); //Give us a user, see if we're around $tmpuser = User::LoadFromSession(); //They already with us? If so, quit this function. if ($tmpuser->isLoggedIn()) { $Auth->printDebug("User is already logged in.", 1); return; } //Let regular authentication plugins configure themselves for auto //authentication chaining $Auth->autoAuthSetup(); //The user hasn't already been authenticated, let's check them $Auth->printDebug("User is not logged in, we need to authenticate", 1); $authenticated = $Auth->authenticate($LDAPSSLUsername); if (!$authenticated) { //If the user doesn't exist in LDAP, there isn't much reason to //go any further. $Auth->printDebug("User wasn't found in LDAP, exiting.", 1); return; } //We need the username that MediaWiki will always use, *not* the one we //get from LDAP. $mungedUsername = $Auth->getCanonicalName($LDAPSSLUsername); $Auth->printDebug("User exists in LDAP; finding the user by name in MediaWiki.", 1); //Is the user already in the database? $tmpuser = User::newFromName($mungedUsername); if ($tmpuser == null) { $Auth->printDebug("Username is not a valid MediaWiki username.", 1); return; } //If exists, log them in if ($tmpuser->getID() != 0) { $Auth->printDebug("User exists in local database, logging in.", 1); $User =& $tmpuser; $Auth->updateUser($User); $User->setCookies(); $User->setupSession(); return; } $Auth->printDebug("User does not exist in local database; creating.", 1); //Require SpecialUserlogin so that we can get a loginForm require_once 'SpecialUserlogin.php'; //This section contains a silly hack for MW global $Lang; global $ContLang; global $Request; if (!isset($Lang)) { $Lang = $ContLang; $LangUnset = true; } $Auth->printDebug("Creating LoginForm.", 1); //This creates our form that'll let us create a new user in the database $lf = new LoginForm($Request); //The user we'll be creating... $User =& $tmpuser; $User->setName($ContLang->ucfirst($mungedUsername)); $Auth->printDebug("Creating User.", 1); //Create the user $lf->initUser($User); //Initialize the user $User->setupSession(); $User->setCookies(); }