cookie_auth.hpp
// ---------------------------------------------------------------------
// pion: a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//
#ifndef __PION_HTTP_COOKIE_AUTH_HEADER__
#define __PION_HTTP_COOKIE_AUTH_HEADER__
#include <map>
#include <string>
#include <boost/random.hpp>
#include <pion/config.hpp>
#include <pion/http/auth.hpp>
namespace pion { // begin namespace pion
namespace http { // begin namespace http
class PION_API cookie_auth :
public http::auth
{
public:
cookie_auth(user_manager_ptr userManager,
const std::string& login="/login",
const std::string& logout="/logout",
const std::string& redirect="");
virtual ~cookie_auth() {}
virtual bool handle_request(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn);
virtual void set_option(const std::string& name, const std::string& value);
protected:
bool process_login(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn);
void handle_unauthorized(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn);
void handle_redirection(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn,
const std::string &redirection_url, const std::string &new_cookie="", bool delete_cookie=false);
void handle_ok(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn,
const std::string &new_cookie="", bool delete_cookie=false);
void expire_cache(const boost::posix_time::ptime &time_now);
private:
static const unsigned int CACHE_EXPIRATION;
static const unsigned int RANDOM_COOKIE_BYTES;
static const std::string AUTH_COOKIE_NAME;
std::string m_login;
std::string m_logout;
std::string m_redirect;
boost::mt19937 m_random_gen;
boost::uniform_int<> m_random_range;
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_random_die;
boost::posix_time::ptime m_cache_cleanup_time;
user_cache_type m_user_cache;
mutable boost::mutex m_cache_mutex;
};
} // end namespace http
} // end namespace pion
#endif
pion::http::cookie_auth::~cookie_auth
virtual ~cookie_auth()
virtual destructor
Definition: cookie_auth.hpp:50
pion::http::cookie_auth
Definition: cookie_auth.hpp:28
pion::http::auth
Definition: auth.hpp:34
pion
Definition: admin_rights.hpp:19