Leosac  0.8.0
Open Source Access Control
Leosac::Module::Auth::FileAuthSourceMapper Class Reference

Use a file to map auth source (card, PIN, etc) to user. More...

#include <FileAuthSourceMapper.hpp>

+ Inheritance diagram for Leosac::Module::Auth::FileAuthSourceMapper:
+ Collaboration diagram for Leosac::Module::Auth::FileAuthSourceMapper:

Public Member Functions

 FileAuthSourceMapper (const std::string &auth_file)
 
virtual void visit (::Leosac::Cred::RFIDCard &src) override
 Try to map a wiegand card_id to a user. More...
 
virtual void visit (::Leosac::Cred::PinCode &src) override
 Try to map a PIN code to a user. More...
 
virtual void visit (::Leosac::Cred::RFIDCardPin &src) override
 Try to map a card id + a PIN code to a user. More...
 
virtual void mapToUser (Leosac::Cred::ICredentialPtr auth_source)
 Must map the ICredential data to a User. More...
 
virtual Leosac::Auth::IAccessProfilePtr buildProfile (Leosac::Cred::ICredentialPtr cred)
 Build an AccessProfile object given a Credential. More...
 
std::vector< Leosac::Auth::GroupPtrgroups () const override
 Return the groups this mapper is aware of. More...
 
- Public Member Functions inherited from Leosac::Auth::IAuthSourceMapper
virtual ~IAuthSourceMapper ()=default
 
- Public Member Functions inherited from Leosac::Tools::Visitor< WiegandCard >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 
- Public Member Functions inherited from Leosac::Tools::BaseVisitor
virtual ~BaseVisitor ()=default
 
virtual void cannot_visit (const IVisitable &)
 Invoked when the visitable cannot be visited by the visitor. More...
 
- Public Member Functions inherited from Leosac::Tools::Visitor< PINCode >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 
- Public Member Functions inherited from Leosac::Tools::Visitor< WiegandCardPin >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 
- Public Member Functions inherited from Leosac::Tools::Visitor<::Leosac::Cred::RFIDCard >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 
- Public Member Functions inherited from Leosac::Tools::Visitor<::Leosac::Cred::PinCode >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 
- Public Member Functions inherited from Leosac::Tools::Visitor<::Leosac::Cred::RFIDCardPin >
virtual void visit (const VisitableT &)
 
virtual void visit (VisitableT &visitable)
 

Private Member Functions

Cred::ICredentialPtr find_cred_by_alias (const std::string &alias)
 Lookup a credentials by ID. More...
 
Leosac::Auth::SimpleAccessProfilePtr build_user_profile (Leosac::Auth::UserPtr u)
 Build an access for a user. More...
 
Leosac::Auth::SimpleAccessProfilePtr build_group_profile (Leosac::Auth::GroupPtr g)
 
Leosac::Auth::SimpleAccessProfilePtr build_cred_profile (Leosac::Cred::ICredentialPtr c)
 
void add_cred_to_id_map (Leosac::Cred::ICredentialPtr credential)
 Store the credential to the id <-> credential map if the id is non-empty. More...
 
void load_users (const boost::property_tree::ptree &users)
 Load users from configuration tree, storing them in the users_ map. More...
 
void load_schedules (const boost::property_tree::ptree &schedules)
 Load the schedules information from the config tree. More...
 
void map_schedules (const boost::property_tree::ptree &schedules_mapping)
 Interpret the schedule mapping content of the config file. More...
 
void load_groups (const boost::property_tree::ptree &group_mapping)
 Extract group membership. More...
 
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 access. More...
 
std::vector< Leosac::Auth::GroupPtrget_user_groups (Leosac::Auth::UserPtr u)
 Naive method that bruteforce groups to try to find membership for an user. More...
 
Leosac::Auth::IAccessProfilePtr merge_profiles (const std::vector< Leosac::Auth::IAccessProfilePtr > profiles)
 Merge a bunch of profiles together and returns a new profile. More...
 
Leosac::Auth::ValidityInfo extract_credentials_validity (const boost::property_tree::ptree &node)
 

Private Attributes

std::string config_file_
 Store the name of the configuration file. More...
 
std::map< std::string, Leosac::Auth::UserPtrusers_
 Maps user id (or name) to object. More...
 
std::map< std::string, Leosac::Auth::GroupPtrgroups_
 Maps group name to object. More...
 
std::unordered_map< std::string, Leosac::Cred::RFIDCardPtrrfid_cards_
 Maps card_id to object. More...
 
std::unordered_map< std::string, Leosac::Cred::PinCodePtrpin_codes_
 Maps PIN code to object. More...
 
std::map< std::pair< std::string, std::string >, Leosac::Cred::RFIDCardPinPtrrfid_cards_pin
 Maps WiegandCard + PIN code to object. More...
 
std::unordered_map< std::string, Leosac::Cred::ICredentialPtrid_to_cred_
 Maps credentials ID (from XML) to object. More...
 
Tools::XmlScheduleLoader xml_schedules_
 
std::vector< Tools::ScheduleMappingPtrmappings_
 List of mappings defined in the configuration file. More...
 
std::vector< Leosac::Auth::DoorPtrdoors_
 We store doors object, but really we only use the name property. More...
 
Tools::XmlNodeNameEnforcer xmlnne_
 

Additional Inherited Members

- Public Types inherited from Leosac::Tools::Visitor< WiegandCard >
using VisitableT = std::remove_reference_t< std::remove_const_t< WiegandCard > >
 
- Public Types inherited from Leosac::Tools::Visitor< PINCode >
using VisitableT = std::remove_reference_t< std::remove_const_t< PINCode > >
 
- Public Types inherited from Leosac::Tools::Visitor< WiegandCardPin >
using VisitableT = std::remove_reference_t< std::remove_const_t< WiegandCardPin > >
 
- Public Types inherited from Leosac::Tools::Visitor<::Leosac::Cred::RFIDCard >
using VisitableT = std::remove_reference_t< std::remove_const_t< ::Leosac::Cred::RFIDCard > >
 
- Public Types inherited from Leosac::Tools::Visitor<::Leosac::Cred::PinCode >
using VisitableT = std::remove_reference_t< std::remove_const_t< ::Leosac::Cred::PinCode > >
 
- Public Types inherited from Leosac::Tools::Visitor<::Leosac::Cred::RFIDCardPin >
using VisitableT = std::remove_reference_t< std::remove_const_t< ::Leosac::Cred::RFIDCardPin > >
 

Detailed Description

Use a file to map auth source (card, PIN, etc) to user.

Definition at line 47 of file FileAuthSourceMapper.hpp.

Constructor & Destructor Documentation

◆ FileAuthSourceMapper()

FileAuthSourceMapper::FileAuthSourceMapper ( const std::string &  auth_file)

Definition at line 42 of file FileAuthSourceMapper.cpp.

Member Function Documentation

◆ add_cred_to_id_map()

void FileAuthSourceMapper::add_cred_to_id_map ( Leosac::Cred::ICredentialPtr  credential)
private

Store the credential to the id <-> credential map if the id is non-empty.

Definition at line 444 of file FileAuthSourceMapper.cpp.

◆ build_cred_profile()

Leosac::Auth::SimpleAccessProfilePtr FileAuthSourceMapper::build_cred_profile ( Leosac::Cred::ICredentialPtr  c)
private

Definition at line 563 of file FileAuthSourceMapper.cpp.

◆ build_group_profile()

SimpleAccessProfilePtr FileAuthSourceMapper::build_group_profile ( Leosac::Auth::GroupPtr  g)
private

Definition at line 547 of file FileAuthSourceMapper.cpp.

◆ build_user_profile()

