mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-13 13:17:39 +03:00
This commit is contained in:
parent
532982b6fb
commit
70435d9043
@ -48,6 +48,7 @@ public:
|
||||
*/
|
||||
int allocate (
|
||||
int * oid,
|
||||
int gid,
|
||||
const string& hostname,
|
||||
const string& im_mad_name,
|
||||
const string& vmm_mad_name,
|
||||
|
113
include/RequestManagerUser.h
Normal file
113
include/RequestManagerUser.h
Normal file
@ -0,0 +1,113 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_USER_H
|
||||
#define REQUEST_MANAGER_USER_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerUser: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerUser(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
|
||||
auth_object = AuthRequest::USER;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerUser(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
virtual int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& error_str ) = 0;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserChangePassword : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserChangePassword():
|
||||
RequestManagerUser("UserChangePassword",
|
||||
"Changes user's password",
|
||||
"A:sis"){};
|
||||
~UserChangePassword(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserAddGroup : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserAddGroup():
|
||||
RequestManagerUser("UserAddGroup",
|
||||
"Adds a new group to the user",
|
||||
"A:sii"){};
|
||||
~UserAddGroup(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserDelGroup : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserDelGroup():
|
||||
RequestManagerUser("UserDelGroup",
|
||||
"Deletes a new group to the user",
|
||||
"A:sii"){};
|
||||
~UserDelGroup(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -103,6 +103,28 @@ public:
|
||||
return get_collection_copy();
|
||||
};
|
||||
|
||||
// *************************************************************************
|
||||
// Group IDs set Management
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Adds the User oid to the Main Group (gid), should be called after
|
||||
* the constructor.
|
||||
*/
|
||||
int add_group(int group_id)
|
||||
{
|
||||
return add_collection_id(group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the User ID from all the groups it belongs to. Must be called
|
||||
* before the User is dropped.
|
||||
*/
|
||||
int del_group(int group_id)
|
||||
{
|
||||
return del_collection_id(group_id);
|
||||
}
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
@ -154,6 +176,7 @@ private:
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// *************************************************************************
|
||||
@ -168,23 +191,6 @@ protected:
|
||||
|
||||
virtual ~User(){};
|
||||
|
||||
// *************************************************************************
|
||||
// Group IDs set Management
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Adds the User oid to the Main Group (gid), should be called after
|
||||
* the constructor.
|
||||
*/
|
||||
int add_to_group();
|
||||
|
||||
/**
|
||||
* Deletes the User ID from all the groups it belongs to. Must be called
|
||||
* before the User is dropped.
|
||||
*/
|
||||
int delete_from_groups();
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -94,7 +94,6 @@ public:
|
||||
*/
|
||||
int drop(User * user)
|
||||
{
|
||||
user->delete_from_groups();
|
||||
return PoolSQL::drop(user);
|
||||
};
|
||||
|
||||
|
@ -135,7 +135,8 @@ HostPool::HostPool(SqlDB* db,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::allocate (
|
||||
int * oid,
|
||||
int * oid,
|
||||
int gid,
|
||||
const string& hostname,
|
||||
const string& im_mad_name,
|
||||
const string& vmm_mad_name,
|
||||
@ -174,29 +175,12 @@ int HostPool::allocate (
|
||||
|
||||
// Build a new Host object
|
||||
|
||||
host = new Host(-1,
|
||||
ClusterPool::DEFAULT_CLUSTER_ID,
|
||||
hostname,
|
||||
im_mad_name,
|
||||
vmm_mad_name,
|
||||
tm_mad_name);
|
||||
host = new Host(-1, gid, hostname, im_mad_name, vmm_mad_name, tm_mad_name);
|
||||
|
||||
// Insert the Object in the pool
|
||||
|
||||
*oid = PoolSQL::allocate(host, error_str);
|
||||
|
||||
if( *oid != -1 )
|
||||
{
|
||||
// Add this Host's ID to its cluster
|
||||
|
||||
host = get(*oid, true);
|
||||
|
||||
host->add_to_cluster();
|
||||
|
||||
update( host );
|
||||
host->unlock();
|
||||
}
|
||||
|
||||
return *oid;
|
||||
|
||||
|
||||
|
@ -47,7 +47,6 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_cluster',
|
||||
'nebula_host',
|
||||
'nebula_vnm',
|
||||
'nebula_vm',
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "RequestManagerPublish.h"
|
||||
#include "RequestManagerAllocate.h"
|
||||
#include "RequestManagerUpdateTemplate.h"
|
||||
#include "RequestManagerUser.h"
|
||||
|
||||
#include "RequestManagerVirtualNetwork.h"
|
||||
#include "RequestManagerVirtualMachine.h"
|
||||
@ -225,7 +226,12 @@ void RequestManager::do_action(
|
||||
|
||||
void RequestManager::register_xml_methods()
|
||||
{
|
||||
// VirtualMachine Methods
|
||||
// User Methods
|
||||
xmlrpc_c::methodPtr user_change_password(new UserChangePassword());
|
||||
xmlrpc_c::methodPtr user_add_group(new UserAddGroup());
|
||||
xmlrpc_c::methodPtr user_del_group(new UserDelGroup());
|
||||
|
||||
// VirtualMachine Template Methods
|
||||
xmlrpc_c::methodPtr template_instantiate(new VMTemplateInstantiate());
|
||||
|
||||
// VirtualMachine Methods
|
||||
@ -314,8 +320,6 @@ void RequestManager::register_xml_methods()
|
||||
RequestManager::GenericChown(this,AuthRequest::NET));
|
||||
|
||||
|
||||
xmlrpc_c::methodPtr user_change_password(new
|
||||
RequestManager::UserChangePassword(upool));
|
||||
|
||||
xmlrpc_c::methodPtr user_chown(new
|
||||
RequestManager::GenericChown(this,USER));
|
||||
@ -403,14 +407,14 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
/* User related methods*/
|
||||
/*
|
||||
RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
|
||||
RequestManagerRegistry.addMethod("one.user.chown", user_chown);
|
||||
RequestManagerRegistry.addMethod("one.user.addgroup", user_addgroup);
|
||||
RequestManagerRegistry.addMethod("one.user.delgroup", user_delgroup);
|
||||
*/
|
||||
RequestManagerRegistry.addMethod("one.user.allocate", user_allocate);
|
||||
RequestManagerRegistry.addMethod("one.user.delete", user_delete);
|
||||
RequestManagerRegistry.addMethod("one.user.info", user_info);
|
||||
RequestManagerRegistry.addMethod("one.user.addgroup", user_add_group);
|
||||
RequestManagerRegistry.addMethod("one.user.delgroup", user_del_group);
|
||||
RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
|
||||
|
||||
|
@ -240,7 +240,7 @@ int HostAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
HostPool * hpool = static_cast<HostPool *>(pool);
|
||||
|
||||
return hpool->allocate(&id, host, im_mad, vmm_mad, tm_mad, error_str);
|
||||
return hpool->allocate(&id,gid, host, im_mad, vmm_mad, tm_mad, error_str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -40,7 +40,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
return;
|
||||
}
|
||||
|
||||
if ( auth_ob == AuthRequest::USER )
|
||||
if ( auth_object == AuthRequest::USER )
|
||||
{
|
||||
User * user = static_cast<User *>(object);
|
||||
group_set = user->get_groups();
|
||||
@ -56,7 +56,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
return;
|
||||
}
|
||||
|
||||
if ( auth_ob == AuthRequest::USER )
|
||||
if ( auth_object == AuthRequest::USER )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
|
170
src/rm/RequestManagerUser.cc
Normal file
170
src/rm/RequestManagerUser.cc
Normal file
@ -0,0 +1,170 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManagerUser.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void RequestManagerUser::
|
||||
request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
User * user;
|
||||
string error_str;
|
||||
|
||||
if ( basic_authorization(id) == false ) //TODO REALLY NEED TO ADD GROUP HERE?
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
user = static_cast<User *>(pool->get(id,true));
|
||||
|
||||
if ( user == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),id));
|
||||
return;
|
||||
}
|
||||
|
||||
if ( user_action(user,paramList,error_str) < 0 )
|
||||
{
|
||||
failure_response(INTERNAL, error_str); //TODO
|
||||
}
|
||||
|
||||
success_response(id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserChangePassword::user_action(User * user,
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
string& error_str)
|
||||
{
|
||||
|
||||
string new_pass = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
user->set_password(new_pass);
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserAddGroup::user_action(User * user,
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
string& error_str)
|
||||
{
|
||||
|
||||
int user_id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int group_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int rc;
|
||||
|
||||
rc = user->add_group(group_id);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
user->unlock();
|
||||
|
||||
error_str = "Can not add group to user";
|
||||
return rc;
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
Group * group = gpool->get(gid, true);
|
||||
|
||||
if( group == 0 )
|
||||
{
|
||||
User * user = static_cast<User *>(pool->get(user_id,true));
|
||||
|
||||
if ( user != 0 )
|
||||
{
|
||||
user->del_group(group_id);
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
|
||||
error_str = "Group does not exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
group->add_user(user_id);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int UserDelGroup::user_action(User * user,
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
string& error_str)
|
||||
{
|
||||
|
||||
int user_id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int group_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int rc;
|
||||
|
||||
rc = user->del_group(group_id);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
user->unlock();
|
||||
|
||||
error_str = "Can not remove group from user";
|
||||
return rc;
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
Group * group = gpool->get(gid, true);
|
||||
|
||||
if( group == 0 )
|
||||
{
|
||||
//Group does not exists, should never occur
|
||||
error_str = "Can not remove user from group";
|
||||
return -1;
|
||||
}
|
||||
|
||||
group->del_user(user_id);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -34,6 +34,7 @@ source_files=[
|
||||
'RequestManagerVirtualMachine.cc',
|
||||
'RequestManagerVMTemplate.cc',
|
||||
'RequestManagerUpdateTemplate.cc',
|
||||
'RequestManagerUser.cc',
|
||||
|
||||
# 'RequestManagerAction.cc',
|
||||
# 'RequestManagerAllocate.cc',
|
||||
|
@ -124,7 +124,6 @@ int UserPool::allocate (
|
||||
{
|
||||
User * user;
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
if ( username.empty() )
|
||||
{
|
||||
@ -154,11 +153,6 @@ error_duplicated:
|
||||
oss << "NAME is already taken by USER " << user->get_oid() << ".";
|
||||
goto error_common;
|
||||
|
||||
error_group:
|
||||
oss << "Error trying to add USER to group " << gid << ".";
|
||||
drop( user );
|
||||
user->unlock();
|
||||
|
||||
error_common:
|
||||
*oid = -1;
|
||||
error_str = oss.str();
|
||||
|
Loading…
x
Reference in New Issue
Block a user