Index: trunk/extensions/LdapAuthentication/AutoAuthentication.php |
— | — | @@ -1,114 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class LdapAutoAuthentication { |
5 | | - |
6 | | - /** |
7 | | - * Does the web server authentication piece of the LDAP plugin. |
8 | | - * |
9 | | - * @access public |
10 | | - */ |
11 | | - static function Authenticate( $user, &$result ) { |
12 | | - global $wgUser; |
13 | | - global $wgAuth; |
14 | | - global $wgLDAPAutoAuthUsername; |
15 | | - |
16 | | - $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE ); |
17 | | - |
18 | | - //The following section is a hack to determine whether or not |
19 | | - //the user is logged in. We need a core fix to make this simpler. |
20 | | - if ( isset( $_SESSION['wsUserID'] ) ) { |
21 | | - $user->setID( $_SESSION['wsUserID'] ); |
22 | | - if ( $user->loadFromId() ) { |
23 | | - if ( $_SESSION['wsToken'] == $user->mToken && $_SESSION['wsUserName'] == $user->mName ) { |
24 | | - $wgAuth->printDebug( "User is already logged in.", NONSENSITIVE ); |
25 | | - $result = true; |
26 | | - return true; |
27 | | - } else { |
28 | | - $user->loadFromDefaults(); |
29 | | - } |
30 | | - } |
31 | | - } |
32 | | - |
33 | | - $wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE ); |
34 | | - |
35 | | - //Let regular authentication plugins configure themselves for auto |
36 | | - //authentication chaining |
37 | | - $wgAuth->autoAuthSetup(); |
38 | | - |
39 | | - $wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE ); |
40 | | - //The user hasn't already been authenticated, let's check them |
41 | | - $authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername ); |
42 | | - if ( !$authenticated ) { |
43 | | - //If the user doesn't exist in LDAP, there isn't much reason to |
44 | | - //go any further. |
45 | | - $wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE ); |
46 | | - return false; |
47 | | - } |
48 | | - |
49 | | - //We need the username that MediaWiki will always use, *not* the one we |
50 | | - //get from LDAP. |
51 | | - $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername ); |
52 | | - |
53 | | - $wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE ); |
54 | | - |
55 | | - $localId = User::idFromName( $mungedUsername ); |
56 | | - $wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE ); |
57 | | - |
58 | | - //Is the user already in the database? |
59 | | - if( !$localId ) { |
60 | | - $userAdded = self::attemptAddUser( $user, $mungedUsername ); |
61 | | - if ( !$userAdded ) { |
62 | | - $result = false; |
63 | | - return false; |
64 | | - } |
65 | | - } else { |
66 | | - $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE ); |
67 | | - $user->setID( $localId ); |
68 | | - $user->loadFromId(); |
69 | | - $user->setCookies(); |
70 | | - $wgAuth->updateUser( $user ); |
71 | | - wfSetupSession(); |
72 | | - $result = true; |
73 | | - } |
74 | | - |
75 | | - return true; |
76 | | - } |
77 | | - |
78 | | - static function attemptAddUser( $user, $mungedUsername ) { |
79 | | - global $wgAuth; |
80 | | - |
81 | | - if ( !$wgAuth->autoCreate() ) { |
82 | | - $wgAuth->printDebug( "Cannot automatically create accounts.", NONSENSITIVE ); |
83 | | - return false; |
84 | | - } |
85 | | - |
86 | | - $wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE ); |
87 | | - |
88 | | - // Checks passed, create the user |
89 | | - $user->loadDefaults( $mungedUsername ); |
90 | | - $user->addToDatabase(); |
91 | | - |
92 | | - $wgAuth->initUser( $user, true ); |
93 | | - $user->setCookies(); |
94 | | - wfSetupSession(); |
95 | | - |
96 | | - # Update user count |
97 | | - $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
98 | | - $ssUpdate->doUpdate(); |
99 | | - |
100 | | - # Notify hooks (e.g. Newuserlog) |
101 | | - wfRunHooks( 'AuthPluginAutoCreate', array( $user ) ); |
102 | | - |
103 | | - return true; |
104 | | - } |
105 | | - |
106 | | - /* No logout link in MW */ |
107 | | - static function NoLogout( &$personal_urls, $title ) { |
108 | | - global $wgAuth; |
109 | | - $wgAuth->printDebug( "Entering NoLogout.", NONSENSITIVE ); |
110 | | - |
111 | | - $personal_urls['logout'] = null; |
112 | | - |
113 | | - return true; |
114 | | - } |
115 | | -} |
Index: trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php |
— | — | @@ -0,0 +1,114 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class LdapAutoAuthentication { |
| 5 | + |
| 6 | + /** |
| 7 | + * Does the web server authentication piece of the LDAP plugin. |
| 8 | + * |
| 9 | + * @access public |
| 10 | + */ |
| 11 | + static function Authenticate( $user, &$result ) { |
| 12 | + global $wgUser; |
| 13 | + global $wgAuth; |
| 14 | + global $wgLDAPAutoAuthUsername; |
| 15 | + |
| 16 | + $wgAuth->printDebug( "Entering AutoAuthentication.", NONSENSITIVE ); |
| 17 | + |
| 18 | + //The following section is a hack to determine whether or not |
| 19 | + //the user is logged in. We need a core fix to make this simpler. |
| 20 | + if ( isset( $_SESSION['wsUserID'] ) ) { |
| 21 | + $user->setID( $_SESSION['wsUserID'] ); |
| 22 | + if ( $user->loadFromId() ) { |
| 23 | + if ( $_SESSION['wsToken'] == $user->mToken && $_SESSION['wsUserName'] == $user->mName ) { |
| 24 | + $wgAuth->printDebug( "User is already logged in.", NONSENSITIVE ); |
| 25 | + $result = true; |
| 26 | + return true; |
| 27 | + } else { |
| 28 | + $user->loadFromDefaults(); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + $wgAuth->printDebug( "User isn't logged in, calling setup.", NONSENSITIVE ); |
| 34 | + |
| 35 | + //Let regular authentication plugins configure themselves for auto |
| 36 | + //authentication chaining |
| 37 | + $wgAuth->autoAuthSetup(); |
| 38 | + |
| 39 | + $wgAuth->printDebug( "Calling authenticate with username ($wgLDAPAutoAuthUsername).", NONSENSITIVE ); |
| 40 | + //The user hasn't already been authenticated, let's check them |
| 41 | + $authenticated = $wgAuth->authenticate( $wgLDAPAutoAuthUsername ); |
| 42 | + if ( !$authenticated ) { |
| 43 | + //If the user doesn't exist in LDAP, there isn't much reason to |
| 44 | + //go any further. |
| 45 | + $wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE ); |
| 46 | + return false; |
| 47 | + } |
| 48 | + |
| 49 | + //We need the username that MediaWiki will always use, *not* the one we |
| 50 | + //get from LDAP. |
| 51 | + $mungedUsername = $wgAuth->getCanonicalName( $wgLDAPAutoAuthUsername ); |
| 52 | + |
| 53 | + $wgAuth->printDebug( "User exists in LDAP; finding the user by name ($mungedUsername) in MediaWiki.", NONSENSITIVE ); |
| 54 | + |
| 55 | + $localId = User::idFromName( $mungedUsername ); |
| 56 | + $wgAuth->printDebug( "Got id ($localId).", NONSENSITIVE ); |
| 57 | + |
| 58 | + //Is the user already in the database? |
| 59 | + if( !$localId ) { |
| 60 | + $userAdded = self::attemptAddUser( $user, $mungedUsername ); |
| 61 | + if ( !$userAdded ) { |
| 62 | + $result = false; |
| 63 | + return false; |
| 64 | + } |
| 65 | + } else { |
| 66 | + $wgAuth->printDebug( "User exists in local database, logging in.", NONSENSITIVE ); |
| 67 | + $user->setID( $localId ); |
| 68 | + $user->loadFromId(); |
| 69 | + $user->setCookies(); |
| 70 | + $wgAuth->updateUser( $user ); |
| 71 | + wfSetupSession(); |
| 72 | + $result = true; |
| 73 | + } |
| 74 | + |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + static function attemptAddUser( $user, $mungedUsername ) { |
| 79 | + global $wgAuth; |
| 80 | + |
| 81 | + if ( !$wgAuth->autoCreate() ) { |
| 82 | + $wgAuth->printDebug( "Cannot automatically create accounts.", NONSENSITIVE ); |
| 83 | + return false; |
| 84 | + } |
| 85 | + |
| 86 | + $wgAuth->printDebug( "User does not exist in local database; creating.", NONSENSITIVE ); |
| 87 | + |
| 88 | + // Checks passed, create the user |
| 89 | + $user->loadDefaults( $mungedUsername ); |
| 90 | + $user->addToDatabase(); |
| 91 | + |
| 92 | + $wgAuth->initUser( $user, true ); |
| 93 | + $user->setCookies(); |
| 94 | + wfSetupSession(); |
| 95 | + |
| 96 | + # Update user count |
| 97 | + $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); |
| 98 | + $ssUpdate->doUpdate(); |
| 99 | + |
| 100 | + # Notify hooks (e.g. Newuserlog) |
| 101 | + wfRunHooks( 'AuthPluginAutoCreate', array( $user ) ); |
| 102 | + |
| 103 | + return true; |
| 104 | + } |
| 105 | + |
| 106 | + /* No logout link in MW */ |
| 107 | + static function NoLogout( &$personal_urls, $title ) { |
| 108 | + global $wgAuth; |
| 109 | + $wgAuth->printDebug( "Entering NoLogout.", NONSENSITIVE ); |
| 110 | + |
| 111 | + $personal_urls['logout'] = null; |
| 112 | + |
| 113 | + return true; |
| 114 | + } |
| 115 | +} |
Property changes on: trunk/extensions/LdapAuthentication/LdapAutoAuthentication.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 116 | + native |