Leosac  0.7.0
OpenSourceAccessControl
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 }
std::string file_path_
Path to the auth data file.
FileAuthSourceMapperPtr mapper_
Authentication config file parser.
std::string target_name_
Name of the target we auth against.
zmqpp::socket bus_push_
Socket to write to the bus.
This is the header file for a generated source file, GitSHA1.cpp.
An instance of an authentication handler that use files to check whether or not access is granted or ...
std::shared_ptr< FileAuthSourceMapper > FileAuthSourceMapperPtr
AuthResult(bool s, ::Leosac::Auth::IAccessProfilePtr p, ::Leosac::Auth::UserPtr u)
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
bool success
Wether access shall be granted, or not.
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
std::shared_ptr< AuthFileInstance > AuthFileInstancePtr
::Leosac::Auth::UserPtr user
A user object representing the user who made the authentication attempt.
::Leosac::Auth::IAccessProfilePtr profile
Profile used to grant or deny access.
std::mutex mutex_
A mutex used only internally.
std::string name_
Name of this auth context instance.
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
zmqpp::socket bus_sub_
Socket to read from the bus.