r96495 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96494‎ | r96495 | r96496 >
Date:21:02, 7 September 2011
Author:laner
Status:deferred
Tags:ldap 
Comment:
* Added new wgLDAPUseFetchedUsername option, which will use the attribute from wgLDAPSearchAttributes as the username, if set
* Added support for authenticating with one username, but having a different wiki name (ie: login with uid, but have cn be the wiki name)
* Added some debugging messages
* Bumped version to 1.1f
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -87,8 +87,9 @@
8888 $wgLDAPUniqueAttribute = array(); //Currently unused
8989 $wgLDAPUniqueBlockLogin = array(); //Currently unused
9090 $wgLDAPUniqueRenameUser = array(); //Currently unused
 91+$wgLDAPUseFetchedUsername = array();
9192
92 -define( "LDAPAUTHVERSION", "1.2e" );
 93+define( "LDAPAUTHVERSION", "1.2f" );
9394
9495 /**
9596 * Add extension information to Special:Version
@@ -305,7 +306,7 @@
306307 global $wgLDAPLowerCaseUsername;
307308 global $wgLDAPSearchStrings;
308309
309 - $this->printDebug( "Entering authenticate", NONSENSITIVE );
 310+ $this->printDebug( "Entering authenticate for username $username", NONSENSITIVE );
310311
311312 // We don't handle local authentication
312313 if ( 'local' == $_SESSION['wsDomain'] ) {
@@ -959,16 +960,34 @@
960961 * @access public
961962 */
962963 function getCanonicalName( $username ) {
 964+ global $wgLDAPUseFetchedUsername;
963965 $this->printDebug( "Entering getCanonicalName", NONSENSITIVE );
964966
965967 if ( $username != '' ) {
966968 $this->printDebug( "Username isn't empty.", NONSENSITIVE );
967969
 970+ # Fetch username, so that we can possibly use it.
 971+ # Only do it if we haven't already fetched it.
 972+ if ( !$this->userdn ) {
 973+ $this->connect();
 974+ if ( $this->ldapconn ) {
 975+ $this->printDebug( "Successfully connected", NONSENSITIVE );
 976+ $this->userdn = $this->getSearchString( $username );
 977+ wfRunHooks( 'SetUsernameAttributeFromLDAP', array( &$this->LDAPUsername, $this->userInfo ) );
 978+ } else {
 979+ $this->printDebug( "Failed to connect in getCanonicalName, this is non-critical, but may indicate a misconfiguration.", NONSENSITIVE );
 980+ }
 981+ }
 982+
968983 // We want to use the username returned by LDAP
969984 // if it exists
970985 if ( $this->LDAPUsername != '' ) {
971 - $this->printDebug( "Using LDAPUsername.", NONSENSITIVE );
972986 $username = $this->LDAPUsername;
 987+ if ( isset( $wgLDAPUseFetchedUsername[$_SESSION['wsDomain']] ) && $wgLDAPUseFetchedUsername[$_SESSION['wsDomain']] ) {
 988+ $username[0] = strtoupper( $username[0] );
 989+ return $username;
 990+ }
 991+ $this->printDebug( "Using LDAPUsername: $username", NONSENSITIVE );
973992 }
974993
975994 if ( isset( $_SESSION['wsDomain'] ) && 'local' != $_SESSION['wsDomain'] ) {
@@ -1086,6 +1105,12 @@
10871106
10881107 $this->userInfo = @ldap_get_entries( $this->ldapconn, $entry );
10891108 $this->fetchedUserInfo = true;
 1109+ $searchattr = $wgLDAPSearchAttributes[$_SESSION['wsDomain']];
 1110+ if ( isset( $this->userInfo[0][$searchattr] ) ) {
 1111+ $username = $this->userInfo[0][$searchattr][0];
 1112+ $this->printDebug( "Setting the LDAPUsername based on fetched wgLDAPSearchAttributes: $username", NONSENSITIVE );
 1113+ $this->LDAPUsername = $username;
 1114+ }
10901115
10911116 // This is a pretty useful thing to have for auto authentication,
10921117 // group checking, and pulling preferences.

Status & tagging log