Index: trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php |
— | — | @@ -8,13 +8,13 @@ |
9 | 9 | * @access public |
10 | 10 | */ |
11 | 11 | static function Authenticate( $user, &$result = null ) { |
12 | | - global $wgUser; |
13 | | - global $wgAuth; |
| 12 | + global $wgUser; |
| 13 | + global $wgAuth; |
14 | 14 | global $wgLDAPAutoAuthUsername; |
15 | 15 | global $wgVersion; |
16 | | - |
17 | | - $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE ); |
18 | 16 | |
| 17 | + $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE ); |
| 18 | + |
19 | 19 | if ( version_compare( $wgVersion, '1.14.0', '<' ) ) { |
20 | 20 | // The following section is a hack to determine whether or not |
21 | 21 | // the user is logged in. We need a core fix to make this simpler. |
— | — | @@ -22,10 +22,10 @@ |
23 | 23 | $user->setID( $_SESSION['wsUserID'] ); |
24 | 24 | if ( $user->loadFromId() ) { |
25 | 25 | 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 ); |
27 | 27 | $result = true; |
28 | | - return true; |
29 | | - } else { |
| 28 | + return true; |
| 29 | + } else { |
30 | 30 | $user->loadDefaults(); |
31 | 31 | } |
32 | 32 | } |
— | — | @@ -36,50 +36,50 @@ |
37 | 37 | return true; |
38 | 38 | } |
39 | 39 | } |
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 | + |
63 | 63 | $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 ) { |
68 | 68 | $userAdded = self::attemptAddUser( $user, $mungedUsername ); |
69 | 69 | if ( !$userAdded ) { |
70 | 70 | $result = false; |
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | } else { |
74 | | - $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE ); |
| 74 | + $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE ); |
75 | 75 | $user->setID( $localId ); |
76 | 76 | $user->loadFromId(); |
77 | 77 | $user->setCookies(); |
78 | 78 | $wgAuth->updateUser( $user ); |
79 | 79 | wfSetupSession(); |
80 | 80 | $result = true; |
81 | | - } |
| 81 | + } |
82 | 82 | |
83 | | - return true; |
| 83 | + return true; |
84 | 84 | } |
85 | 85 | |
86 | 86 | static function attemptAddUser( $user, $mungedUsername ) { |
— | — | @@ -90,14 +90,14 @@ |
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
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 | + |
96 | 96 | // Checks passed, create the user |
97 | 97 | $user->loadDefaults( $mungedUsername ); |
98 | 98 | $user->addToDatabase(); |
99 | 99 | |
100 | 100 | $wgAuth->initUser( $user, true ); |
101 | | - $user->setCookies(); |
| 101 | + $user->setCookies(); |
102 | 102 | wfSetupSession(); |
103 | 103 | |
104 | 104 | # Update user count |
— | — | @@ -112,11 +112,11 @@ |
113 | 113 | |
114 | 114 | /* No logout link in MW */ |
115 | 115 | 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; |
122 | 122 | } |
123 | 123 | } |