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

feature #662: New authenticate method returns the GID

This commit is contained in:
Ruben S. Montero 2011-05-24 15:15:23 +02:00
parent 043cba4cee
commit c3e29e7f83
3 changed files with 45 additions and 15 deletions

View File

@ -105,12 +105,22 @@ public:
User::bootstrap(_db);
};
//TODO REMOVE THIS, HERE TO FIX COMPILATION
/**
* Returns whether there is a user with given username/password or not
* @param session, colon separated username and password string
* @return -1 if authn failed, uid of the user in other case
*/
int authenticate(string& session);
int authenticate(string& session){return 0;}
/**
* Returns whether there is a user with given username/password or not
* @param session, colon separated username and password string
* @param uid of the user if authN succeeded -1 otherwise
* @param gid of the user if authN succeeded -1 otherwise
* @return false if authn failed, true otherwise
*/
bool authenticate(const string& session, int& uid, int& gid);
/**
* Returns whether there is a user with given username/password or not

View File

@ -36,7 +36,7 @@ void Request::execute(
NebulaLog::log("ReM",Log::DEBUG, method_name + " method invoked");
if (true) // if ( upool->authenticate(uid, gid) == false )
if ( upool->authenticate(session, uid, gid) == false )
{
failure_response(RequestManager::AUTHENTICATION,
authenticate_error());

View File

@ -163,21 +163,25 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int UserPool::authenticate(string& session)
bool UserPool::authenticate(const string& session, int& user_id, int& group_id)
{
map<string, int>::iterator index;
User * user = 0;
string username;
string secret, u_pass;
int uid;
int user_id = -1;
int rc;
int uid, gid;
int rc;
bool result;
Nebula& nd = Nebula::instance();
AuthManager * authm = nd.get_authm();
user_id = -1;
group_id = -1;
result = false;
rc = User::split_secret(session,username,secret);
if ( rc != 0 )
@ -191,6 +195,7 @@ int UserPool::authenticate(string& session)
{
u_pass = user->password;
uid = user->oid;
gid = user->gid;
user->unlock();
}
@ -198,6 +203,7 @@ int UserPool::authenticate(string& session)
{
u_pass = "-";
uid = -1;
gid = -1;
}
AuthRequest ar(uid);
@ -208,14 +214,18 @@ int UserPool::authenticate(string& session)
{
if (ar.plain_authenticate())
{
user_id = 0;
user_id = 0;
group_id = GroupPool::ONEADMIN_ID;
result = true;
}
}
else if (authm == 0) //plain auth
{
if ( user != 0 && ar.plain_authenticate()) //no plain for external users
{
user_id = uid;
user_id = uid;
group_id = gid;
result = true;
}
}
else //use the driver
@ -227,7 +237,9 @@ int UserPool::authenticate(string& session)
{
if ( user != 0 ) //knwon user_id
{
user_id = uid;
user_id = uid;
group_id = gid;
result = true;
}
else //External user, username & pass in driver message
{
@ -244,8 +256,13 @@ int UserPool::authenticate(string& session)
if ( !is.fail() )
{
allocate(&user_id,GroupPool::USERS_ID,mad_name,mad_pass,
true,error_str);
allocate(&user_id,
GroupPool::USERS_ID,
mad_name,
mad_pass,
true,
error_str);
}
if ( user_id == -1 )
@ -256,12 +273,15 @@ int UserPool::authenticate(string& session)
". Driver response: " << ar.message;
ar.message = oss.str();
user_id = -1;
}
else
{
group_id = GroupPool::USERS_ID;
result = true;
}
}
}
if (user_id == -1)
else
{
ostringstream oss;
oss << "Auth Error: " << ar.message;
@ -270,7 +290,7 @@ int UserPool::authenticate(string& session)
}
}
return user_id;
return result;
}
/* -------------------------------------------------------------------------- */