| Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php |
| — | — | @@ -278,25 +278,16 @@ |
| 279 | 279 | switch ( $preference ) { |
| 280 | 280 | case 'ServerNames': |
| 281 | 281 | global $wgLDAPServerNames; |
| 282 | | - if ( isset( $wgLDAPServerNames[$domain] ) ) { |
| 283 | | - return $wgLDAPServerNames[$domain]; |
| 284 | | - } |
| 285 | | - return array(); |
| | 282 | + return self::setOrDefault( $wgLDAPServerNames, $domain, array() ); |
| 286 | 283 | case 'UseLocal': |
| 287 | 284 | global $wgLDAPUseLocal; |
| 288 | 285 | return $wgLDAPUseLocal; |
| 289 | 286 | case 'EncryptionType': |
| 290 | 287 | global $wgLDAPEncryptionType; |
| 291 | | - if ( isset( $wgLDAPEncryptionType[$domain] ) ) { |
| 292 | | - return $wgLDAPEncryptionType[$domain]; |
| 293 | | - } |
| 294 | | - return 'tls'; |
| | 288 | + return self::setOrDefault( $wgLDAPEncryptionType, $domain, 'tls' ); |
| 295 | 289 | case 'Options': |
| 296 | 290 | global $wgLDAPOptions; |
| 297 | | - if ( isset( $wgLDAPOptions[$domain] ) ) { |
| 298 | | - return $wgLDAPOptions[$domain]; |
| 299 | | - } |
| 300 | | - return array(); |
| | 291 | + return self::setOrDefault( $wgLDAPOptions, $domain, array() ); |
| 301 | 292 | case 'Port': |
| 302 | 293 | global $wgLDAPPort; |
| 303 | 294 | if ( isset( $wgLDAPPort[$domain] ) ) { |
| — | — | @@ -309,181 +300,104 @@ |
| 310 | 301 | } |
| 311 | 302 | case 'SearchString': |
| 312 | 303 | global $wgLDAPSearchStrings; |
| 313 | | - if ( isset( $wgLDAPSearchStrings[$domain] ) ) { |
| 314 | | - return $wgLDAPSearchStrings[$domain]; |
| 315 | | - } |
| | 304 | + return self::setOrDefault( $wgLDAPSearchStrings, $domain ); |
| 316 | 305 | case 'ProxyAgent': |
| 317 | 306 | global $wgLDAPProxyAgent; |
| 318 | | - if ( isset( $wgLDAPProxyAgent[$domain] ) ) { |
| 319 | | - return $wgLDAPProxyAgent[$domain]; |
| 320 | | - } |
| | 307 | + return self::setOrDefault( $wgLDAPProxyAgent, $domain ); |
| 321 | 308 | case 'ProxyAgentPassword': |
| 322 | 309 | global $wgLDAPProxyAgentPassword; |
| 323 | | - if ( isset( $wgLDAPProxyAgentPassword[$domain] ) ) { |
| 324 | | - return $wgLDAPProxyAgentPassword[$domain]; |
| 325 | | - } |
| | 310 | + return self::setOrDefault( $wgLDAPProxyAgentPassword, $domain ); |
| 326 | 311 | case 'SearchAttribute': |
| 327 | 312 | global $wgLDAPSearchAttributes; |
| 328 | | - if ( isset( $wgLDAPSearchAttributes[$domain] ) ) { |
| 329 | | - return $wgLDAPSearchAttributes[$domain]; |
| 330 | | - } |
| | 313 | + return self::setOrDefault( $wgLDAPSearchAttributes, $domain ); |
| 331 | 314 | case 'BaseDN': |
| 332 | 315 | global $wgLDAPBaseDNs; |
| 333 | | - if ( isset( $wgLDAPBaseDNs[$domain] ) ) { |
| 334 | | - return $wgLDAPBaseDNs[$domain]; |
| 335 | | - } |
| | 316 | + return self::setOrDefault( $wgLDAPBaseDNs, $domain ); |
| 336 | 317 | case 'GroupBaseDN': |
| 337 | 318 | global $wgLDAPGroupBaseDNs; |
| 338 | | - if ( isset( $wgLDAPGroupBaseDNs[$domain] ) ) { |
| 339 | | - return $wgLDAPGroupBaseDNs[$domain]; |
| 340 | | - } |
| | 319 | + return self::setOrDefault( $wgLDAPGroupBaseDNs, $domain ); |
| 341 | 320 | case 'UserBaseDN': |
| 342 | 321 | global $wgLDAPUserBaseDNs; |
| 343 | | - if ( isset( $wgLDAPUserBaseDNs[$domain] ) ) { |
| 344 | | - return $wgLDAPUserBaseDNs[$domain]; |
| 345 | | - } |
| | 322 | + return self::setOrDefault( $wgLDAPUserBaseDNs, $domain ); |
| 346 | 323 | case 'WriterDN': |
| 347 | 324 | global $wgLDAPWriterDN; |
| 348 | | - if ( isset( $wgLDAPWriterDN[$domain] ) ) { |
| 349 | | - return $wgLDAPWriterDN[$domain]; |
| 350 | | - } |
| | 325 | + return self::setOrDefault( $wgLDAPWriterDN, $domain ); |
| 351 | 326 | case 'WriterPassword': |
| 352 | 327 | global $wgLDAPWriterPassword; |
| 353 | | - if ( isset( $wgLDAPWriterPassword[$domain] ) ) { |
| 354 | | - return $wgLDAPWriterPassword[$domain]; |
| 355 | | - } |
| | 328 | + return self::setOrDefault( $wgLDAPWriterPassword, $domain ); |
| 356 | 329 | case 'WriteLocation': |
| 357 | 330 | global $wgLDAPWriteLocation; |
| 358 | | - if ( isset( $wgLDAPWriteLocation[$domain] ) ) { |
| 359 | | - return $wgLDAPWriteLocation[$domain]; |
| 360 | | - } |
| | 331 | + return self::setOrDefault( $wgLDAPWriteLocation, $domain ); |
| 361 | 332 | case 'AddLDAPUsers': |
| 362 | 333 | global $wgLDAPAddLDAPUsers; |
| 363 | | - if ( isset( $wgLDAPAddLDAPUsers[$domain] ) ) { |
| 364 | | - return $wgLDAPAddLDAPUsers[$domain]; |
| 365 | | - } |
| 366 | | - return false; |
| | 334 | + return self::setOrDefault( $wgLDAPAddLDAPUsers, $domain, false ); |
| 367 | 335 | case 'UpdateLDAP': |
| 368 | 336 | global $wgLDAPUpdateLDAP; |
| 369 | | - if ( isset( $wgLDAPUpdateLDAP[$domain] ) ) { |
| 370 | | - return $wgLDAPUpdateLDAP[$domain]; |
| 371 | | - } |
| 372 | | - return false; |
| | 337 | + return self::setOrDefault( $wgLDAPUpdateLDAP, $domain, false ); |
| 373 | 338 | case 'PasswordHash': |
| 374 | 339 | global $wgLDAPPasswordHash; |
| 375 | | - if ( isset( $wgLDAPPasswordHash[$domain] ) ) { |
| 376 | | - return $wgLDAPPasswordHash[$domain]; |
| 377 | | - } else { |
| 378 | | - return 'clear'; |
| 379 | | - } |
| | 340 | + return self::setOrDefault( $wgLDAPPasswordHash, $domain, 'clear' ); |
| 380 | 341 | case 'MailPassword': |
| 381 | 342 | global $wgLDAPMailPassword; |
| 382 | | - if ( isset( $wgLDAPMailPassword[$domain] ) ) { |
| 383 | | - return $wgLDAPMailPassword[$domain]; |
| 384 | | - } |
| 385 | | - return false; |
| | 343 | + return self::setOrDefault( $wgLDAPMailPassword, $domain, false ); |
| 386 | 344 | case 'Preferences': |
| 387 | 345 | global $wgLDAPPreferences; |
| 388 | | - if ( isset( $wgLDAPPreferences[$domain] ) ) { |
| 389 | | - return $wgLDAPPreferences[$domain]; |
| 390 | | - } |
| 391 | | - return array(); |
| | 346 | + return self::setOrDefault( $wgLDAPPreferences, $domain, array() ); |
| 392 | 347 | case 'DisableAutoCreate': |
| 393 | 348 | global $wgLDAPDisableAutoCreate; |
| 394 | | - if ( isset( $wgLDAPDisableAutoCreate[$domain] ) ) { |
| 395 | | - return $wgLDAPDisableAutoCreate[$domain]; |
| 396 | | - } |
| 397 | | - return false; |
| | 349 | + return self::setOrDefault( $wgLDAPDisableAutoCreate, $domain, false ); |
| 398 | 350 | case 'GroupUseFullDN': |
| 399 | 351 | global $wgLDAPGroupUseFullDN; |
| 400 | | - if ( isset( $wgLDAPGroupUseFullDN[$domain] ) ) { |
| 401 | | - return $wgLDAPGroupUseFullDN[$domain]; |
| 402 | | - } |
| 403 | | - return false; |
| | 352 | + return self::setOrDefault( $wgLDAPGroupUseFullDN, $domain, false ); |
| 404 | 353 | case 'LowerCaseUsername': |
| 405 | 354 | global $wgLDAPLowerCaseUsername; |
| 406 | 355 | if ( isset( $wgLDAPLowerCaseUsername[$domain] ) ) { |
| 407 | 356 | $this->printDebug( "Configuration set to lowercase username.", NONSENSITIVE ); |
| 408 | 357 | return $wgLDAPLowerCaseUsername[$domain]; |
| | 358 | + } else { |
| | 359 | + return false; |
| 409 | 360 | } |
| 410 | | - return false; |
| 411 | 361 | case 'LowerCaseUsernameScheme': |
| 412 | 362 | global $wgLDAPLowerCaseUsernameScheme; |
| 413 | | - if ( isset( $wgLDAPLowerCaseUsernameScheme[$domain] ) ) { |
| 414 | | - return $wgLDAPLowerCaseUsernameScheme[$domain]; |
| 415 | | - } else { |
| 416 | | - // Default set to true for backwards compatibility with |
| 417 | | - // versions < 2.0a |
| 418 | | - return true; |
| 419 | | - } |
| | 363 | + // Default set to true for backwards compatibility with |
| | 364 | + // versions < 2.0a |
| | 365 | + return self::setOrDefault( $wgLDAPLowerCaseUsernameScheme, $domain, true ); |
| 420 | 366 | case 'GroupUseRetievedUsername': |
| 421 | 367 | global $wgLDAPGroupUseRetrievedUsername; |
| 422 | | - if ( isset( $wgLDAPGroupUseRetrievedUsername[$domain] ) ) { |
| 423 | | - return $wgLDAPGroupUseRetrievedUsername[$domain]; |
| 424 | | - } |
| 425 | | - return false; |
| | 368 | + return self::setOrDefault( $wgLDAPGroupUseRetrievedUsername, $domain, false ); |
| 426 | 369 | case 'GroupObjectclass': |
| 427 | 370 | global $wgLDAPGroupObjectclass; |
| 428 | | - if ( isset( $wgLDAPGroupObjectclass[$domain] ) ) { |
| 429 | | - return $wgLDAPGroupObjectclass[$domain]; |
| 430 | | - } |
| | 371 | + return self::setOrDefault( $wgLDAPGroupObjectclass, $domain ); |
| 431 | 372 | case 'GroupAttribute': |
| 432 | 373 | global $wgLDAPGroupAttribute; |
| 433 | | - if ( isset( $wgLDAPGroupAttribute[$domain] ) ) { |
| 434 | | - return $wgLDAPGroupAttribute[$domain]; |
| 435 | | - } |
| | 374 | + return self::setOrDefault( $wgLDAPGroupAttribute, $domain ); |
| 436 | 375 | case 'GroupNameAttribute': |
| 437 | 376 | global $wgLDAPGroupNameAttribute; |
| 438 | | - if ( isset( $wgLDAPGroupNameAttribute[$domain] ) ) { |
| 439 | | - return $wgLDAPGroupNameAttribute[$domain]; |
| 440 | | - } |
| | 377 | + return self::setOrDefault( $wgLDAPGroupNameAttribute, $domain ); |
| 441 | 378 | case 'GroupsUseMemberOf': |
| 442 | 379 | global $wgLDAPGroupsUseMemberOf; |
| 443 | | - if ( isset( $wgLDAPGroupsUseMemberOf[$domain] ) ) { |
| 444 | | - return $wgLDAPGroupsUseMemberOf[$domain]; |
| 445 | | - } |
| 446 | | - return false; |
| | 380 | + return self::setOrDefault( $wgLDAPGroupsUseMemberOf, $domain, false ); |
| 447 | 381 | case 'UseLDAPGroups': |
| 448 | 382 | global $wgLDAPUseLDAPGroups; |
| 449 | | - if ( isset( $wgLDAPUseLDAPGroups[$domain] ) ) { |
| 450 | | - return $wgLDAPUseLDAPGroups[$domain]; |
| 451 | | - } |
| 452 | | - return false; |
| | 383 | + return self::setOrDefault( $wgLDAPUseLDAPGroups, $domain, false ); |
| 453 | 384 | case 'LocallyManagedGroups': |
| 454 | 385 | global $wgLDAPLocallyManagedGroups; |
| 455 | | - if ( isset( $wgLDAPLocallyManagedGroups[$domain] ) ) { |
| 456 | | - return $wgLDAPLocallyManagedGroups[$domain]; |
| 457 | | - } |
| 458 | | - return array(); |
| | 386 | + return self::setOrDefault( $wgLDAPLocallyManagedGroups, $domain, array() ); |
| 459 | 387 | case 'GroupsPrevail': |
| 460 | 388 | global $wgLDAPGroupsPrevail; |
| 461 | | - if ( isset( $wgLDAPGroupsPrevail[$domain] ) ) { |
| 462 | | - return $wgLDAPGroupsPrevail[$domain]; |
| 463 | | - } |
| 464 | | - return false; |
| | 389 | + return self::setOrDefault( $wgLDAPGroupsPrevail, $domain, false ); |
| 465 | 390 | case 'RequiredGroups': |
| 466 | 391 | global $wgLDAPRequiredGroups; |
| 467 | | - if ( isset( $wgLDAPRequiredGroups[$domain] ) ) { |
| 468 | | - return $wgLDAPRequiredGroups[$domain]; |
| 469 | | - } |
| 470 | | - return array(); |
| | 392 | + return self::setOrDefault( $wgLDAPRequiredGroups, $domain, array() ); |
| 471 | 393 | case 'ExcludedGroups': |
| 472 | 394 | global $wgLDAPExcludedGroups; |
| 473 | | - if ( isset( $wgLDAPExcludedGroups[$domain] ) ) { |
| 474 | | - return $wgLDAPExcludedGroups[$domain]; |
| 475 | | - } |
| 476 | | - return array(); |
| | 395 | + return self::setOrDefault( $wgLDAPExcludedGroups, $domain, array() ); |
| 477 | 396 | case 'GroupSearchNestedGroups': |
| 478 | 397 | global $wgLDAPGroupSearchNestedGroups; |
| 479 | | - if ( isset( $wgLDAPGroupSearchNestedGroups[$domain] ) ) { |
| 480 | | - return $wgLDAPGroupSearchNestedGroups[$domain]; |
| 481 | | - } |
| 482 | | - return false; |
| | 398 | + return self::setOrDefault( $wgLDAPGroupSearchNestedGroups, $domain, false ); |
| 483 | 399 | case 'AuthAttribute': |
| 484 | 400 | global $wgLDAPAuthAttribute; |
| 485 | | - if ( isset( $wgLDAPAuthAttribute[$domain] ) ) { |
| 486 | | - return $wgLDAPAuthAttribute[$domain]; |
| 487 | | - } |
| | 401 | + return self::setOrDefault( $wgLDAPAuthAttribute, $domain ); |
| 488 | 402 | case 'AutoAuthUsername': |
| 489 | 403 | global $wgLDAPAutoAuthUsername; |
| 490 | 404 | return $wgLDAPAutoAuthUsername; |
| — | — | @@ -495,6 +409,19 @@ |
| 496 | 410 | } |
| 497 | 411 | |
| 498 | 412 | /** |
| | 413 | + * Returns the item from $array at index $key if it is set, |
| | 414 | + * else, it returns $default |
| | 415 | + * |
| | 416 | + * @param $array array |
| | 417 | + * @param $key |
| | 418 | + * @param $default mixed |
| | 419 | + * @return mixed |
| | 420 | + */ |
| | 421 | + private static function setOrDefault( $array, $key, $default = '' ) { |
| | 422 | + return isset( $array[$key] ) ? $array[$key] : $default; |
| | 423 | + } |
| | 424 | + |
| | 425 | + /** |
| 499 | 426 | * Check whether there exists a user account with the given name. |
| 500 | 427 | * The name will be normalized to MediaWiki's requirements, so |
| 501 | 428 | * you might need to munge it (for instance, for lowercase initial |
| — | — | @@ -549,7 +476,8 @@ |
| 550 | 477 | /** |
| 551 | 478 | * Connect to LDAP |
| 552 | 479 | */ |
| 553 | | - private function connect( $domain='' ) { |
| | 480 | + public function connect( $domain='' ) { |
| | 481 | + // FIXME: $domain isn't used |
| 554 | 482 | if ( $domain == '' ) { |
| 555 | 483 | $domain = $this->getSessionDomain(); |
| 556 | 484 | } |
| — | — | @@ -557,7 +485,9 @@ |
| 558 | 486 | $this->printDebug( "Entering Connect", NONSENSITIVE ); |
| 559 | 487 | |
| 560 | 488 | if ( !function_exists( 'ldap_connect' ) ) { |
| 561 | | - $this->printDebug( "It looks like you are missing LDAP support; please ensure you have either compiled LDAP support in, or have enabled the module. If the authentication is working for you, the plugin isn't properly detecting the LDAP module, and you can safely ignore this message.", NONSENSITIVE ); |
| | 489 | + $this->printDebug( "It looks like you are missing LDAP support; please ensure you have either compiled LDAP " |
| | 490 | + . "support in, or have enabled the module. If the authentication is working for you, the plugin isn't properly " |
| | 491 | + . "detecting the LDAP module, and you can safely ignore this message.", NONSENSITIVE ); |
| 562 | 492 | return false; |
| 563 | 493 | } |
| 564 | 494 | |