Leosac
0.8.0
Open Source Access Control
|
This is the application-level object that provide the API. More...
#include <APISession.hpp>
Public Types | |
enum | AuthStatus { AuthStatus::NONE, AuthStatus::LOGGED_IN } |
Enumeration describing the authentication status of a client. More... | |
using | json = nlohmann::json |
Public Member Functions | |
APISession (WSServer &server) | |
APISession (const APISession &)=delete | |
APISession (APISession &&)=delete | |
Auth::UserId | current_user_id () const |
Retrieve the UserId of the user associated with this API session. More... | |
Auth::UserPtr | current_user () const |
Retrieve the user associated with the session, or nullptr. More... | |
Auth::TokenPtr | current_token () const |
Retrieve the currently in-use token, or nullptr. More... | |
bool | allowed (const std::string &cmd) |
Is this API client allowed to perform the request cmd ? More... | |
json | get_leosac_version (const json &) |
Retrieve the current version number of Leosac. More... | |
json | create_auth_token (const json &req) |
Generate an authentication token using the user credential, and logs the user in on success. More... | |
json | authenticate_with_token (const json &req) |
Attempt to authenticate with a (previously generated) authentication token. More... | |
json | logout (const json &req) |
Log an user out. More... | |
json | system_overview (const json &req) |
Presents an overview of the system to the end user. More... | |
void | hook_before_request () |
A hook that is called before a request processing method will be invoked. More... | |
void | abort_session () |
Abort the current websocket session. More... | |
SecurityContext & | security_context () const |
Private Member Functions | |
void | mark_authenticated (Auth::TokenPtr token) |
void | clear_authentication () |
Private Attributes | |
WSServer & | server_ |
The API server. More... | |
AuthStatus | auth_status_ |
Auth::TokenPtr | current_auth_token_ |
The token we are authenticated with. More... | |
std::unique_ptr< SecurityContext > | security_ |
This is the application-level object that provide the API.
One objected is instantiated per websocket client.
Definition at line 42 of file APISession.hpp.
using Leosac::Module::WebSockAPI::APISession::json = nlohmann::json |
Definition at line 45 of file APISession.hpp.
Enumeration describing the authentication status of a client.
Enumerator | |
---|---|
NONE | |
LOGGED_IN |
Definition at line 50 of file APISession.hpp.
APISession::APISession | ( | WSServer & | server | ) |
Definition at line 42 of file APISession.cpp.
|
delete |
|
delete |
void APISession::abort_session | ( | ) |
Abort the current websocket session.
This means that we reset the authentication status.
Definition at line 165 of file APISession.cpp.
bool APISession::allowed | ( | const std::string & | cmd | ) |
Is this API client allowed to perform the request cmd
?
Definition at line 126 of file APISession.cpp.
APISession::json APISession::authenticate_with_token | ( | const json & | req | ) |
Attempt to authenticate with a (previously generated) authentication token.
Request:
token
: The authentication tokenResponse:
user_id
: On success, the user-id of the newly authenticated user.username
: On success, the username authenticated user.status
: See create_auth_token status.message
: An optional text message describing the status.Definition at line 82 of file APISession.cpp.
|
private |
Definition at line 198 of file APISession.cpp.
APISession::json APISession::create_auth_token | ( | const json & | req | ) |
Generate an authentication token using the user credential, and logs the user in on success.
Request:
username
: Username of the user attempting to log-in.password
: Clear text password.Response:
status
: An integer.0
means success.-1
means invalid username/password.user_id
: On success, the identifier of the logged in user.token
: On success, value of the generated authentication token.message
: An optional text message describing the status. Definition at line 56 of file APISession.cpp.
Auth::TokenPtr APISession::current_token | ( | ) | const |
Retrieve the currently in-use token, or nullptr.
Definition at line 185 of file APISession.cpp.
Auth::UserPtr APISession::current_user | ( | ) | const |
Retrieve the user associated with the session, or nullptr.
Definition at line 178 of file APISession.cpp.
Auth::UserId APISession::current_user_id | ( | ) | const |
Retrieve the UserId of the user associated with this API session.
Definition at line 171 of file APISession.cpp.
APISession::json APISession::get_leosac_version | ( | const json & | ) |
Retrieve the current version number of Leosac.
Request:
Response:
version
: An alphanumeric string representing the version of the Leosac daemon. Definition at line 48 of file APISession.cpp.
void APISession::hook_before_request | ( | ) |
A hook that is called before a request processing method will be invoked.
Typically, this is used to:
Definition at line 135 of file APISession.cpp.
APISession::json APISession::logout | ( | const json & | req | ) |
Log an user out.
Request:
Response:
Definition at line 104 of file APISession.cpp.
|
private |
Definition at line 190 of file APISession.cpp.
SecurityContext & APISession::security_context | ( | ) | const |
Definition at line 205 of file APISession.cpp.
APISession::json APISession::system_overview | ( | const json & | req | ) |
Presents an overview of the system to the end user.
Request:
Response:
instance_name
: General config instance_name
value.config_version
: The current version number of the configuration.uptime
: Number of seconds since Leosac started to run.modules
: List of name of the currently running modules. Definition at line 113 of file APISession.cpp.
|
private |
Definition at line 181 of file APISession.hpp.
|
private |
The token we are authenticated with.
Definition at line 186 of file APISession.hpp.
|
private |
Definition at line 188 of file APISession.hpp.
|
private |
The API server.
Definition at line 180 of file APISession.hpp.