#include <HTTPCookieAuth.hpp>
Inherits pion::net::HTTPAuth.
Definition at line 28 of file HTTPCookieAuth.hpp.
Public Member Functions | |
HTTPCookieAuth (PionUserManagerPtr userManager, const std::string &login="/login", const std::string &logout="/logout", const std::string &redirect="") | |
virtual | ~HTTPCookieAuth () |
virtual destructor | |
virtual bool | handleRequest (HTTPRequestPtr &request, TCPConnectionPtr &tcp_conn) |
virtual void | setOption (const std::string &name, const std::string &value) |
Protected Member Functions | |
bool | processLogin (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
void | handleUnauthorized (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
void | handleRedirection (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &redirection_url, const std::string &new_cookie="", bool delete_cookie=false) |
void | handleOk (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &new_cookie="", bool delete_cookie=false) |
void | expireCache (const PionDateTime &time_now) |
pion::net::HTTPCookieAuth::HTTPCookieAuth | ( | PionUserManagerPtr | userManager, | |
const std::string & | login = "/login" , |
|||
const std::string & | logout = "/logout" , |
|||
const std::string & | redirect = "" | |||
) |
default constructor
userManager | ||
login | - URL resource for login request. Typical login request has format: http://website/login?user="username"&pass="password"&url="redirection_url" | |
logout | - URL resource for logout request. Typical logout request has format: http://website/logout?url="redirection_url" | |
redirect | - if not empty, URL for redirection in case of authentication failure if empty - send code 401 on authentication failure |
Definition at line 30 of file HTTPCookieAuth.cpp.
References pion::net::HTTPAuth::setLogger().
void pion::net::HTTPCookieAuth::expireCache | ( | const PionDateTime & | time_now | ) | [protected] |
Cache expiration cleanup. (Call it periodically)
Definition at line 260 of file HTTPCookieAuth.cpp.
Referenced by handleRequest().
void pion::net::HTTPCookieAuth::handleOk | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn, | |||
const std::string & | new_cookie = "" , |
|||
bool | delete_cookie = false | |||
) | [protected] |
used to send OK responses with new cookie
http_request | the new HTTP request to handle | |
tcp_conn | the TCP connection that has the new request |
Definition at line 236 of file HTTPCookieAuth.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), pion::net::HTTPTypes::RESPONSE_CODE_NO_CONTENT, and pion::net::HTTPTypes::RESPONSE_MESSAGE_NO_CONTENT.
Referenced by processLogin().
void pion::net::HTTPCookieAuth::handleRedirection | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn, | |||
const std::string & | redirection_url, | |||
const std::string & | new_cookie = "" , |
|||
bool | delete_cookie = false | |||
) | [protected] |
used to send redirection responses
http_request | the new HTTP request to handle | |
tcp_conn | the TCP connection that has the new request |
Definition at line 198 of file HTTPCookieAuth.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), pion::net::HTTPTypes::HEADER_LOCATION, pion::net::HTTPTypes::RESPONSE_CODE_FOUND, and pion::net::HTTPTypes::RESPONSE_MESSAGE_FOUND.
Referenced by handleUnauthorized(), and processLogin().
bool pion::net::HTTPCookieAuth::handleRequest | ( | HTTPRequestPtr & | request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [virtual] |
attempts to validate authentication of a new HTTP request. If request valid, pointer to user identity object (if any) will be preserved in the request and return "true". If request not authenticated, appropriate response is sent over tcp_conn and return "false";
Note: if request matches "login" resource, then login sequences attempted. If "name" and "pass" attributes match user definition, a random cookie is created and associated with given user session. If request contains "url" attribute, then page redirection response returned. Otherwise - empty 204 response.
request | the new HTTP request to handle | |
tcp_conn | the TCP connection that has the new request |
Implements pion::net::HTTPAuth.
Definition at line 52 of file HTTPCookieAuth.cpp.
References expireCache(), handleUnauthorized(), pion::net::HTTPAuth::needAuthentication(), and processLogin().
void pion::net::HTTPCookieAuth::handleUnauthorized | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [protected] |
used to send responses when access to resource is not authorized
http_request | the new HTTP request to handle | |
tcp_conn | the TCP connection that has the new request |
Definition at line 170 of file HTTPCookieAuth.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), handleRedirection(), pion::net::HTTPTypes::RESPONSE_CODE_UNAUTHORIZED, and pion::net::HTTPTypes::RESPONSE_MESSAGE_UNAUTHORIZED.
Referenced by handleRequest(), and processLogin().
bool pion::net::HTTPCookieAuth::processLogin | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [protected] |
check if given request is a login/logout and process it
http_request | the new HTTP request to handle | |
tcp_conn | the TCP connection that has the new request |
Definition at line 104 of file HTTPCookieAuth.cpp.
References pion::net::HTTPTypes::base64_encode(), handleOk(), handleRedirection(), handleUnauthorized(), pion::net::HTTPAuth::m_user_manager, pion::net::HTTPServer::stripTrailingSlash(), and pion::net::HTTPTypes::url_decode().
Referenced by handleRequest().
void pion::net::HTTPCookieAuth::setOption | ( | const std::string & | name, | |
const std::string & | value | |||
) | [virtual] |
sets a configuration option Valid options:
name | the name of the option to change | |
value | the value of the option |
Reimplemented from pion::net::HTTPAuth.
Definition at line 92 of file HTTPCookieAuth.cpp.