Leosac  0.8.0
Open Source Access Control
AuthFileInstance.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 "FileAuthSourceMapper.hpp"
23 #include "LeosacFwd.hpp"
24 #include "core/auth/AuthFwd.hpp"
25 #include "core/tasks/Task.hpp"
26 #include <fstream>
27 #include <zmqpp/zmqpp.hpp>
28 
29 namespace Leosac
30 {
31 namespace Module
32 {
33 namespace Auth
34 {
35 
36 class AuthFileInstance;
37 using AuthFileInstancePtr = std::shared_ptr<AuthFileInstance>;
38 
39 struct AuthResult
40 {
43  : success(s)
44  , profile(p)
45  , user(u)
46  {
47  }
48 
52  bool success;
58 
64 };
65 
71 class AuthFileInstance : public std::enable_shared_from_this<AuthFileInstance>
72 {
73  public:
84  AuthFileInstance(zmqpp::context &ctx, const std::string &auth_ctx_name,
85  const std::list<std::string> &auth_sources_names,
86  const std::string &auth_target_name,
87  const std::string &input_file, CoreUtilsPtr core_utils);
88 
90 
91  AuthFileInstance(const AuthFileInstance &) = delete;
92 
93  AuthFileInstance &operator=(const AuthFileInstance &) = delete;
94 
98  void handle_bus_msg();
99 
103  zmqpp::socket &bus_sub();
104 
108  const std::string &auth_file_name() const;
109 
114  std::string auth_file_content() const;
115 
116  private:
123  bool handle_kernel_message(const zmqpp::message &msg);
124 
128  void reload_auth_config();
129 
140  AuthResult handle_auth(zmqpp::message *msg) noexcept;
141 
148  std::mutex mutex_;
149 
154 
158  zmqpp::socket bus_push_;
159 
163  zmqpp::socket bus_sub_;
164 
168  std::string name_;
169 
173  std::string target_name_;
174 
178  std::string file_path_;
179 
181 };
182 }
183 }
184 }
Leosac::Module::Auth::AuthFileInstance::reload_auth_config
void reload_auth_config()
Schedule an asynchronous reload of the module configuration file.
Definition: AuthFileInstance.cpp:169
Leosac::Module::Auth::AuthResult
Definition: AuthFileInstance.hpp:39
Leosac::Module::Auth::AuthFileInstance::auth_file_name
const std::string & auth_file_name() const
Return the name of the file associated with the authenticator.
Definition: AuthFileInstance.cpp:164
Leosac::Module::Auth::AuthFileInstance::mapper_
FileAuthSourceMapperPtr mapper_
Authentication config file parser.
Definition: AuthFileInstance.hpp:153
Leosac::Module::Auth::AuthFileInstance::target_name_
std::string target_name_
Name of the target we auth against.
Definition: AuthFileInstance.hpp:173
Leosac::Module::Auth::AuthFileInstance::bus_push_
zmqpp::socket bus_push_
Socket to write to the bus.
Definition: AuthFileInstance.hpp:158
Leosac::Module::Auth::AuthFileInstance::file_path_
std::string file_path_
Path to the auth data file.
Definition: AuthFileInstance.hpp:178
AuthFwd.hpp
Leosac::Module::Auth::FileAuthSourceMapperPtr
std::shared_ptr< FileAuthSourceMapper > FileAuthSourceMapperPtr
Definition: FileAuthSourceMapper.hpp:208
LeosacFwd.hpp
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
Leosac::Auth::IAccessProfilePtr
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
Leosac::Module::Auth::AuthFileInstance::core_utils_
CoreUtilsPtr core_utils_
Definition: AuthFileInstance.hpp:180
Leosac::Module::Auth::AuthFileInstance::auth_file_content
std::string auth_file_content() const
Return the content of the configuration file use for user/group and permission mapping.
Definition: AuthFileInstance.cpp:155
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Auth::AuthResult::AuthResult
AuthResult(bool s, ::Leosac::Auth::IAccessProfilePtr p, ::Leosac::Auth::UserPtr u)
Definition: AuthFileInstance.hpp:41
Leosac::Module::Auth::AuthFileInstance::handle_kernel_message
bool handle_kernel_message(const zmqpp::message &msg)
Handle the message if its from Leosac's kernel, or does nothing.
Definition: AuthFileInstance.cpp:201
FileAuthSourceMapper.hpp
Leosac::Module::Auth::AuthFileInstancePtr
std::shared_ptr< AuthFileInstance > AuthFileInstancePtr
Definition: AuthFileInstance.hpp:37
Leosac::Module::Auth::AuthFileInstance::operator=
AuthFileInstance & operator=(const AuthFileInstance &)=delete
Leosac::Module::Auth::AuthFileInstance::mutex_
std::mutex mutex_
A mutex used only internally.
Definition: AuthFileInstance.hpp:148
Leosac::Module::Auth::AuthFileInstance::AuthFileInstance
AuthFileInstance(zmqpp::context &ctx, const std::string &auth_ctx_name, const std::list< std::string > &auth_sources_names, const std::string &auth_target_name, const std::string &input_file, CoreUtilsPtr core_utils)
Create a new Authenticator that watch a device and emit authentication message.
Definition: AuthFileInstance.cpp:37
Leosac::Module::Auth::AuthFileInstance::bus_sub
zmqpp::socket & bus_sub()
Returns the socket subscribed to the message bus.
Definition: AuthFileInstance.cpp:104
Leosac::Module::Auth::AuthFileInstance::handle_bus_msg
void handle_bus_msg()
Something happened on the bus that we have interest into.
Definition: AuthFileInstance.cpp:67
Leosac::Module::Auth::AuthFileInstance::handle_auth
AuthResult handle_auth(zmqpp::message *msg) noexcept
Prepare auth source object, map them to profile and check if access is granted.
Definition: AuthFileInstance.cpp:109
Leosac::Module::Auth::AuthResult::user
::Leosac::Auth::UserPtr user
A user object representing the user who made the authentication attempt.
Definition: AuthFileInstance.hpp:63
Leosac::Module::Auth::AuthFileInstance::name_
std::string name_
Name of this auth context instance.
Definition: AuthFileInstance.hpp:168
Task.hpp
Leosac::Module::Auth::AuthFileInstance::~AuthFileInstance
~AuthFileInstance()
Definition: AuthFileInstance.cpp:62
Leosac::Module::Auth::AuthResult::profile
::Leosac::Auth::IAccessProfilePtr profile
Profile used to grant or deny access.
Definition: AuthFileInstance.hpp:57
Leosac::Module::Auth::AuthFileInstance
An instance of an authentication handler that use files to check whether or not access is granted or ...
Definition: AuthFileInstance.hpp:71
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
Leosac::Module::Auth::AuthFileInstance::bus_sub_
zmqpp::socket bus_sub_
Socket to read from the bus.
Definition: AuthFileInstance.hpp:163
Leosac::Module::Auth::AuthResult::success
bool success
Wether access shall be granted, or not.
Definition: AuthFileInstance.hpp:52