1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Bug #847 - #918: Add method to change user auth driver in core, ruby oca and CLI

This commit is contained in:
Carlos Martín 2011-10-17 15:08:00 +02:00
parent 30a9162f5e
commit d2e781cd27
6 changed files with 81 additions and 1 deletions

View File

@ -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);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -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 (<usr>:<pass>)
* @param secret, the authentication token

View File

@ -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

View File

@ -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
#######################################################################

View File

@ -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);

View File

@ -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;
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */