From 303d17b260140fa5f448aed9856e327f528e14f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 20 Oct 2011 18:58:40 +0200 Subject: [PATCH] Bug #847 - #918: Add password to one.user.chauth method, this way the driver and the auth driver are changed atomically --- include/RequestManagerUser.h | 2 +- src/cli/oneuser | 22 ++++++++++++++++--- .../src/org/opennebula/client/user/User.java | 17 +++++++++----- src/oca/java/test/UserTest.java | 2 +- src/oca/ruby/OpenNebula/User.rb | 7 +++--- src/rm/RequestManagerUser.cc | 11 +++++++++- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/RequestManagerUser.h b/include/RequestManagerUser.h index b28e1b8bc5..016a85d2ce 100644 --- a/include/RequestManagerUser.h +++ b/include/RequestManagerUser.h @@ -85,7 +85,7 @@ public: UserChangeAuth(): RequestManagerUser("UserChangeAuth", "Changes user's authentication driver", - "A:sis") + "A:siss") { auth_op = AuthRequest::CHAUTH; }; diff --git a/src/cli/oneuser b/src/cli/oneuser index d6a95ef975..b70b067d32 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -263,10 +263,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do Changes the User's auth driver EOT - command :chauth, chauth_desc, [:range, :userid_list], :auth do + command :chauth, chauth_desc, :userid, :auth, [:password, nil], + :options=>create_options do + helper = OneUserHelper.new - helper.perform_actions(args[0],options,"Auth driver changed") do |user| - user.chauth(args[1]) + + if args[2] + pass = args[2] + else + rc = helper.password(options) + if rc.first == 0 + pass = rc[1] + else + exit_with_code *rc + end + end + + helper.perform_action(args[0], + options, + "Auth driver and password changed") do |user| + user.chauth(args[1], pass) end end diff --git a/src/oca/java/src/org/opennebula/client/user/User.java b/src/oca/java/src/org/opennebula/client/user/User.java index 16da68bd83..cfcd85d979 100644 --- a/src/oca/java/src/org/opennebula/client/user/User.java +++ b/src/oca/java/src/org/opennebula/client/user/User.java @@ -146,16 +146,20 @@ public class User extends PoolElement{ } /** - * Changes the auth driver of the given user + * Changes the auth driver and the password of the given user * * @param client XML-RPC Client. * @param id The user id (uid) of the target user we want to modify. * @param auth The new auth driver. + * @param password The new password. * @return If an error occurs the error message contains the reason. */ - public static OneResponse chauth(Client client, int id, String auth) + public static OneResponse chauth(Client client, + int id, + String auth, + String password) { - return client.call(CHAUTH, id, auth); + return client.call(CHAUTH, id, auth, password); } /** @@ -222,14 +226,15 @@ public class User extends PoolElement{ } /** - * Changes the auth driver of the given user + * Changes the auth driver and the password of the given user * * @param auth The new auth driver. + * @param password The new password. * @return If an error occurs the error message contains the reason. */ - public OneResponse chauth(String auth) + public OneResponse chauth(String auth, String password) { - return chauth(client, id, auth); + return chauth(client, id, auth, password); } /** diff --git a/src/oca/java/test/UserTest.java b/src/oca/java/test/UserTest.java index d8e9a0f720..58964354dc 100644 --- a/src/oca/java/test/UserTest.java +++ b/src/oca/java/test/UserTest.java @@ -121,7 +121,7 @@ public class UserTest assertTrue( user.xpath("AUTH_DRIVER").equals("core") ); - res = user.chauth("new_driver"); + res = user.chauth("new_driver", password); res = user.info(); assertTrue( res.getErrorMessage(), !res.isError() ); diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index e5e1a57d41..06f30a0331 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -116,15 +116,16 @@ module OpenNebula return rc end - # Changes the auth driver + # Changes the auth driver and the password of the given User # # @param auth [String] the new auth driver + # @param password [String] the new password # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise - def chauth(auth) + def chauth(auth, password) return Error.new('ID not defined') if !@pe_id - rc = @client.call(USER_METHODS[:chauth],@pe_id, auth) + rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password) rc = nil if !OpenNebula.is_error?(rc) return rc diff --git a/src/rm/RequestManagerUser.cc b/src/rm/RequestManagerUser.cc index d389cf8f1d..b7503323ac 100644 --- a/src/rm/RequestManagerUser.cc +++ b/src/rm/RequestManagerUser.cc @@ -81,8 +81,17 @@ int UserChangeAuth::user_action(User * user, string& error_str) { string new_auth = xmlrpc_c::value_string(paramList.getString(2)); + string new_pass = xmlrpc_c::value_string(paramList.getString(3)); - int rc = user->set_auth_driver(new_auth, error_str); + int rc; + + // The password may be invalid, try to change it first + rc = user->set_password(new_pass, error_str); + + if ( rc == 0 ) + { + rc = user->set_auth_driver(new_auth, error_str); + } if ( rc == 0 ) {