10 #ifndef __PION_HTTP_AUTH_HEADER__ 11 #define __PION_HTTP_AUTH_HEADER__ 15 #include <boost/noncopyable.hpp> 16 #include <boost/shared_ptr.hpp> 17 #include <pion/config.hpp> 18 #include <pion/error.hpp> 19 #include <pion/logger.hpp> 20 #include <pion/hash_map.hpp> 21 #include <pion/tcp/connection.hpp> 22 #include <pion/user.hpp> 23 #include <pion/http/request.hpp> 24 #include <boost/date_time/posix_time/posix_time.hpp> 35 private boost::noncopyable
40 auth(user_manager_ptr userManager)
41 : m_logger(PION_GET_LOGGER(
"pion.http.auth")),
42 m_user_manager(userManager)
60 virtual bool handle_request(
const http::request_ptr& http_request_ptr,
const tcp::connection_ptr& tcp_conn) = 0;
68 virtual void set_option(
const std::string& name,
const std::string& value) {
69 BOOST_THROW_EXCEPTION(
error::bad_arg() << error::errinfo_arg_name(name) );
77 void add_restrict(
const std::string& resource);
84 void add_permit(
const std::string& resource);
91 virtual bool add_user(std::string
const &username, std::string
const &password) {
92 return m_user_manager->add_user(username, password);
100 virtual bool update_user(std::string
const &username, std::string
const &password) {
101 return m_user_manager->update_user(username, password);
110 return m_user_manager->remove_user(username);
116 virtual user_ptr
get_user(std::string
const &username) {
117 return m_user_manager->get_user(username);
127 typedef std::map<std::string,std::pair<boost::posix_time::ptime,user_ptr> >
user_cache_type;
135 bool need_authentication(http::request_ptr
const& http_request_ptr)
const;
145 bool find_resource(
const resource_set_type& resource_set,
146 const std::string& resource)
const;
169 typedef boost::shared_ptr<auth> auth_ptr;
virtual bool update_user(std::string const &username, std::string const &password)
virtual bool remove_user(std::string const &username)
virtual ~auth()
virtual destructor
virtual bool add_user(std::string const &username, std::string const &password)
user_manager_ptr m_user_manager
container used to manager user objects
resource_set_type m_white_list
collection of resources that do NOT require authentication
boost::mutex m_resource_mutex
mutex used to protect access to the resources
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
virtual void set_option(const std::string &name, const std::string &value)
void set_logger(logger log_ptr)
sets the logger to be used
logger m_logger
primary logging interface used by this class
virtual user_ptr get_user(std::string const &username)
exception thrown for an invalid configuration argument or option
auth(user_manager_ptr userManager)
default constructor
std::set< std::string > resource_set_type
data type for a set of resources to be authenticated
resource_set_type m_restrict_list
collection of resources that require authentication