diff --git a/include/Request.h b/include/Request.h index 8b194c11d5..2a79a504ac 100644 --- a/include/Request.h +++ b/include/Request.h @@ -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: /** diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 011f0d06fa..15d2f975cf 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -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; }; diff --git a/src/rm/Request.cc b/src/rm/Request.cc index bda4b23aac..e958e13e99 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -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()); +} diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ab73c43495..35dbeae9e5 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -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; } diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index 5e2da44574..c6a29097c8 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -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; } diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 7e56d7d0bc..da5c443183 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -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; }