pion-net  4.0.9
HTTPBasicAuth.hpp
1 // ------------------------------------------------------------------
2 // pion-net: a C++ framework for building lightweight HTTP interfaces
3 // ------------------------------------------------------------------
4 // Copyright (C) 2007-2008 Atomic Labs, Inc. (http://www.atomiclabs.com)
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_HTTPBASICAUTH_HEADER__
11 #define __PION_HTTPBASICAUTH_HEADER__
12 
13 #include <map>
14 #include <string>
15 #include <pion/PionConfig.hpp>
16 #include <pion/net/HTTPAuth.hpp>
17 #include <pion/PionDateTime.hpp> // order important , otherwise compiling error under win32
18 
19 
20 namespace pion { // begin namespace pion
21 namespace net { // begin namespace net (Pion Network Library)
22 
27 class PION_NET_API HTTPBasicAuth :
28  public HTTPAuth
29 {
30 public:
31 
33  HTTPBasicAuth(PionUserManagerPtr userManager, const std::string& realm="PION:NET");
34 
36  virtual ~HTTPBasicAuth() {}
37 
50  virtual bool handleRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn);
51 
60  virtual void setOption(const std::string& name, const std::string& value);
61 
62 
63 protected:
64 
71  void handleUnauthorized(HTTPRequestPtr& http_request, TCPConnectionPtr& tcp_conn);
72 
78  static bool parseAuthorization(std::string const &authorization, std::string &credentials);
79 
83  static bool parseCredentials(std::string const &credentials, std::string &username, std::string &password);
84 
85 
86 private:
87 
89  typedef std::map<std::string,std::pair<PionDateTime,PionUserPtr> > PionUserCache;
90 
92  static const unsigned int CACHE_EXPIRATION;
93 
94 
96  std::string m_realm;
97 
99  PionDateTime m_cache_cleanup_time;
100 
102  PionUserCache m_user_cache;
103 
105  mutable boost::mutex m_cache_mutex;
106 };
107 
108 
109 } // end namespace net
110 } // end namespace pion
111 
112 #endif
virtual ~HTTPBasicAuth()
virtual destructor
boost::posix_time::ptime PionDateTime
PionDateTime is a typedef for boost::posix_time::ptime.