pion  5.0.6
basic_auth.hpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_HTTP_BASIC_AUTH_HEADER__
11 #define __PION_HTTP_BASIC_AUTH_HEADER__
12 
13 #include <map>
14 #include <string>
15 #include <pion/config.hpp>
16 #include <pion/http/auth.hpp>
17 
18 
19 namespace pion { // begin namespace pion
20 namespace http { // begin namespace http
21 
26 class PION_API basic_auth :
27  public http::auth
28 {
29 public:
30 
32  basic_auth(user_manager_ptr userManager, const std::string& realm="PION");
33 
35  virtual ~basic_auth() {}
36 
49  virtual bool handle_request(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
50 
59  virtual void set_option(const std::string& name, const std::string& value);
60 
61 
62 protected:
63 
70  void handle_unauthorized(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
71 
77  static bool parse_authorization(std::string const &authorization, std::string &credentials);
78 
82  static bool parse_credentials(std::string const &credentials, std::string &username, std::string &password);
83 
84 
85 private:
86 
88  static const unsigned int CACHE_EXPIRATION;
89 
90 
92  std::string m_realm;
93 
95  boost::posix_time::ptime m_cache_cleanup_time;
96 
98  user_cache_type m_user_cache;
99 
101  mutable boost::mutex m_cache_mutex;
102 };
103 
104 
105 } // end namespace http
106 } // end namespace pion
107 
108 #endif
virtual ~basic_auth()
virtual destructor
Definition: basic_auth.hpp:35