1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

feature #662: Better error messages for authZ operations

This commit is contained in:
Ruben S. Montero 2011-06-04 02:51:50 +02:00
parent 6caa5cf2c5
commit e3a930dd10
6 changed files with 64 additions and 75 deletions

View File

@ -137,16 +137,10 @@ protected:
/**
* Logs authorization errors
* @param action authorization action
* @param object object that needs to be authorized
* @param uid user that is authorized
* @param id id of the object, -1 for Pool
* @param message with the authorization error details
* @return string for logging
*/
string authorization_error (const string &action,
const string &object,
int uid,
int id);
string authorization_error (const string &message);
/**
* Logs authenticate errors
* @return string for logging
@ -175,6 +169,19 @@ protected:
const string &object,
int id,
int rc);
/**
* Logs allocate errors
* @param message with the allocate error details
* @return string for logging
*/
string allocate_error (const string& error);
/**
* Logs allocate errors
* @param message with the allocate error details (parsing)
* @return string for logging
*/
string allocate_error (char *error);
private:
/**

View File

@ -50,10 +50,6 @@ protected:
virtual bool allocate_authorization(Template * obj_template);
string allocate_error (char *error);
string allocate_error (const string& error);
/* -------------------------------------------------------------------- */
virtual Template * get_object_template() { return 0; };

View File

@ -85,8 +85,7 @@ bool Request::basic_authorization(int oid)
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO",object_name(auth_object),oid,-1));
failure_response(AUTHORIZATION, authorization_error(ar.message));
return false;
}
@ -173,24 +172,17 @@ string Request::object_name(AuthRequest::Object ob)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string Request::authorization_error (const string &action,
const string &object,
int uid,
int id)
string Request::authorization_error (const string &message)
{
ostringstream oss;
oss << "[" << method_name << "]" << " User [" << uid << "] not authorized"
<< " to perform " << action << " on " << object;
<< " to perform action on " << object_name(auth_object) << ".";
if ( id != -1 )
if ( !message.empty() )
{
oss << " [" << id << "].";
}
else
{
oss << " Pool";
oss << message ;
}
return oss.str();
@ -260,3 +252,43 @@ string Request::action_error (const string &action,
return oss.str();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string Request::allocate_error (const string& error)
{
ostringstream oss;
oss << "[" << method_name << "]" << " Error allocating a new "
<< object_name(auth_object) << ".";
if (!error.empty())
{
oss << " " << error;
}
return oss.str();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string Request::allocate_error (char *error)
{
ostringstream oss;
oss << "Parse error";
if ( error != 0 )
{
oss << ": " << error;
free(error);
}
else
{
oss << ".";
}
return allocate_error(oss.str());
}

View File

@ -19,45 +19,6 @@
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string RequestManagerAllocate::allocate_error (const string& error)
{
ostringstream oss;
oss << "[" << method_name << "]" << " Error allocating a new "
<< object_name(auth_object) << ".";
if (!error.empty())
{
oss << " " << error;
}
return oss.str();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string RequestManagerAllocate::allocate_error (char *error)
{
ostringstream oss;
oss << "Parse error";
if ( error != 0 )
{
oss << ": " << error;
free(error);
}
else
{
oss << ".";
}
return allocate_error(oss.str());
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -84,9 +45,7 @@ bool RequestManagerAllocate::allocate_authorization(Template * tmpl)
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO","USER",uid,-1));
failure_response(AUTHORIZATION, authorization_error(ar.message));
return false;
}
@ -114,9 +73,7 @@ bool VirtualMachineAllocate::allocate_authorization(Template * tmpl)
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO","USER",uid,-1));
failure_response(AUTHORIZATION, authorization_error(ar.message));
return false;
}

View File

@ -62,8 +62,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO",object_name(auth_object),id,-1));
failure_response(AUTHORIZATION, authorization_error(ar.message));
delete tmpl;
return;
}

View File

@ -64,9 +64,7 @@ bool RequestManagerVirtualMachine::vm_authorization(int oid, int hid, ImageTempl
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO",object_name(auth_object),oid,-1));
failure_response(AUTHORIZATION, authorization_error(ar.message));
return false;
}