Leosac  0.8.0
Open Source Access Control
APIAuth.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "core/auth/AuthFwd.hpp"
23 #include "core/auth/Token.hpp"
24 #include <map>
25 #include <string>
26 #include <vector>
27 
28 namespace Leosac
29 {
30 namespace Module
31 {
32 namespace WebSockAPI
33 {
34 class WSServer;
41 class APIAuth
42 {
43  public:
44  APIAuth(WSServer &srv);
45 
57  Auth::TokenPtr authenticate_credentials(const std::string &username,
58  const std::string &password) const;
59 
70  Auth::TokenPtr authenticate_token(const std::string &token_str) const;
71 
75  void invalidate_token(Auth::TokenPtr token) const;
76 
77  private:
82  void enforce_user_enabled(const Auth::User &u) const;
83 
90 };
91 }
92 }
93 }
Leosac::Auth::TokenPtr
std::shared_ptr< Token > TokenPtr
Definition: AuthFwd.hpp:85
Leosac::Module::WebSockAPI::APIAuth::enforce_user_enabled
void enforce_user_enabled(const Auth::User &u) const
Make sure the User u is authorized to log in.
Definition: APIAuth.cpp:123
Leosac::Module::WebSockAPI::APIAuth::authenticate_token
Auth::TokenPtr authenticate_token(const std::string &token_str) const
Attempt to authenticate with an authentication token.
Definition: APIAuth.cpp:60
AuthFwd.hpp
Leosac::Module::WebSockAPI::APIAuth
This class is responsible for providing an API to manage authentication for Websocket client.
Definition: APIAuth.hpp:41
Leosac::Module::WebSockAPI::APIAuth::authenticate_credentials
Auth::TokenPtr authenticate_credentials(const std::string &username, const std::string &password) const
Attempt to authenticate with username/password credential and generate an authentication token.
Definition: APIAuth.cpp:82
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::User
Represent a user.
Definition: User.hpp:42
Leosac::Module::WebSockAPI::APIAuth::server_
WSServer & server_
Reference to the Websocket server.
Definition: APIAuth.hpp:89
Leosac::Module::WebSockAPI::WSServer
The implementation class that runs the websocket server.
Definition: WSServer.hpp:61
Leosac::Module::WebSockAPI::APIAuth::invalidate_token
void invalidate_token(Auth::TokenPtr token) const
Invalidate the authentication token, removing it from the database.
Definition: APIAuth.cpp:49
Token.hpp
Leosac::Module::WebSockAPI::APIAuth::APIAuth
APIAuth(WSServer &srv)
Definition: APIAuth.cpp:44