- Main Page
- Classes
- Files

- File List

# include/pion/http/cookie_auth.hpp

    00001 // ---------------------------------------------------------------------
    00002 // pion:  a Boost C++ framework for building lightweight HTTP interfaces
    00003 // ---------------------------------------------------------------------
    00004 // Copyright (C) 2007-2014 Splunk Inc.  (https://github.com/splunk/pion)
    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_HTTP_COOKIE_AUTH_HEADER__
    00011 #define __PION_HTTP_COOKIE_AUTH_HEADER__
    00012
    00013 #include <map>
    00014 #include <string>
    00015 #include <boost/random.hpp>
    00016 #include <pion/config.hpp>
    00017 #include <pion/http/auth.hpp>
    00018
    00019
    00020 namespace pion {    // begin namespace pion
    00021 namespace http {    // begin namespace http
    00022
    00023
    00028 class PION_API cookie_auth :
    00029     public http::auth
    00030 {
    00031 public:
    00032
    00044     cookie_auth(user_manager_ptr userManager,
    00045         const std::string& login="/login",
    00046         const std::string& logout="/logout",
    00047         const std::string& redirect="");
    00048
    00050     virtual ~cookie_auth() {}
    00051
    00069     virtual bool handle_request(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
    00070
    00084     virtual void set_option(const std::string& name, const std::string& value);
    00085
    00086
    00087 protected:
    00088
    00097     bool process_login(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
    00098
    00105     void handle_unauthorized(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn);
    00106
    00113     void handle_redirection(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn,
    00114         const std::string &redirection_url, const std::string &new_cookie="", bool delete_cookie=false);
    00115
    00122     void handle_ok(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn,
    00123         const std::string &new_cookie="", bool delete_cookie=false);
    00124
    00128     void expire_cache(const boost::posix_time::ptime &time_now);
    00129
    00130
    00131 private:
    00132
    00134     static const unsigned int   CACHE_EXPIRATION;
    00135
    00137     static const unsigned int   RANDOM_COOKIE_BYTES;
    00138
    00140     static const std::string    AUTH_COOKIE_NAME;
    00141
    00143     std::string                 m_login;
    00144
    00146     std::string                 m_logout;
    00147
    00149     std::string                 m_redirect;
    00150
    00152     boost::mt19937              m_random_gen;
    00153
    00155     boost::uniform_int<>        m_random_range;
    00156
    00158     boost::variate_generator<boost::mt19937&, boost::uniform_int<> >    m_random_die;
    00159
    00161     boost::posix_time::ptime    m_cache_cleanup_time;
    00162
    00164     user_cache_type             m_user_cache;
    00165
    00167     mutable boost::mutex        m_cache_mutex;
    00168 };
    00169
    00170
    00171 }   // end namespace http
    00172 }   // end namespace pion
    00173
    00174 #endif