00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PION_HTTP_BASIC_AUTH_HEADER__
00011 #define __PION_HTTP_BASIC_AUTH_HEADER__
00012
00013 #include <map>
00014 #include <string>
00015 #include <pion/config.hpp>
00016 #include <pion/http/auth.hpp>
00017
00018
00019 namespace pion {
00020 namespace http {
00021
00026 class PION_API basic_auth :
00027 public http::auth
00028 {
00029 public:
00030
00032 basic_auth(user_manager_ptr userManager, const std::string& realm="PION");
00033
00035 virtual ~basic_auth() {}
00036
00049 virtual bool handle_request(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
00050
00059 virtual void set_option(const std::string& name, const std::string& value);
00060
00061
00062 protected:
00063
00070 void handle_unauthorized(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
00071
00077 static bool parse_authorization(std::string const &authorization, std::string &credentials);
00078
00082 static bool parse_credentials(std::string const &credentials, std::string &username, std::string &password);
00083
00084
00085 private:
00086
00088 static const unsigned int CACHE_EXPIRATION;
00089
00090
00092 std::string m_realm;
00093
00095 boost::posix_time::ptime m_cache_cleanup_time;
00096
00098 user_cache_type m_user_cache;
00099
00101 mutable boost::mutex m_cache_mutex;
00102 };
00103
00104
00105 }
00106 }
00107
00108 #endif