2010-05-28 02:27:29 +04:00
/* -------------------------------------------------------------------------- */
2023-01-09 14:23:19 +03:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
2010-05-28 02:27:29 +04:00
/* */
/* 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 AUTH_MANAGER_H_
# define AUTH_MANAGER_H_
2010-07-06 14:35:47 +04:00
# include <time.h>
2020-07-24 17:00:59 +03:00
# include "Listener.h"
2020-06-29 13:14:00 +03:00
# include "ProtocolMessages.h"
# include "DriverManager.h"
2010-05-28 02:27:29 +04:00
2012-01-02 22:21:54 +04:00
//Forward definitions
2010-07-06 14:35:47 +04:00
class AuthRequest ;
2010-05-28 02:27:29 +04:00
2020-06-29 13:14:00 +03:00
class AuthManager :
public DriverManager < Driver < auth_msg_t > > ,
2020-07-24 17:00:59 +03:00
public Listener
2010-05-28 02:27:29 +04:00
{
public :
AuthManager (
2020-07-24 17:00:59 +03:00
time_t timer ,
2023-02-02 14:48:43 +03:00
const std : : string & mads_location )
: DriverManager ( mads_location )
, Listener ( " Authorization Manager " )
, timer_thread ( timer , [ this ] ( ) { timer_action ( ) ; } )
, authz_enabled ( false )
2010-05-28 02:27:29 +04:00
{
2017-02-03 16:19:15 +03:00
}
2010-05-28 02:27:29 +04:00
/**
* This functions starts the associated listener thread , and creates a
2010-05-29 05:42:30 +04:00
* new thread for the AuthManager . This thread will wait in
2010-05-28 02:27:29 +04:00
* an action loop till it receives ACTION_FINALIZE .
* @ return 0 on success .
*/
int start ( ) ;
/**
* Loads Virtual Machine Manager Mads defined in configuration file
2020-06-29 13:14:00 +03:00
* @ param _mads configuration of drivers
2010-05-28 02:27:29 +04:00
*/
2020-06-29 13:14:00 +03:00
int load_drivers ( const std : : vector < const VectorAttribute * > & _mads ) ;
2010-05-28 02:27:29 +04:00
2012-04-11 19:58:57 +04:00
/**
* Returns true if there is an authorization driver enabled
*
* @ return true if there is an authorization driver enabled
*/
bool is_authz_enabled ( )
{
return authz_enabled ;
2020-06-29 13:14:00 +03:00
}
2012-04-11 19:58:57 +04:00
2010-05-28 02:27:29 +04:00
/**
2020-07-24 17:00:59 +03:00
* This function authenticates a user
2010-05-28 02:27:29 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_authenticate ( AuthRequest & ar ) ;
2010-05-28 02:27:29 +04:00
/**
2020-07-24 17:00:59 +03:00
* This function authorizes a user request
2010-05-28 02:27:29 +04:00
*/
2020-07-24 17:00:59 +03:00
void trigger_authorize ( AuthRequest & ar ) ;
2010-05-28 02:27:29 +04:00
2020-07-24 17:00:59 +03:00
private :
2010-07-06 14:35:47 +04:00
/**
2020-07-24 17:00:59 +03:00
* Timer action async execution
2010-07-06 14:35:47 +04:00
*/
2020-07-24 17:00:59 +03:00
Timer timer_thread ;
2010-05-28 02:27:29 +04:00
2010-07-08 20:50:32 +04:00
/**
* Generic name for the Auth driver
*/
2020-07-24 17:00:59 +03:00
static const char * auth_driver_name ;
2012-04-11 19:58:57 +04:00
/**
* True if there is an authorization driver enabled
*/
2020-07-24 17:00:59 +03:00
bool authz_enabled ;
/**
*
*/
static const int drivers_timeout = 10 ;
2010-07-08 20:50:32 +04:00
2010-05-28 02:27:29 +04:00
/**
* Returns a pointer to a Auth Manager driver .
* @ param name of an attribute of the driver ( e . g . its type )
* @ param value of the attribute
* @ return the Auth driver with attribute name equal to value
* or 0 in not found
*/
2020-07-05 23:01:32 +03:00
const Driver < auth_msg_t > * get ( const std : : string & name ) const
2010-05-28 02:27:29 +04:00
{
2020-06-29 13:14:00 +03:00
return DriverManager : : get_driver ( name ) ;
}
2010-05-28 02:27:29 +04:00
/**
* Returns a pointer to a Auth Manager driver . The driver is
* searched by its name .
* @ param name the name of the driver
* @ return the TM driver owned by uid with attribute name equal to value
* or 0 in not found
*/
2020-07-05 23:01:32 +03:00
const Driver < auth_msg_t > * get ( ) const
2010-05-28 02:27:29 +04:00
{
2020-06-29 13:14:00 +03:00
return DriverManager : : get_driver ( auth_driver_name ) ;
}
2010-05-28 02:27:29 +04:00
2020-06-29 13:14:00 +03:00
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
/**
*
*/
2020-07-02 23:42:10 +03:00
static void _undefined ( std : : unique_ptr < auth_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
/**
*
*/
2020-07-02 23:42:10 +03:00
void _authorize ( std : : unique_ptr < auth_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
/**
*
*/
2020-07-02 23:42:10 +03:00
void _authenticate ( std : : unique_ptr < auth_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
/**
*
*/
2020-07-02 23:42:10 +03:00
static void _log ( std : : unique_ptr < auth_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
2017-02-03 16:19:15 +03:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
2020-07-24 17:00:59 +03:00
void timer_action ( )
2017-02-03 16:19:15 +03:00
{
check_time_outs_action ( ) ;
2020-06-29 13:14:00 +03:00
}
2020-07-24 17:00:59 +03:00
void finalize_action ( ) override ;
2010-05-28 02:27:29 +04:00
} ;
# endif /*AUTH_MANAGER_H*/