pion::net::HTTPCookieAuth Class Reference

#include <HTTPCookieAuth.hpp>

Inherits pion::net::HTTPAuth.

List of all members.


Detailed Description

HTTPCookieAuth: handles HTTP authentication and session management in accordance with RFC 2617 (http://tools.ietf.org/html/rfc2617 ) using cookies.

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)


Constructor & Destructor Documentation

pion::net::HTTPCookieAuth::HTTPCookieAuth ( PionUserManagerPtr  userManager,
const std::string &  login = "/login",
const std::string &  logout = "/logout",
const std::string &  redirect = "" 
)

default constructor

Parameters:
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().


Member Function Documentation

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

Parameters:
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

Parameters:
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.

Parameters:
request the new HTTP request to handle
tcp_conn the TCP connection that has the new request
Returns:
true if request valid and user identity inserted into 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

Parameters:
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

Parameters:
http_request the new HTTP request to handle
tcp_conn the TCP connection that has the new request
Returns:
true if it was a login/logout request and no future processing required.

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:

Parameters:
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.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 14:48:54 2010 for pion-net by  doxygen 1.4.7