SimpleAccessProfilePtr FileAuthSourceMapper::build_user_profile ( Leosac::Auth::UserPtr  u)
private

Build an access for a user.

This simply check for mapping which are linked directly to the given user.

Definition at line 532 of file FileAuthSourceMapper.cpp.

◆ buildProfile()

Leosac::Auth::IAccessProfilePtr FileAuthSourceMapper::buildProfile ( Leosac::Cred::ICredentialPtr  auth_source)
virtual

Build an AccessProfile object given a Credential.

How the profile is built (ie, based only on user-id, based on auth source and user-id, group membership, etc) is implementation-defined.

The caller expect a valid profile object that will behave correctly or nullptr if no profile could be built.

Implements Leosac::Auth::IAuthSourceMapper.

Definition at line 460 of file FileAuthSourceMapper.cpp.

◆ extract_credentials_validity()

Leosac::Auth::ValidityInfo FileAuthSourceMapper::extract_credentials_validity ( const boost::property_tree::ptree &  node)
private

Definition at line 423 of file FileAuthSourceMapper.cpp.

◆ find_cred_by_alias()

Leosac::Cred::ICredentialPtr FileAuthSourceMapper::find_cred_by_alias ( const std::string &  alias)
private

Lookup a credentials by ID.

Definition at line 436 of file FileAuthSourceMapper.cpp.

◆ get_user_groups()

std::vector< GroupPtr > FileAuthSourceMapper::get_user_groups ( Leosac::Auth::UserPtr  u)
private

Naive method that bruteforce groups to try to find membership for an user.

Parameters
ua non-null pointer to user.
Returns
all group the user is a member of.

Definition at line 195 of file FileAuthSourceMapper.cpp.

◆ groups()

std::vector< GroupPtr > FileAuthSourceMapper::groups ( ) const
overridevirtual

Return the groups this mapper is aware of.

Implements Leosac::Auth::IAuthSourceMapper.

Definition at line 183 of file FileAuthSourceMapper.cpp.

◆ load_credentials()

void FileAuthSourceMapper::load_credentials ( const boost::property_tree::ptree &  credentials)
private

Eager loading of credentials to avoid walking through the ptree whenever we have to grant/deny an access.

Definition at line 233 of file FileAuthSourceMapper.cpp.

◆ load_groups()

void FileAuthSourceMapper::load_groups ( const boost::property_tree::ptree &  group_mapping)
private

Extract group membership.

Definition at line 151 of file FileAuthSourceMapper.cpp.

◆ load_schedules()

void FileAuthSourceMapper::load_schedules ( const boost::property_tree::ptree &  schedules)
private

Load the schedules information from the config tree.

Parameters
schedulesThe <schedules> subtree.

Definition at line 306 of file FileAuthSourceMapper.cpp.

◆ load_users()

void FileAuthSourceMapper::load_users ( const boost::property_tree::ptree &  users)
private

Load users from configuration tree, storing them in the users_ map.

Definition at line 384 of file FileAuthSourceMapper.cpp.

◆ map_schedules()

void FileAuthSourceMapper::map_schedules ( const boost::property_tree::ptree &  schedules_mapping)
private

Interpret the schedule mapping content of the config file.

This effectively build access profile for user.

Definition at line 313 of file FileAuthSourceMapper.cpp.

◆ mapToUser()

void FileAuthSourceMapper::mapToUser ( Leosac::Cred::ICredentialPtr  cred)
virtual

Must map the ICredential data to a User.

This is done by calling the owner() method on the auth source object. In case it fails, the field shall be set to nullptr.

Note
The User may be newed.

Implements Leosac::Auth::IAuthSourceMapper.

Definition at line 137 of file FileAuthSourceMapper.cpp.

◆ merge_profiles()

IAccessProfilePtr FileAuthSourceMapper::merge_profiles ( const std::vector< Leosac::Auth::IAccessProfilePtr profiles)
private

Merge a bunch of profiles together and returns a new profile.

