8 #ifndef MOD_SERVLET_SESSION_H
9 #define MOD_SERVLET_SESSION_H
13 #include <experimental/string_view>
20 std::string generate_session_id();
22 using std::experimental::string_view;
23 using std::experimental::any;
62 typedef std::chrono::time_point<std::chrono::system_clock, typename std::chrono::system_clock::duration>
time_type;
71 const std::string&
get_id()
const {
return _session_id; }
135 void set_principal(std::unique_ptr<principal>&& p) { _principal = std::move(p); }
154 http_session(
const string_view &client_ip,
const string_view &user_agent);
165 virtual void validate(
const string_view &client_ip,
const string_view &user_agent) = 0;
195 std::string _session_id;
197 std::shared_ptr<principal> _principal;
215 virtual string_view
get_name() noexcept = 0;
238 string_view
get_name() noexcept
override {
return _name; }
245 #endif // MOD_SERVLET_SESSION_H
std::string _client_ip
Client IP string.
Definition: session.h:178
void set_principal(principal *p)
Set the authenticated principal that is associated with this session.
Definition: session.h:113
virtual string_view get_name() noexcept=0
Returns the name of this principal.
named_principal(const std::string &name)
Constructs principal with a given name.
Definition: session.h:229
string_view get_name() noexceptoverride
Returns the name of this principal.
Definition: session.h:238
const std::string & get_id() const
Returns a string containing the unique identifier assigned to this session.
Definition: session.h:71
virtual void reset_session_id()
Resets session_id for this session.
bool _new
New flag for this session.
Definition: session.h:187
std::string _user_agent
User agent string.
Definition: session.h:182
std::chrono::time_point< std::chrono::system_clock, typename std::chrono::system_clock::duration > time_type
Type to be returned with get_creation_time and get_last_accessed_time.
Definition: session.h:62
Covenience class on top of associative container to facilitate work with value type std::any...
Definition: any_map.h:84
Simple inplementation of servlet::principal with a name only.
Definition: session.h:222
This interface represents the abstract notion of a principal, which can be used to represent any enti...
Definition: session.h:205
time_type get_last_accessed_time() const
Returns the last time the client sent a request associated with this session, as recorded by std::chr...
Definition: session.h:92
bool is_new() const
Returns true if the client does not yet know about the session or if the client chooses not to join t...
Definition: session.h:103
named_principal(std::string &&name)
Constructs principal with a given name.
Definition: session.h:234
time_type get_creation_time() const
Returns the time when this session was created as recorded by std::chrono::system_clock.
Definition: session.h:79
void set_principal(std::shared_ptr< principal > p)
Set the authenticated principal that is associated with this session.
Definition: session.h:124
Provides a way to identify a user across more than one page request or visit to a Web site and to sto...
Definition: session.h:56
std::shared_ptr< principal > get_principal() const
Return the authenticated principal that is associated with this session.
Definition: session.h:146
time_type _last_accessed
Last accessed timestamp.
Definition: session.h:192
virtual void validate(const string_view &client_ip, const string_view &user_agent)=0
Validates client IP and user agent against this session ones.
void set_principal(std::unique_ptr< principal > &&p)
Set the authenticated principal that is associated with this session.
Definition: session.h:135
Containes the implementation of any_map class and related type definitions.
http_session(const string_view &client_ip, const string_view &user_agent)
Protected constructor.