3
class LdapAutoAuthentication {
6
* Does the web server authentication piece of the LDAP plugin.
10
static function Authenticate( $user, &$result ) {
13
global $wgLDAPAutoAuthUsername;
16
$wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE );
18
if ( version_compare( $wgVersion, '1.14.0', '<' ) ) {
19
//The following section is a hack to determine whether or not
20
//the user is logged in. We need a core fix to make this simpler.
21
if ( isset( $_SESSION['wsUserID'] ) ) {
22
$user->setID( $_SESSION['wsUserID'] );
23
if ( $user->loadFromId() ) {
24
if ( $_SESSION['wsToken'] == $user->mToken && $_SESSION['wsUserName'] == $user->mName ) {
25
$wgAuth->printDebug( "User is already logged in.", NONSENSITIVE );
29
$user->loadDefaults();
34
if ( $user->isLoggedIn() ) {
35
$wgAuth->printDebug( "User is already logged in.", NONSENSITIVE );
40
$wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE );
42
//Let regular authentication plugins configure themselves for auto
43
//authentication chaining
44
$wgAuth->autoAuthSetup();
46
$wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE );
47
//The user hasn't already been authenticated, let's check them
48
$authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername );
49
if ( !$authenticated ) {
50
//If the user doesn't exist in LDAP, there isn't much reason to
52
$wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE );
56
//We need the username that MediaWiki will always use, *not* the one we
58
$mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername );
60
$wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE );
62
$localId = User::idFromName( $mungedUsername );
63
$wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE );
65
//Is the user already in the database?
67
$userAdded = self::attemptAddUser( $user, $mungedUsername );
73
$wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE );
74
$user->setID( $localId );
77
$wgAuth->updateUser( $user );
85
static function attemptAddUser( $user, $mungedUsername ) {
88
if ( !$wgAuth->autoCreate() ) {
89
$wgAuth->printDebug( "Cannot automatically create accounts.", NONSENSITIVE );
93
$wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE );
95
// Checks passed, create the user
96
$user->loadDefaults( $mungedUsername );
97
$user->addToDatabase();
99
$wgAuth->initUser( $user, true );
104
$ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
105
$ssUpdate->doUpdate();
107
# Notify hooks (e.g. Newuserlog)
108
wfRunHooks( 'AuthPluginAutoCreate', array( $user ) );
113
/* No logout link in MW */
114
static function NoLogout( &$personal_urls, $title ) {
116
$wgAuth->printDebug( "Entering NoLogout.", NONSENSITIVE );
118
$personal_urls['logout'] = null;