r68500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68499‎ | r68500 | r68501 >
Date:03:02, 24 June 2010
Author:laner
Status:deferred
Tags:
Comment:
Formatting
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php
@@ -8,13 +8,13 @@
99 * @access public
1010 */
1111 static function Authenticate( $user, &$result = null ) {
12 - global $wgUser;
13 - global $wgAuth;
 12+ global $wgUser;
 13+ global $wgAuth;
1414 global $wgLDAPAutoAuthUsername;
1515 global $wgVersion;
16 -
17 - $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE );
1816
 17+ $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE );
 18+
1919 if ( version_compare( $wgVersion, '1.14.0', '<' ) ) {
2020 // The following section is a hack to determine whether or not
2121 // the user is logged in. We need a core fix to make this simpler.
@@ -22,10 +22,10 @@
2323 $user->setID( $_SESSION['wsUserID'] );
2424 if ( $user->loadFromId() ) {
2525 if ( $_SESSION['wsToken'] == $user->mToken && $_SESSION['wsUserName'] == $user->mName ) {
26 - $wgAuth->printDebug( "User is already logged in.", NONSENSITIVE );
 26+ $wgAuth->printDebug( "User is already logged in.", NONSENSITIVE );
2727 $result = true;
28 - return true;
29 - } else {
 28+ return true;
 29+ } else {
3030 $user->loadDefaults();
3131 }
3232 }
@@ -36,50 +36,50 @@
3737 return true;
3838 }
3939 }
40 -
41 - $wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE );
42 -
43 - // Let regular authentication plugins configure themselves for auto
44 - // authentication chaining
45 - $wgAuth->autoAuthSetup();
46 -
47 - $wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE );
48 - // The user hasn't already been authenticated, let's check them
49 - $authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername );
50 - if ( !$authenticated ) {
51 - // If the user doesn't exist in LDAP, there isn't much reason to
52 - // go any further.
53 - $wgAuth->printDebug( "User wasn't found in LDAP, exiting.", NONSENSITIVE );
54 - return false;
55 - }
56 -
57 - // We need the username that MediaWiki will always use, *not* the one we
58 - // get from LDAP.
59 - $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername );
60 -
61 - $wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE );
62 -
 40+
 41+ $wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE );
 42+
 43+ // Let regular authentication plugins configure themselves for auto
 44+ // authentication chaining
 45+ $wgAuth->autoAuthSetup();
 46+
 47+ $wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE );
 48+ // The user hasn't already been authenticated, let's check them
 49+ $authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername );
 50+ if ( !$authenticated ) {
 51+ // If the user doesn't exist in LDAP, there isn't much reason to
 52+ // go any further.
 53+ $wgAuth->printDebug( "User wasn't found in LDAP, exiting.", NONSENSITIVE );
 54+ return false;
 55+ }
 56+
 57+ // We need the username that MediaWiki will always use, *not* the one we
 58+ // get from LDAP.
 59+ $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername );
 60+
 61+ $wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE );
 62+
6363 $localId = User::idFromName( $mungedUsername );
64 - $wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE );
65 -
66 - // Is the user already in the database?
67 - if ( !$localId ) {
 64+ $wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE );
 65+
 66+ // Is the user already in the database?
 67+ if ( !$localId ) {
6868 $userAdded = self::attemptAddUser( $user, $mungedUsername );
6969 if ( !$userAdded ) {
7070 $result = false;
7171 return false;
7272 }
7373 } else {
74 - $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE );
 74+ $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE );
7575 $user->setID( $localId );
7676 $user->loadFromId();
7777 $user->setCookies();
7878 $wgAuth->updateUser( $user );
7979 wfSetupSession();
8080 $result = true;
81 - }
 81+ }
8282
83 - return true;
 83+ return true;
8484 }
8585
8686 static function attemptAddUser( $user, $mungedUsername ) {
@@ -90,14 +90,14 @@
9191 return false;
9292 }
9393
94 - $wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE );
95 -
 94+ $wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE );
 95+
9696 // Checks passed, create the user
9797 $user->loadDefaults( $mungedUsername );
9898 $user->addToDatabase();
9999
100100 $wgAuth->initUser( $user, true );
101 - $user->setCookies();
 101+ $user->setCookies();
102102 wfSetupSession();
103103
104104 # Update user count
@@ -112,11 +112,11 @@
113113
114114 /* No logout link in MW */
115115 static function NoLogout( &$personal_urls, $title ) {
116 - global $wgAuth;
117 - $wgAuth->printDebug( "Entering NoLogout.", NONSENSITIVE );
118 -
119 - $personal_urls['logout'] = null;
120 -
121 - return true;
 116+ global $wgAuth;
 117+ $wgAuth->printDebug( "Entering NoLogout.", NONSENSITIVE );
 118+
 119+ $personal_urls['logout'] = null;
 120+
 121+ return true;
122122 }
123123 }

Status & tagging log