diff --git a/include/RequestManagerUser.h b/include/RequestManagerUser.h index 507bc38c60..6730cc9f09 100644 --- a/include/RequestManagerUser.h +++ b/include/RequestManagerUser.h @@ -72,6 +72,23 @@ public: string& err); }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class UserChangeAuth: public RequestManagerUser +{ +public: + UserChangeAuth(): + RequestManagerUser("UserChangeAuth", + "Changes user's authentication driver", + "A:sis"){}; + ~UserChangeAuth(){}; + + int user_action(User * user, + xmlrpc_c::paramList const& _paramList, + string& err); +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/User.h b/include/User.h index edf0d19e70..8b9db80536 100644 --- a/include/User.h +++ b/include/User.h @@ -131,6 +131,20 @@ public: return rc; }; + /** + * Sets the user auth driver. + * + * @param _auth_driver the new auth. driver + * @param error_str Returns the error reason, if any + * @return 0 on success, -1 otherwise + */ + int set_auth_driver(const string& _auth_driver, string& error_str) + { + auth_driver = _auth_driver; + + return 0; + }; + /** * Splits an authentication token (:) * @param secret, the authentication token diff --git a/src/cli/oneuser b/src/cli/oneuser index 3deb422500..d6a95ef975 100755 --- a/src/cli/oneuser +++ b/src/cli/oneuser @@ -259,6 +259,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do end end + chauth_desc = <<-EOT.unindent + Changes the User's auth driver + EOT + + command :chauth, chauth_desc, [:range, :userid_list], :auth do + helper = OneUserHelper.new + helper.perform_actions(args[0],options,"Auth driver changed") do |user| + user.chauth(args[1]) + end + end + list_desc = <<-EOT.unindent Lists Users in the pool EOT diff --git a/src/oca/ruby/OpenNebula/User.rb b/src/oca/ruby/OpenNebula/User.rb index 2f0673e50c..e5e1a57d41 100644 --- a/src/oca/ruby/OpenNebula/User.rb +++ b/src/oca/ruby/OpenNebula/User.rb @@ -29,7 +29,8 @@ module OpenNebula :delete => "user.delete", :passwd => "user.passwd", :chgrp => "user.chgrp", - :update => "user.update" + :update => "user.update", + :chauth => "user.chauth" } SELF = -1 @@ -115,6 +116,20 @@ module OpenNebula return rc end + # Changes the auth driver + # + # @param auth [String] the new auth driver + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def chauth(auth) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(USER_METHODS[:chauth],@pe_id, auth) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end + ####################################################################### # Helpers to get User information ####################################################################### diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 445f3b6f43..f555f0337f 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -232,6 +232,7 @@ void RequestManager::register_xml_methods() { // User Methods xmlrpc_c::methodPtr user_change_password(new UserChangePassword()); + xmlrpc_c::methodPtr user_change_auth(new UserChangeAuth()); // VMTemplate Methods xmlrpc_c::methodPtr template_instantiate(new VMTemplateInstantiate()); @@ -371,6 +372,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.user.info", user_info); RequestManagerRegistry.addMethod("one.user.passwd", user_change_password); RequestManagerRegistry.addMethod("one.user.chgrp", user_chown); + RequestManagerRegistry.addMethod("one.user.chauth", user_change_auth); RequestManagerRegistry.addMethod("one.userpool.info", userpool_info); diff --git a/src/rm/RequestManagerUser.cc b/src/rm/RequestManagerUser.cc index 2dcb17401d..d389cf8f1d 100644 --- a/src/rm/RequestManagerUser.cc +++ b/src/rm/RequestManagerUser.cc @@ -73,6 +73,27 @@ int UserChangePassword::user_action(User * user, return rc; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int UserChangeAuth::user_action(User * user, + xmlrpc_c::paramList const& paramList, + string& error_str) +{ + string new_auth = xmlrpc_c::value_string(paramList.getString(2)); + + int rc = user->set_auth_driver(new_auth, error_str); + + if ( rc == 0 ) + { + pool->update(user); + } + + user->unlock(); + + return rc; +} + /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */