Leosac  0.8.0
Open Source Access Control
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 }
Leosac::Module::Auth::FileAuthSourceMapper::groups_
std::map< std::string, Leosac::Auth::GroupPtr > groups_
Maps group name to object.
Definition: FileAuthSourceMapper.hpp:167
Leosac::Tools::XmlScheduleLoader
Load a list of schedules from a boost::property_tree.
Definition: XmlScheduleLoader.hpp:36
Leosac::Cred::PinCode
A PinCode credential.
Definition: PinCode.hpp:33
Leosac::Module::Auth::FileAuthSourceMapper::add_cred_to_id_map
void add_cred_to_id_map(Leosac::Cred::ICredentialPtr credential)
Store the credential to the id <-> credential map if the id is non-empty.
Definition: FileAuthSourceMapper.cpp:444
Leosac::Module::Auth::FileAuthSourceMapper::find_cred_by_alias
Cred::ICredentialPtr find_cred_by_alias(const std::string &alias)
Lookup a credentials by ID.
Definition: FileAuthSourceMapper.cpp:436
Leosac::Cred::RFIDCardPin
Credentials composed of an RFIDCard and a PIN code.
Definition: RFIDCardPin.hpp:37
AuthFwd.hpp
Leosac::Module::Auth::FileAuthSourceMapperPtr
std::shared_ptr< FileAuthSourceMapper > FileAuthSourceMapperPtr
Definition: FileAuthSourceMapper.hpp:208
SimpleAccessProfile.hpp
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
Leosac::Module::Auth::FileAuthSourceMapper::pin_codes_
std::unordered_map< std::string, Leosac::Cred::PinCodePtr > pin_codes_
Maps PIN code to object.
Definition: FileAuthSourceMapper.hpp:178
Leosac::Auth::IAccessProfilePtr
std::shared_ptr< IAccessProfile > IAccessProfilePtr
Definition: AuthFwd.hpp:88
Leosac::Module::Auth::FileAuthSourceMapper::load_credentials
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...
Definition: FileAuthSourceMapper.cpp:233
Leosac::Cred::RFIDCard
An RFID card credential.
Definition: RFIDCard.hpp:33
Leosac::Module::Auth::FileAuthSourceMapper::build_group_profile
Leosac::Auth::SimpleAccessProfilePtr build_group_profile(Leosac::Auth::GroupPtr g)
Definition: FileAuthSourceMapper.cpp:547
Leosac::Module::Auth::FileAuthSourceMapper::xmlnne_
Tools::XmlNodeNameEnforcer xmlnne_
Definition: FileAuthSourceMapper.hpp:206
Leosac::Tools::Visitor
A Visitor object.
Definition: Visitor.hpp:64
Leosac::Module::Auth::FileAuthSourceMapper::rfid_cards_pin
std::map< std::pair< std::string, std::string >, Leosac::Cred::RFIDCardPinPtr > rfid_cards_pin
Maps WiegandCard + PIN code to object.
Definition: FileAuthSourceMapper.hpp:184
Leosac::Module::Auth::FileAuthSourceMapper::buildProfile
virtual Leosac::Auth::IAccessProfilePtr buildProfile(Leosac::Cred::ICredentialPtr cred)
Build an AccessProfile object given a Credential.
Definition: FileAuthSourceMapper.cpp:460
Leosac::Module::Auth::FileAuthSourceMapper::load_groups
void load_groups(const boost::property_tree::ptree &group_mapping)
Extract group membership.
Definition: FileAuthSourceMapper.cpp:151
Leosac::Module::Auth::FileAuthSourceMapper::load_schedules
void load_schedules(const boost::property_tree::ptree &schedules)
Load the schedules information from the config tree.
Definition: FileAuthSourceMapper.cpp:306
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
XmlScheduleLoader.hpp
Leosac::Module::Auth::FileAuthSourceMapper::mapToUser
virtual void mapToUser(Leosac::Cred::ICredentialPtr auth_source)
Must map the ICredential data to a User.
Definition: FileAuthSourceMapper.cpp:137
Leosac::Auth::GroupPtr
std::shared_ptr< Group > GroupPtr
Definition: AuthFwd.hpp:37
Leosac::Auth::SimpleAccessProfilePtr
std::shared_ptr< SimpleAccessProfile > SimpleAccessProfilePtr
Definition: AuthFwd.hpp:44
Leosac::Module::Auth::FileAuthSourceMapper::groups
std::vector< Leosac::Auth::GroupPtr > groups() const override
Return the groups this mapper is aware of.
Definition: FileAuthSourceMapper.cpp:183
Leosac::Module::Auth::FileAuthSourceMapper::rfid_cards_
std::unordered_map< std::string, Leosac::Cred::RFIDCardPtr > rfid_cards_
Maps card_id to object.
Definition: FileAuthSourceMapper.hpp:172
Leosac::Module::Auth::FileAuthSourceMapper::users_
std::map< std::string, Leosac::Auth::UserPtr > users_
Maps user id (or name) to object.
Definition: FileAuthSourceMapper.hpp:162
Leosac::Module::Auth::FileAuthSourceMapper::config_file_
std::string config_file_
Store the name of the configuration file.
Definition: FileAuthSourceMapper.hpp:157
Leosac::Auth::IAuthSourceMapper
Base class to perform abstracted mapping operation over various AuthSource object.
Definition: IAuthSourceMapper.hpp:43
Leosac::Module::Auth::FileAuthSourceMapper::visit
virtual void visit(::Leosac::Cred::RFIDCard &src) override
Try to map a wiegand card_id to a user.
Definition: FileAuthSourceMapper.cpp:93
Leosac::Module::Auth::FileAuthSourceMapper::id_to_cred_
std::unordered_map< std::string, Leosac::Cred::ICredentialPtr > id_to_cred_
Maps credentials ID (from XML) to object.
Definition: FileAuthSourceMapper.hpp:190
Leosac::Module::Auth::FileAuthSourceMapper::xml_schedules_
Tools::XmlScheduleLoader xml_schedules_
Definition: FileAuthSourceMapper.hpp:192
Leosac::Module::Auth::FileAuthSourceMapper::FileAuthSourceMapper
FileAuthSourceMapper(const std::string &auth_file)
Definition: FileAuthSourceMapper.cpp:42
Leosac::Module::Auth::FileAuthSourceMapper::build_cred_profile
Leosac::Auth::SimpleAccessProfilePtr build_cred_profile(Leosac::Cred::ICredentialPtr c)
Definition: FileAuthSourceMapper.cpp:563
Leosac::Cred::ICredentialPtr
std::shared_ptr< ICredential > ICredentialPtr
Definition: CredentialFwd.hpp:32
Leosac::Module::Auth::FileAuthSourceMapper::extract_credentials_validity
Leosac::Auth::ValidityInfo extract_credentials_validity(const boost::property_tree::ptree &node)
Definition: FileAuthSourceMapper.cpp:423
Leosac::Cred::RFIDCardPinPtr
std::shared_ptr< RFIDCardPin > RFIDCardPinPtr
Definition: CredentialFwd.hpp:50
Leosac::Module::Auth::FileAuthSourceMapper::map_schedules
void map_schedules(const boost::property_tree::ptree &schedules_mapping)
Interpret the schedule mapping content of the config file.
Definition: FileAuthSourceMapper.cpp:313
Leosac::Tools::XmlNodeNameEnforcer
This class is a simple wrapper that throws a ConfigException message formated to report the user that...
Definition: XmlNodeNameEnforcer.hpp:36
IAuthSourceMapper.hpp
Leosac::Module::Auth::FileAuthSourceMapper::merge_profiles
Leosac::Auth::IAccessProfilePtr merge_profiles(const std::vector< Leosac::Auth::IAccessProfilePtr > profiles)
Merge a bunch of profiles together and returns a new profile.
Definition: FileAuthSourceMapper.cpp:218
ScheduleMapping.hpp
CredentialFwd.hpp
Leosac::Module::Auth::FileAuthSourceMapper::load_users
void load_users(const boost::property_tree::ptree &users)
Load users from configuration tree, storing them in the users_ map.
Definition: FileAuthSourceMapper.cpp:384
Leosac::Module::Auth::FileAuthSourceMapper::mappings_
std::vector< Tools::ScheduleMappingPtr > mappings_
List of mappings defined in the configuration file.
Definition: FileAuthSourceMapper.hpp:197
XmlNodeNameEnforcer.hpp
Leosac::Module::Auth::FileAuthSourceMapper::get_user_groups
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.
Definition: FileAuthSourceMapper.cpp:195
Leosac::Module::Auth::FileAuthSourceMapper
Use a file to map auth source (card, PIN, etc) to user.
Definition: FileAuthSourceMapper.hpp:47
Leosac::Module::Auth::FileAuthSourceMapper::build_user_profile
Leosac::Auth::SimpleAccessProfilePtr build_user_profile(Leosac::Auth::UserPtr u)
Build an access for a user.
Definition: FileAuthSourceMapper.cpp:532
Leosac::Auth::ValidityInfo
A simple class that stores (and can be queried for) the validity of some objects.
Definition: ValidityInfo.hpp:42
IAuthenticationSource.hpp
Leosac::Module::Auth::FileAuthSourceMapper::doors_
std::vector< Leosac::Auth::DoorPtr > doors_
We store doors object, but really we only use the name property.
Definition: FileAuthSourceMapper.hpp:204
SingleTimeFrame.hpp