r95934 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95933‎ | r95934 | r95935 >
Date:05:11, 1 September 2011
Author:laner
Status:deferred
Tags:
Comment:
If a user is missing nova credentials upon login, add them
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php
@@ -409,12 +409,15 @@
410410 * @param $auth
411411 * @param $username
412412 * @param $values
 413+ * @param $writeloc
 414+ * @param $userdn
413415 * @param $result
414416 * @return bool
415417 */
416 - static function LDAPSetCreationValues( $auth, $username, &$values, &$result ) {
 418+ static function LDAPSetCreationValues( $auth, $username, &$values, $writeloc, &$userdn, &$result ) {
417419 global $wgOpenStackManagerLDAPDefaultGid;
418420 global $wgOpenStackManagerLDAPDefaultShell;
 421+ global $wgOpenStackManagerLDAPUseUidAsNamingAttribute;
419422 global $wgRequest;
420423
421424 $values['objectclass'][] = 'person';
@@ -462,6 +465,15 @@
463466 $values['homedirectory'] = '/home/' . $username;
464467 $values['loginshell'] = $wgOpenStackManagerLDAPDefaultShell;
465468
 469+ if ( $wgOpenStackManagerLDAPUseUidAsNamingAttribute ) {
 470+ if ( $writeloc = '' ) {
 471+ return false;
 472+ $auth->printDebug( "Trying to set the userdn, but write location isn't set.", NONSENSITIVE );
 473+ } else {
 474+ $userdn = 'uid=' . $username . ',' . $writeloc;
 475+ $auth->printDebug( "Using uid as the naming attribute, dn is: $userdn", NONSENSITIVE );
 476+ }
 477+ }
466478 $auth->printDebug( "User account's objectclasses: ", NONSENSITIVE, $values['objectclass'] );
467479 $auth->printDebug( "User account's attributes: ", HIGHLYSENSITIVE, $values );
468480
@@ -469,7 +481,40 @@
470482 }
471483
472484 /**
 485+ * Hook to add objectclasses and attributes for users that already exist, but have
 486+ * missing information.
 487+ *
473488 * @static
 489+ * @param $auth
 490+ * @return bool
 491+ */
 492+ static function LDAPSetNovaInfo( $auth ) {
 493+ $this->userInfo = $auth->userInfo;
 494+ if ( !$this->exists() ) {
 495+ if ( !in_array( 'novauser', $this->userInfo[0]['objectclass'] ) ) {
 496+ $values['objectclass'] = $this->userInfo[0]['objectclass'];
 497+ $values['objectclass'][] = 'novauser';
 498+ }
 499+ $values['accesskey'] = OpenStackNovaUser::uuid4();
 500+ $values['secretkey'] = OpenStackNovaUser::uuid4();
 501+ $values['isnovaadmin'] = 'FALSE';
 502+
 503+ wfSuppressWarnings();
 504+ $success = ldap_modify( $auth->ldapconn, $auth->userdn, $values );
 505+ wfRestoreWarnings();
 506+ if ( $success ) {
 507+ $auth->printDebug( "Successfully modified the user's nova attributes", NONSENSITIVE );
 508+ return true;
 509+ } else {
 510+ $auth->printDebug( "Failed to modify the user's nova attributes", NONSENSITIVE );
 511+ # Always return true, other hooks should still run, even if this fails
 512+ return true;
 513+ }
 514+ }
 515+ }
 516+
 517+ /**
 518+ * @static
474519 * @param $template
475520 * @return bool
476521 */
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -131,5 +131,6 @@
132132
133133 $wgHooks['LDAPSetCreationValues'][] = 'OpenStackNovaUser::LDAPSetCreationValues';
134134 $wgHooks['LDAPModifyUITemplate'][] = 'OpenStackNovaUser::LDAPModifyUITemplate';
 135+$wgHooks['LDAPUpdateUser'][] = 'OpenStackNovaUser::LDAPSetNovaInfo';
135136
136137 require_once( "$IP/extensions/OpenStackManager/OpenStackNovaProject.php" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r95936Of course, doesn't work in static functions :). Follow up to r95934laner05:24, 1 September 2011

Status & tagging log