pion-net
4.0.9
|
00001 // ------------------------------------------------------------------ 00002 // pion-net: a C++ framework for building lightweight HTTP interfaces 00003 // ------------------------------------------------------------------ 00004 // Copyright (C) 2007-2008 Atomic Labs, Inc. (http://www.atomiclabs.com) 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // See http://www.boost.org/LICENSE_1_0.txt 00008 // 00009 00010 #ifndef __PION_HTTPBASICAUTH_HEADER__ 00011 #define __PION_HTTPBASICAUTH_HEADER__ 00012 00013 #include <map> 00014 #include <string> 00015 #include <pion/PionConfig.hpp> 00016 #include <pion/net/HTTPAuth.hpp> 00017 #include <pion/PionDateTime.hpp> // order important , otherwise compiling error under win32 00018 00019 00020 namespace pion { // begin namespace pion 00021 namespace net { // begin namespace net (Pion Network Library) 00022 00027 class PION_NET_API HTTPBasicAuth : 00028 public HTTPAuth 00029 { 00030 public: 00031 00033 HTTPBasicAuth(PionUserManagerPtr userManager, const std::string& realm="PION:NET"); 00034 00036 virtual ~HTTPBasicAuth() {} 00037 00050 virtual bool handleRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn); 00051 00060 virtual void setOption(const std::string& name, const std::string& value); 00061 00062 00063 protected: 00064 00071 void handleUnauthorized(HTTPRequestPtr& http_request, TCPConnectionPtr& tcp_conn); 00072 00078 static bool parseAuthorization(std::string const &authorization, std::string &credentials); 00079 00083 static bool parseCredentials(std::string const &credentials, std::string &username, std::string &password); 00084 00085 00086 private: 00087 00089 typedef std::map<std::string,std::pair<PionDateTime,PionUserPtr> > PionUserCache; 00090 00092 static const unsigned int CACHE_EXPIRATION; 00093 00094 00096 std::string m_realm; 00097 00099 PionDateTime m_cache_cleanup_time; 00100 00102 PionUserCache m_user_cache; 00103 00105 mutable boost::mutex m_cache_mutex; 00106 }; 00107 00108 00109 } // end namespace net 00110 } // end namespace pion 00111 00112 #endif