If the resulting profile contains the schedule, this method will return nullptr.

Definition at line 218 of file FileAuthSourceMapper.cpp.

◆ visit() [1/3]

void FileAuthSourceMapper::visit ( ::Leosac::Cred::PinCode src)
overridevirtual

Try to map a PIN code to a user.

Definition at line 107 of file FileAuthSourceMapper.cpp.

◆ visit() [2/3]

void FileAuthSourceMapper::visit ( ::Leosac::Cred::RFIDCard src)
overridevirtual

Try to map a wiegand card_id to a user.

Definition at line 93 of file FileAuthSourceMapper.cpp.

◆ visit() [3/3]

void FileAuthSourceMapper::visit ( ::Leosac::Cred::RFIDCardPin src)
overridevirtual

Try to map a card id + a PIN code to a user.

Definition at line 121 of file FileAuthSourceMapper.cpp.

Member Data Documentation

◆ config_file_

std::string Leosac::Module::Auth::FileAuthSourceMapper::config_file_
private

Store the name of the configuration file.

Definition at line 157 of file FileAuthSourceMapper.hpp.

◆ doors_

std::vector<Leosac::Auth::DoorPtr> Leosac::Module::Auth::FileAuthSourceMapper::doors_
private

We store doors object, but really we only use the name property.

On door object is created for each mapping that specify a door.

Definition at line 204 of file FileAuthSourceMapper.hpp.

◆ groups_

std::map<std::string, Leosac::Auth::GroupPtr> Leosac::Module::Auth::FileAuthSourceMapper::groups_
private

Maps group name to object.

Definition at line 167 of file FileAuthSourceMapper.hpp.

◆ id_to_cred_

std::unordered_map<std::string, Leosac::Cred::ICredentialPtr> Leosac::Module::Auth::FileAuthSourceMapper::id_to_cred_
private

Maps credentials ID (from XML) to object.

If id is empty, the cred wont end up is this list.

Definition at line 190 of file FileAuthSourceMapper.hpp.

◆ mappings_

std::vector<Tools::ScheduleMappingPtr> Leosac::Module::Auth::FileAuthSourceMapper::mappings_
private

List of mappings defined in the configuration file.

Definition at line 197 of file FileAuthSourceMapper.hpp.

◆ pin_codes_

std::unordered_map<std::string, Leosac::Cred::PinCodePtr> Leosac::Module::Auth::FileAuthSourceMapper::pin_codes_
private

Maps PIN code to object.

Definition at line 178 of file FileAuthSourceMapper.hpp.

◆ rfid_cards_

std::unordered_map<std::string, Leosac::Cred::RFIDCardPtr> Leosac::Module::Auth::FileAuthSourceMapper::rfid_cards_
private

Maps card_id to object.

Definition at line 172 of file FileAuthSourceMapper.hpp.

◆ rfid_cards_pin

std::map<std::pair<std::string, std::string>, Leosac::Cred::RFIDCardPinPtr> Leosac::Module::Auth::FileAuthSourceMapper::rfid_cards_pin
private

Maps WiegandCard + PIN code to object.

Definition at line 184 of file FileAuthSourceMapper.hpp.

◆ users_

std::map<std::string, Leosac::Auth::UserPtr> Leosac::Module::Auth::FileAuthSourceMapper::users_
private

Maps user id (or name) to object.

Definition at line 162 of file FileAuthSourceMapper.hpp.

◆ xml_schedules_

Tools::XmlScheduleLoader Leosac::Module::Auth::FileAuthSourceMapper::xml_schedules_
private

Definition at line 192 of file FileAuthSourceMapper.hpp.

◆ xmlnne_

Tools::XmlNodeNameEnforcer Leosac::Module::Auth::FileAuthSourceMapper::xmlnne_
private

Definition at line 206 of file FileAuthSourceMapper.hpp.


The documentation for this class was generated from the following files: