Leosac  0.8.0
Open Source Access Control
AuthFileModule.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2017 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 #include "AuthFileModule.hpp"
21 #include "core/CoreUtils.hpp"
22 #include "core/kernel.hpp"
23 
24 using namespace Leosac;
25 using namespace Leosac::Module::Auth;
26 
27 AuthFileModule::AuthFileModule(zmqpp::context &ctx, zmqpp::socket *pipe,
28  const boost::property_tree::ptree &cfg,
29  CoreUtilsPtr utils)
30  : BaseModule(ctx, pipe, cfg, utils)
31 {
33 
34  for (auto authenticator : authenticators_)
35  {
36  reactor_.add(authenticator->bus_sub(),
37  std::bind(&AuthFileInstance::handle_bus_msg, authenticator));
38  }
39 }
40 
42 {
43 }
44 
46 {
47  boost::property_tree::ptree module_config = config_.get_child("module_config");
48 
49  for (auto &node : module_config.get_child("instances"))
50  {
51  boost::property_tree::ptree auth_instance_cfg = node.second;
52  std::string auth_ctx_name = auth_instance_cfg.get_child("name").data();
53  std::string config_file = auth_instance_cfg.get_child("config_file").data();
54  std::string auth_target_name =
55  auth_instance_cfg.get<std::string>("target", "");
56  std::list<std::string> auth_sources_names;
57 
58  for (const auto &subnode : auth_instance_cfg)
59  {
60  if (subnode.first == "auth_source")
61  auth_sources_names.push_back(subnode.second.data());
62  }
63 
64  if (!auth_target_name.empty())
65  auth_target_name = utils_->kernel().config_manager().instance_name() +
66  '.' + auth_target_name;
67 
68  INFO("Creating AuthFile instance "
69  << auth_ctx_name << ". Target door = " << auth_target_name);
71  new AuthFileInstance(ctx_, auth_ctx_name, auth_sources_names,
72  auth_target_name, config_file, utils_)));
73  }
74 }
75 
76 void AuthFileModule::dump_additional_config(zmqpp::message *out) const
77 {
78  assert(out);
79 
80  for (auto &ptr : authenticators_)
81  {
82  *out << ptr->auth_file_name();
83  *out << ptr->auth_file_content();
84  }
85 }
Leosac::Module::BaseModule
Base class for module implementation.
Definition: BaseModule.hpp:110
INFO
@ INFO
Definition: log.hpp:34
Leosac::Module::Auth::AuthFileModule::~AuthFileModule
~AuthFileModule()
Definition: AuthFileModule.cpp:41
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
kernel.hpp
Leosac::Module::BaseModule::config_
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
Definition: BaseModule.hpp:193
Leosac::Module::BaseModule::reactor_
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
Definition: BaseModule.hpp:214
Leosac::Module::Auth::AuthFileInstancePtr
std::shared_ptr< AuthFileInstance > AuthFileInstancePtr
Definition: AuthFileInstance.hpp:37
Leosac::Module::BaseModule::utils_
CoreUtilsPtr utils_
Pointer to the core utils, which gives access to scheduler and others.
Definition: BaseModule.hpp:198
Leosac::Module::Auth::AuthFileModule::process_config
void process_config()
Processing the configuration tree, spawning AuthFileInstance object as described in the configuration...
Definition: AuthFileModule.cpp:45
Leosac::Module::Auth::AuthFileModule::AuthFileModule
AuthFileModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Definition: AuthFileModule.cpp:27
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::AuthFileModule::authenticators_
std::vector< AuthFileInstancePtr > authenticators_
Authenticator instance.
Definition: AuthFileModule.hpp:69
Leosac::Module::Auth::AuthFileModule::dump_additional_config
virtual void dump_additional_config(zmqpp::message *out) const override
We have one config file per authenticator object.
Definition: AuthFileModule.cpp:76
CoreUtils.hpp
Leosac::Module::Auth
Authentication backend modules live here.
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::Module::BaseModule::ctx_
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
Definition: BaseModule.hpp:183
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
AuthFileModule.hpp