r39506 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39505‎ | r39506 | r39507 >
Date:21:54, 16 August 2008
Author:laner
Status:old
Tags:
Comment:
* Added option for defining attributes to use when pulling preferences
* Fixed session issue when using auto auth that was causing the plugin to not detect when a user was logged in
Modified paths:
  • /trunk/extensions/LdapAuthentication/AutoAuthentication.php (modified) (history)
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -214,7 +214,7 @@
215215 * @access public
216216 */
217217 function authenticate( $username, $password='' ) {
218 - global $wgLDAPRetrievePrefs;
 218+ global $wgLDAPRetrievePrefs, $wgLDAPPreferences;
219219 global $wgLDAPGroupDN, $wgLDAPRequiredGroups;
220220 global $wgLDAPGroupUseFullDN, $wgLDAPGroupUseRetrievedUsername;
221221 global $wgLDAPUseLDAPGroups;
@@ -394,8 +394,43 @@
395395 }
396396
397397 //Retrieve preferences
398 - if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
 398+ if ( isset( $wgLDAPPreferences[$_SESSION['wsDomain']] ) ) {
399399 $this->printDebug( "Retrieving preferences", NONSENSITIVE );
 400+ $entry = @ldap_read( $ldapconn, $userdn, "objectclass=*" );
 401+ $info = @ldap_get_entries( $ldapconn, $entry );
 402+ $prefs = $wgLDAPPreferences[$_SESSION['wsDomain']];
 403+ foreach ( array_keys( $prefs ) as $key ) {
 404+ switch ( $key ) {
 405+ case "email":
 406+ if ( isset( $info[0]["$prefs[$key]"] ) ) {
 407+ $this->email = $info[0]["$prefs[$key]"][0];
 408+ $this->printDebug( "Retrieved email ($this->email) using attribute ($prefs[$key])", NONSENSITIVE );
 409+ }
 410+ break;
 411+ case "language":
 412+ if ( isset( $info[0]["$prefs[$key]"] ) ) {
 413+ $this->lang = $info[0][$prefs[$key]][0];
 414+ $this->printDebug( "Retrieved language ($this->lang) using attribute ($prefs[$key])", NONSENSITIVE );
 415+ }
 416+ break;
 417+ case "nickname":
 418+ if ( isset( $info[0]["$prefs[$key]"] ) ) {
 419+ $this->nickname = $info[0]["$prefs[$key]"][0];
 420+ $this->printDebug( "Retrieved nickname ($this->nickname) using attribute ($prefs[$key])", NONSENSITIVE );
 421+ }
 422+ break;
 423+ case "realname":
 424+ if ( isset( $info[0]["$prefs[$key]"] ) ) {
 425+ $this->realname = $info[0]["$prefs[$key]"][0];
 426+ $this->printDebug( "Retrieved realname ($this->realname) using attribute ($prefs[$key])", NONSENSITIVE );
 427+ }
 428+ break;
 429+ }
 430+ }
 431+ } else if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
 432+ //DEPRECATED. Kept for backwards compatibility.
 433+ $this->printDebug( "Retrieving preferences", NONSENSITIVE );
 434+ $this->printDebug( '$wgLDAPRetrievePrefs is a DEPRECATED option, please use $wgLDAPPreferences.', NONSENSITIVE );
400435
401436 $entry = @ldap_read( $ldapconn, $userdn, "objectclass=*" );
402437 $info = @ldap_get_entries( $ldapconn, $entry );
@@ -723,6 +758,8 @@
724759 global $wgLDAPUpdateLDAP, $wgLDAPMailPassword;
725760 global $wgLDAPUseLocal;
726761
 762+ $this->printDebug( "Entering allowPasswordChange", NONSENSITIVE );
 763+
727764 $retval = false;
728765
729766 // Local domains need to be able to change passwords
@@ -886,7 +923,7 @@
887924 * TODO: fix the setExternalID stuff
888925 */
889926 function updateUser( &$user ) {
890 - global $wgLDAPRetrievePrefs;
 927+ global $wgLDAPRetrievePrefs, $wgLDAPPreferences;
891928 global $wgLDAPUseLDAPGroups;
892929 global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser;
893930
@@ -901,19 +938,24 @@
902939
903940 //If we aren't pulling preferences, we don't want to accidentally
904941 //overwrite anything.
905 - if ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) {
 942+ if ( ( isset( $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] ) && $wgLDAPRetrievePrefs[$_SESSION['wsDomain']] )
 943+ || isset( $wgLDAPPreferences[$_SESSION['wsDomain']] ) ) {
906944 $this->printDebug( "Setting user preferences.", NONSENSITIVE );
907945
908946 if ( '' != $this->lang ) {
 947+ $this->printDebug( "Setting language.", NONSENSITIVE );
909948 $user->setOption( 'language', $this->lang );
910949 }
911950 if ( '' != $this->nickname ) {
 951+ $this->printDebug( "Setting nickname.", NONSENSITIVE );
912952 $user->setOption( 'nickname', $this->nickname );
913953 }
914954 if ( '' != $this->realname ) {
 955+ $this->printDebug( "Setting realname.", NONSENSITIVE );
915956 $user->setRealName( $this->realname );
916957 }
917958 if ( '' != $this->email ) {
 959+ $this->printDebug( "Setting email.", NONSENSITIVE );
918960 $user->setEmail( $this->email );
919961 }
920962 if ( ( isset( $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] ) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] )
@@ -925,6 +967,8 @@
926968 }
927969
928970 $saveSettings = true;
 971+ } else {
 972+ $this->printDebug( "WTF!?", NONSENSITIVE );
929973 }
930974
931975 if ( isset( $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) && $wgLDAPUseLDAPGroups[$_SESSION['wsDomain']] ) {
Index: trunk/extensions/LdapAuthentication/AutoAuthentication.php
@@ -66,6 +66,8 @@
6767 $user->setID( $localId );
6868 $user->loadFromId();
6969 $user->setCookies();
 70+ $wgAuth->updateUser( $user );
 71+ wfSetupSession();
7072 $result = true;
7173 }
7274
@@ -88,6 +90,7 @@
8991
9092 $wgAuth->initUser( $user, true );
9193 $user->setCookies();
 94+ wfSetupSession();
9295
9396 # Update user count
9497 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );

Status & tagging log