http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95934

Revision: 95934
Author:   laner
Date:     2011-09-01 05:11:58 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
If a user is missing nova credentials upon login, add them

Modified Paths:
--------------
    trunk/extensions/OpenStackManager/OpenStackManager.php
    trunk/extensions/OpenStackManager/OpenStackNovaUser.php

Modified: trunk/extensions/OpenStackManager/OpenStackManager.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackManager.php      2011-09-01 
05:01:21 UTC (rev 95933)
+++ trunk/extensions/OpenStackManager/OpenStackManager.php      2011-09-01 
05:11:58 UTC (rev 95934)
@@ -131,5 +131,6 @@
 
 $wgHooks['LDAPSetCreationValues'][] = 
'OpenStackNovaUser::LDAPSetCreationValues';
 $wgHooks['LDAPModifyUITemplate'][] = 'OpenStackNovaUser::LDAPModifyUITemplate';
+$wgHooks['LDAPUpdateUser'][] = 'OpenStackNovaUser::LDAPSetNovaInfo';
 
 require_once( "$IP/extensions/OpenStackManager/OpenStackNovaProject.php" );

Modified: trunk/extensions/OpenStackManager/OpenStackNovaUser.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackNovaUser.php     2011-09-01 
05:01:21 UTC (rev 95933)
+++ trunk/extensions/OpenStackManager/OpenStackNovaUser.php     2011-09-01 
05:11:58 UTC (rev 95934)
@@ -409,12 +409,15 @@
         * @param  $auth
         * @param  $username
         * @param  $values
+        * @param  $writeloc
+        * @param  $userdn
         * @param  $result
         * @return bool
         */
-       static function LDAPSetCreationValues( $auth, $username, &$values, 
&$result ) {
+       static function LDAPSetCreationValues( $auth, $username, &$values, 
$writeloc, &$userdn, &$result ) {
                global $wgOpenStackManagerLDAPDefaultGid;
                global $wgOpenStackManagerLDAPDefaultShell;
+               global $wgOpenStackManagerLDAPUseUidAsNamingAttribute;
                global $wgRequest;
 
                $values['objectclass'][] = 'person';
@@ -462,6 +465,15 @@
                $values['homedirectory'] = '/home/' . $username;
                $values['loginshell'] = $wgOpenStackManagerLDAPDefaultShell;
 
+               if ( $wgOpenStackManagerLDAPUseUidAsNamingAttribute ) {
+                       if ( $writeloc = '' ) {
+                               return false;
+                               $auth->printDebug( "Trying to set the userdn, 
but write location isn't set.", NONSENSITIVE );
+                       } else {
+                               $userdn = 'uid=' . $username . ',' . $writeloc;
+                               $auth->printDebug( "Using uid as the naming 
attribute, dn is: $userdn", NONSENSITIVE );
+                       }
+               }
                $auth->printDebug( "User account's objectclasses: ", 
NONSENSITIVE, $values['objectclass'] );
                $auth->printDebug( "User account's attributes: ", 
HIGHLYSENSITIVE, $values );
 
@@ -469,7 +481,40 @@
        }
 
        /**
+        * Hook to add objectclasses and attributes for users that already 
exist, but have
+        * missing information.
+        *
         * @static
+        * @param  $auth
+        * @return bool
+        */
+       static function LDAPSetNovaInfo( $auth ) {
+               $this->userInfo = $auth->userInfo;
+               if ( !$this->exists() ) {
+                       if ( !in_array( 'novauser', 
$this->userInfo[0]['objectclass'] ) ) {
+                               $values['objectclass'] = 
$this->userInfo[0]['objectclass'];
+                               $values['objectclass'][] = 'novauser';
+                       }
+                       $values['accesskey'] = OpenStackNovaUser::uuid4();
+                       $values['secretkey'] = OpenStackNovaUser::uuid4();
+                       $values['isnovaadmin'] = 'FALSE';
+
+                       wfSuppressWarnings();
+                       $success = ldap_modify( $auth->ldapconn, $auth->userdn, 
$values );
+                       wfRestoreWarnings();
+                       if ( $success ) {
+                               $auth->printDebug( "Successfully modified the 
user's nova attributes", NONSENSITIVE );
+                               return true;
+                       } else {
+                               $auth->printDebug( "Failed to modify the user's 
nova attributes", NONSENSITIVE );
+                               # Always return true, other hooks should still 
run, even if this fails
+                               return true;
+                       }
+               }
+       }
+
+       /**
+        * @static
         * @param  $template
         * @return bool
         */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to