Leosac  0.7.0
OpenSourceAccessControl
FileAuthSourceMapper.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/AuthFwd.hpp"
32 #include <boost/property_tree/ptree.hpp>
33 #include <map>
34 #include <string>
35 #include <unordered_map>
36 #include <utility>
37 
38 namespace Leosac
39 {
40 namespace Module
41 {
42 namespace Auth
43 {
49  public ::Leosac::Tools::Visitor<::Leosac::Cred::RFIDCard>,
50  public ::Leosac::Tools::Visitor<::Leosac::Cred::PinCode>,
51  public ::Leosac::Tools::Visitor<::Leosac::Cred::RFIDCardPin>
52 {
53  public:
54  FileAuthSourceMapper(const std::string &auth_file);
55 
59  virtual void visit(::Leosac::Cred::RFIDCard &src) override;
60 
64  virtual void visit(::Leosac::Cred::PinCode &src) override;
65 
69  virtual void visit(::Leosac::Cred::RFIDCardPin &src) override;
70 
71  virtual void mapToUser(Leosac::Cred::ICredentialPtr auth_source);
72 
75 
76  std::vector<Leosac::Auth::GroupPtr> groups() const override;
77 
78  private:
82  Cred::ICredentialPtr find_cred_by_alias(const std::string &alias);
83 
91 
94 
97 
103 
108  void load_users(const boost::property_tree::ptree &users);
109 
114  void load_schedules(const boost::property_tree::ptree &schedules);
115 
120  void map_schedules(const boost::property_tree::ptree &schedules_mapping);
121 
125  void load_groups(const boost::property_tree::ptree &group_mapping);
126 
131  void load_credentials(const boost::property_tree::ptree &credentials);
132 
140  std::vector<Leosac::Auth::GroupPtr> get_user_groups(Leosac::Auth::UserPtr u);
141 
149  merge_profiles(const std::vector<Leosac::Auth::IAccessProfilePtr> profiles);
150 
152  extract_credentials_validity(const boost::property_tree::ptree &node);
153 
157  std::string config_file_;
158 
162  std::map<std::string, Leosac::Auth::UserPtr> users_;
163 
167  std::map<std::string, Leosac::Auth::GroupPtr> groups_;
168 
172  std::unordered_map<std::string, Leosac::Cred::RFIDCardPtr> rfid_cards_;
173 
174 
178  std::unordered_map<std::string, Leosac::Cred::PinCodePtr> pin_codes_;
179 
183  std::map<std::pair<std::string, std::string>, Leosac::Cred::RFIDCardPinPtr>
185 
190  std::unordered_map<std::string, Leosac::Cred::ICredentialPtr> id_to_cred_;
191 
193 
197  std::vector<Tools::ScheduleMappingPtr> mappings_;
198 
204  std::vector<Leosac::Auth::DoorPtr> doors_;
205 
207 };
208 using FileAuthSourceMapperPtr = std::shared_ptr<FileAuthSourceMapper>;
209 }
210 }
211 }
virtual Leosac::Auth::IAccessProfilePtr buildProfile(Leosac::Cred::ICredentialPtr cred)
Build an AccessProfile object given a Credential.
void load_users(const boost::property_tree::ptree &users)
Load users from configuration tree, storing them in the users_ map.
void load_groups(const boost::property_tree::ptree &group_mapping)
Extract group membership.
virtual void mapToUser(Leosac::Cred::ICredentialPtr auth_source)
Must map the ICredential data to a User.
std::unordered_map< std::string, Leosac::Cred::RFIDCardPtr > rfid_cards_
Maps card_id to object.
Leosac::Auth::ValidityInfo extract_credentials_validity(const boost::property_tree::ptree &node)
std::map< std::pair< std::string, std::string >, Leosac::Cred::RFIDCardPinPtr > rfid_cards_pin
Maps WiegandCard + PIN code to object.
std::vector< Leosac::Auth::GroupPtr > groups() const override
Return the groups this mapper is aware of.
virtual void visit(::Leosac::Cred::RFIDCard &src) override
Try to map a wiegand card_id to a user.
std::map< std::string, Leosac::Auth::UserPtr > users_
Maps user id (or name) to object.
This is the header file for a generated source file, GitSHA1.cpp.
Cred::ICredentialPtr find_cred_by_alias(const std::string &alias)
Lookup a credentials by ID.
std::vector< Leosac::Auth::GroupPtr > get_user_groups(Leosac::Auth::UserPtr u)
Naive method that bruteforce groups to try to find membership for an user.
A simple class that stores (and can be queried for) the validity of some objects. ...
This class is a simple wrapper that throws a ConfigException message formated to report the user that...
std::vector< Tools::ScheduleMappingPtr > mappings_
List of mappings defined in the configuration file.
std::shared_ptr< FileAuthSourceMapper > FileAuthSourceMapperPtr
std::unordered_map< std::string, Leosac::Cred::ICredentialPtr > id_to_cred_
Maps credentials ID (from XML) to object.
std::string config_file_
Store the name of the configuration file.
A PinCode credential.
Definition: PinCode.hpp:33
std::map< std::string, Leosac::Auth::GroupPtr > groups_
Maps group name to object.
std::shared_ptr< ICredential > ICredentialPtr
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
std::shared_ptr< Group > GroupPtr
Definition: AuthFwd.hpp:37
void add_cred_to_id_map(Leosac::Cred::ICredentialPtr credential)
Store the credential to the id <-> credential map if the id is non-empty.
void load_schedules(const boost::property_tree::ptree &schedules)
Load the schedules information from the config tree.
Credentials composed of an RFIDCard and a PIN code.
Definition: RFIDCardPin.hpp:37
std::vector< Leosac::Auth::DoorPtr > doors_
We store doors object, but really we only use the name property.
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
Use a file to map auth source (card, PIN, etc) to user.
Leosac::Auth::SimpleAccessProfilePtr build_group_profile(Leosac::Auth::GroupPtr g)
FileAuthSourceMapper(const std::string &auth_file)
Leosac::Auth::SimpleAccessProfilePtr build_user_profile(Leosac::Auth::UserPtr u)
Build an access for a user.
std::shared_ptr< RFIDCardPin > RFIDCardPinPtr
std::unordered_map< std::string, Leosac::Cred::PinCodePtr > pin_codes_
Maps PIN code to object.
std::shared_ptr< SimpleAccessProfile > SimpleAccessProfilePtr
Definition: AuthFwd.hpp:44
void map_schedules(const boost::property_tree::ptree &schedules_mapping)
Interpret the schedule mapping content of the config file.
Leosac::Auth::IAccessProfilePtr merge_profiles(const std::vector< Leosac::Auth::IAccessProfilePtr > profiles)
Merge a bunch of profiles together and returns a new profile.
Leosac::Auth::SimpleAccessProfilePtr build_cred_profile(Leosac::Cred::ICredentialPtr c)
An RFID card credential.
Definition: RFIDCard.hpp:33
void load_credentials(const boost::property_tree::ptree &credentials)
Eager loading of credentials to avoid walking through the ptree whenever we have to grant/deny an acc...
A Visitor object.
Definition: Visitor.hpp:64
Base class to perform abstracted mapping operation over various AuthSource object.
Load a list of schedules from a boost::property_tree.