PionNetworkLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pion::http::auth Class Referenceabstract

#include <auth.hpp>

Inheritance diagram for pion::http::auth:
Collaboration diagram for pion::http::auth:

Public Member Functions

 auth (user_manager_ptr userManager)
 default constructor More...
 
virtual ~auth ()
 virtual destructor More...
 
virtual bool handle_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn)=0
 
virtual void set_option (const std::string &name, const std::string &)
 
void add_restrict (const std::string &resource)
 
void add_permit (const std::string &resource)
 
virtual bool add_user (std::string const &username, std::string const &password)
 
virtual bool update_user (std::string const &username, std::string const &password)
 
virtual bool remove_user (std::string const &username)
 
virtual user_ptr get_user (std::string const &username)
 

Protected Types

typedef std::set< std::string > resource_set_type
 data type for a set of resources to be authenticated More...
 
typedef std::map< std::string,
std::pair
< boost::posix_time::ptime,
user_ptr > > 
user_cache_type
 data type used to map authentication credentials to user objects More...
 

Protected Member Functions

bool need_authentication (http::request_ptr const &http_request_ptr) const
 
bool find_resource (const resource_set_type &resource_set, const std::string &resource) const
 
void set_logger (logger log_ptr)
 sets the logger to be used More...
 

Protected Attributes

logger m_logger
 primary logging interface used by this class More...
 
user_manager_ptr m_user_manager
 container used to manager user objects More...
 
resource_set_type m_restrict_list
 collection of resources that require authentication More...
 
resource_set_type m_white_list
 collection of resources that do NOT require authentication More...
 
boost::mutex m_resource_mutex
 mutex used to protect access to the resources More...
 

Detailed Description

auth: a base class for handling HTTP Authentication and session management

Member Typedef Documentation

typedef std::set<std::string> pion::http::auth::resource_set_type
protected

data type for a set of resources to be authenticated

typedef std::map<std::string,std::pair<boost::posix_time::ptime,user_ptr> > pion::http::auth::user_cache_type
protected

data type used to map authentication credentials to user objects

Constructor & Destructor Documentation

pion::http::auth::auth ( user_manager_ptr  userManager)
inline

default constructor

virtual pion::http::auth::~auth ( )
inlinevirtual

virtual destructor

Member Function Documentation

void pion::http::auth::add_permit ( const std::string &  resource)

adds a resource that does NOT require authentication

Parameters
resourcethe resource name or uri-stem that does not require authentication

References m_logger, m_resource_mutex, m_white_list, PION_LOG_INFO, and pion::http::server::strip_trailing_slash().

void pion::http::auth::add_restrict ( const std::string &  resource)

adds a resource that requires authentication

Parameters
resourcethe resource name or uri-stem that requires authentication

References m_logger, m_resource_mutex, m_restrict_list, PION_LOG_INFO, and pion::http::server::strip_trailing_slash().

virtual bool pion::http::auth::add_user ( std::string const &  username,
std::string const &  password 
)
inlinevirtual

used to add a new user

@ return false if user with such name already exists

bool pion::http::auth::find_resource ( const resource_set_type resource_set,
const std::string &  resource 
) const
protected

tries to find a resource in a given collection

Parameters
resource_setthe collection of resource to look in
resourcethe resource to look for
Returns
true if the resource was found

Referenced by need_authentication().

virtual user_ptr pion::http::auth::get_user ( std::string const &  username)
inlinevirtual

Used to locate user object by username

virtual bool pion::http::auth::handle_request ( const http::request_ptr http_request_ptr,
const tcp::connection_ptr tcp_conn 
)
pure virtual

attempts to validate authentication of a new HTTP request. If request valid, pointer to user identity object (if any) will be preserved in the request and return "true". If request not authenticated, appropriate response is sent over tcp_conn and return "false";

Parameters
http_request_ptrthe new HTTP request to handle
tcp_connthe TCP connection that has the new request
Returns
true if request valid and user identity inserted into request

Implemented in pion::http::cookie_auth, and pion::http::basic_auth.

bool pion::http::auth::need_authentication ( http::request_ptr const &  http_request_ptr) const
protected

check if given HTTP request requires authentication

Parameters
http_request_ptrthe HTTP request to check

References find_resource(), m_resource_mutex, m_restrict_list, m_user_manager, m_white_list, and pion::http::server::strip_trailing_slash().

Referenced by pion::http::basic_auth::handle_request(), and pion::http::cookie_auth::handle_request().

virtual bool pion::http::auth::remove_user ( std::string const &  username)
inlinevirtual

used to remove given user

Returns
false if no user with such username
void pion::http::auth::set_logger ( logger  log_ptr)
inlineprotected

sets the logger to be used

Referenced by pion::http::basic_auth::basic_auth(), and pion::http::cookie_auth::cookie_auth().

virtual void pion::http::auth::set_option ( const std::string &  name,
const std::string &   
)
inlinevirtual

sets a configuration option

Parameters
namethe name of the option to change
valuethe value of the option

Reimplemented in pion::http::cookie_auth, and pion::http::basic_auth.

virtual bool pion::http::auth::update_user ( std::string const &  username,
std::string const &  password 
)
inlinevirtual

update password for given user

Returns
false if user with such a name doesn't exist

Member Data Documentation

logger pion::http::auth::m_logger
mutableprotected

primary logging interface used by this class

Referenced by add_permit(), and add_restrict().

boost::mutex pion::http::auth::m_resource_mutex
mutableprotected

mutex used to protect access to the resources

Referenced by add_permit(), add_restrict(), and need_authentication().

resource_set_type pion::http::auth::m_restrict_list
protected

collection of resources that require authentication

Referenced by add_restrict(), and need_authentication().

user_manager_ptr pion::http::auth::m_user_manager
protected
resource_set_type pion::http::auth::m_white_list
protected

collection of resources that do NOT require authentication

Referenced by add_permit(), and need_authentication().


The documentation for this class was generated from the following files: