Leosac  0.8.0
Open Source Access Control
DoormanInstance.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/Auth.hpp"
23 #include "core/auth/AuthFwd.hpp"
24 #include "DoormanDoor.hpp"
25 #include <map>
26 #include <zmqpp/zmqpp.hpp>
27 
28 namespace Leosac
29 {
30 namespace Module
31 {
32 namespace Doorman
33 {
34 class DoormanModule;
41 {
45  std::string target_;
46 
51 
56  std::vector<std::string> cmd_;
57 };
58 
65 {
66  public:
76  DoormanInstance(DoormanModule &module, zmqpp::context &ctx,
77  const std::string &name,
78  const std::vector<std::string> &auth_contexts,
79  const std::vector<DoormanAction> &actions);
80 
81  DoormanInstance(const DoormanInstance &) = delete;
82 
83  DoormanInstance &operator=(const DoormanInstance &) = delete;
84 
85  zmqpp::socket &bus_sub();
86 
90  void handle_bus_msg();
91 
92  const std::vector<std::shared_ptr<DoormanDoor>> &doors() const;
93 
94  private:
103  bool ignore_action(const DoormanAction &action, Auth::AccessStatus status) const;
104 
105  Auth::AuthTargetPtr find_target(const std::string &name) const;
106 
107  std::vector<std::shared_ptr<DoormanDoor>> doors_;
108 
115  void command_send_recv(const std::string &target_name, zmqpp::message msg);
116 
117  std::string name_;
118 
119  std::vector<DoormanAction> actions_;
120 
121  zmqpp::socket bus_sub_;
122 
126  std::map<std::string, zmqpp::socket> targets_;
127 };
128 }
129 }
130 }
Leosac::Module::Doorman::DoormanInstance::actions_
std::vector< DoormanAction > actions_
Definition: DoormanInstance.hpp:119
Leosac::Module::Doorman::DoormanAction::on_
Leosac::Auth::AccessStatus on_
When should this action be done? on GRANTED or DENIED ?
Definition: DoormanInstance.hpp:50
Leosac::Module::Doorman::DoormanInstance::operator=
DoormanInstance & operator=(const DoormanInstance &)=delete
Auth.hpp
AuthFwd.hpp
Leosac::Module::Doorman::DoormanAction::target_
std::string target_
Target component.
Definition: DoormanInstance.hpp:45
Leosac::Module::Doorman::DoormanInstance::bus_sub_
zmqpp::socket bus_sub_
Definition: DoormanInstance.hpp:121
Leosac::Module::Doorman::DoormanAction
Helper struct to wrap an "action".
Definition: DoormanInstance.hpp:40
Leosac::Module::Doorman::DoormanInstance::doors_
std::vector< std::shared_ptr< DoormanDoor > > doors_
Definition: DoormanInstance.hpp:107
Leosac::Auth::AuthTargetPtr
std::shared_ptr< AuthTarget > AuthTargetPtr
Definition: AuthFwd.hpp:93
Leosac::Module::Doorman::DoormanInstance::doors
const std::vector< std::shared_ptr< DoormanDoor > > & doors() const
Definition: DoormanInstance.cpp:152
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Doorman::DoormanInstance::ignore_action
bool ignore_action(const DoormanAction &action, Auth::AccessStatus status) const
Should we ignore this action.
Definition: DoormanInstance.cpp:134
Leosac::Auth::AccessStatus
AccessStatus
Definition: Auth.hpp:54
Leosac::Module::Doorman::DoormanAction::cmd_
std::vector< std::string > cmd_
The command to be send.
Definition: DoormanInstance.hpp:56
Leosac::Module::Doorman::DoormanInstance::DoormanInstance
DoormanInstance(DoormanModule &module, zmqpp::context &ctx, const std::string &name, const std::vector< std::string > &auth_contexts, const std::vector< DoormanAction > &actions)
Create a new doorman.
Definition: DoormanInstance.cpp:27
DoormanDoor.hpp
Leosac::Module::Doorman::DoormanInstance::find_target
Auth::AuthTargetPtr find_target(const std::string &name) const
Definition: DoormanInstance.cpp:124
Leosac::Module::Doorman::DoormanInstance
Implements a Doorman, that is, a component that will listen to authentication event and react accordi...
Definition: DoormanInstance.hpp:64
Leosac::Module::Doorman::DoormanInstance::targets_
std::map< std::string, zmqpp::socket > targets_
Socket (REP) connected to each target this doorman may have.
Definition: DoormanInstance.hpp:126
Leosac::Module::Doorman::DoormanInstance::bus_sub
zmqpp::socket & bus_sub()
Definition: DoormanInstance.cpp:58
Leosac::Module::Doorman::DoormanInstance::command_send_recv
void command_send_recv(const std::string &target_name, zmqpp::message msg)
Send a command to a target and wait for response.
Definition: DoormanInstance.cpp:105
Leosac::Module::Doorman::DoormanInstance::handle_bus_msg
void handle_bus_msg()
Activity we care about happened on the bus.
Definition: DoormanInstance.cpp:63
Leosac::Module::Doorman::DoormanInstance::name_
std::string name_
Definition: DoormanInstance.hpp:117
Leosac::Module::Doorman::DoormanModule
Main class for the module, it create handlers and run them to, well, handle events and send command.
Definition: DoormanModule.hpp:52