36 #include <boost/algorithm/string.hpp>    43     : config_file_(auth_file)
    44     , xmlnne_(config_file_)
    54         DEBUG(
"Will load tree");
    56         additional_config        = additional_config.get_child(
"root");
    59         const auto &users_tree = additional_config.get_child_optional(
"users");
    63         const auto &groups_tree =
    64             additional_config.get_child_optional(
"group_mapping");
    68         const auto &credentials_tree =
    69             additional_config.get_child_optional(
"credentials");
    73         const auto &schedules_tree =
    74             additional_config.get_child_optional(
"schedules");
    78         const auto &schedule_mapping_tree =
    79             additional_config.get_child_optional(
"schedules_mapping");
    80         if (schedule_mapping_tree)
    85     catch (std::exception &e)
    87         ERROR(
"Exception: " << e.what());
    88         std::throw_with_nested(
    98         auto cred = it->second;
   112         auto cred = it->second;
   128         auto cred = it->second;
   146         std::throw_with_nested(
   152     const boost::property_tree::ptree &group_mapping)
   156     for (
const auto &group_info : group_mapping)
   158         const boost::property_tree::ptree &node = group_info.second;
   159         const std::string &group_name           = node.get<std::string>(
"group");
   161         xmlnne_(
"map", group_info.first);
   167         for (
const auto &membership : node)
   169             if (membership.first != 
"user")
   171             std::string user_name = membership.second.data();
   175                 ERROR(
"Unknown user " << user_name);
   178             grp->member_add(user);
   185     std::vector<GroupPtr> ret;
   188     for (
const auto &map_entry : 
groups_)
   190         ret.push_back(map_entry.second);
   198     std::vector<GroupPtr> grps;
   199     auto lambda_cmp = [&](
UserPtr user) -> 
bool {
   200         return user->username() == u->username();
   203     for (
const auto &grp_map : 
groups_)
   206         std::tie(std::ignore, grp) = grp_map;
   208         if (std::find_if(grp->members().begin(), grp->members().end(), lambda_cmp) !=
   209             grp->members().end())
   223     for (
auto &profile : profiles)
   226             result = merger.
merge(result, profile);
   228     if (result->schedule_count())
   234     const boost::property_tree::ptree &credentials)
   237     for (
const auto &mapping : credentials)
   239         const std::string &node_name            = mapping.first;
   240         const boost::property_tree::ptree &node = mapping.second;
   244         std::string user_id = node.get<std::string>(
"user");
   248                 config_file_, 
"Credentials defined for undefined user " + user_id);
   254         auto opt_child = node.get_child_optional(
"WiegandCard");
   257             std::string card_id = opt_child->get<std::string>(
"card_id");
   258             int bits            = opt_child->get<
int>(
"bits");
   266         else if (opt_child = node.get_child_optional(
"PINCode"))
   269             std::string pin = opt_child->get<std::string>(
"pin");
   276         else if (opt_child = node.get_child_optional(
"WiegandCardPin"))
   278             std::string card_id = opt_child->get<std::string>(
"card_id");
   279             std::string pin     = opt_child->get<std::string>(
"pin");
   280             int bits            = opt_child->get<
int>(
"bits");
   282             auto c = std::make_shared<Cred::RFIDCard>();
   287             auto p = std::make_shared<Cred::PinCode>();
   290             credential = std::make_shared<Cred::RFIDCardPin>(c, p);
   295         credential->id(cred_id++);
   297         credential->owner(user);
   301         credential->alias(opt_child->get<std::string>(
"id", 
""));
   307     const boost::property_tree::ptree &schedules)
   314     const boost::property_tree::ptree &schedules_mapping)
   316     for (
const auto &mapping_entry : schedules_mapping)
   318         const std::string &node_name            = mapping_entry.first;
   319         const boost::property_tree::ptree &node = mapping_entry.second;
   324         std::list<std::string> schedule_names;
   325         std::list<std::string> user_names;
   326         std::list<std::string> group_names;
   327         std::list<std::string> credential_names;
   328         std::string target_door;
   329         target_door = node.get<std::string>(
"door", 
"");
   330         auto door(std::make_shared<Leosac::Auth::Door>());
   331         door->alias(target_door);
   335         for (
const auto &mapping_data : node)
   337             if (mapping_data.first == 
"door")
   339             if (mapping_data.first == 
"schedule")
   340                 schedule_names.push_back(mapping_data.second.data());
   341             if (mapping_data.first == 
"user")
   342                 user_names.push_back(mapping_data.second.data());
   343             if (mapping_data.first == 
"group")
   344                 group_names.push_back(mapping_data.second.data());
   345             if (mapping_data.first == 
"credential")
   346                 credential_names.push_back(mapping_data.second.data());
   350         for (
const auto &schedule_name : schedule_names)
   358             if (!door->alias().empty())
   361             for (
const auto &user_name : user_names)
   367             for (
const auto &group_name : group_names)
   372             for (
const auto &cred_id : credential_names)
   374                 DEBUG(
"CRED  = " << cred_id);
   376                 sm->add_credential(assert_cast<Cred::CredentialPtr>(cred));
   389     for (
const auto &user : users)
   391         const std::string &node_name            = user.first;
   392         const boost::property_tree::ptree &node = user.second;
   396         std::string username  = node.get<std::string>(
"name");
   397         std::string firstname = node.get<std::string>(
"firstname", 
"");
   398         std::string lastname  = node.get<std::string>(
"lastname", 
"");
   399         std::string email     = node.get<std::string>(
"email", 
"");
   401         if (username == 
"UNKNOWN_USER") 
   403                                   "'UNKNOWN_USER' is a reserved name. Do not use.");
   405         UserPtr uptr(std::make_unique<User>(user_id++));
   406         uptr->username(username);
   407         uptr->firstname(firstname);
   408         uptr->lastname(lastname);
   415         if (
users_.count(username))
   417             NOTICE(
"User " << username << 
" was already defined. Will overwrite.");
   424     const boost::property_tree::ptree &node)
   429     v.
set_end_date(node.get<std::string>(
"validity_end", 
""));
   447     if (!credential->alias().empty())
   451             NOTICE(
"Credential with ID = " << credential->alias()
   452                                            << 
" already exist and "   453                                               "will be overwritten.");
   463     std::vector<GroupPtr> grps;
   464     std::vector<IAccessProfilePtr> profiles; 
   468         ASSERT_LOG(cred->owner().get_eager(), 
"Sanity check failed.");
   470     auto cred_owner = cred->owner().get_eager();
   471     if (!cred->validity().is_valid())
   473         NOTICE(
"Credentials is invalid. It was disabled or out of its validity "   478     if (cred_owner && !cred_owner->is_valid())
   480         NOTICE(
"The user (" << cred_owner->username()
   481                             << 
") is disabled or out of its validity period.");
   492         for (
auto &grp : grps)
   505     ASSERT_LOG(mapping, 
"Mapping cannot be null");
   506     ASSERT_LOG(profile, 
"Profile cannot be null");
   508     auto schedule = 
LEOSAC_ENFORCE(mapping->schedule().get_eager().lock(),
   509                                    "Cannot retrieve schedule from mapping");
   511     if (mapping->doors().size())
   514         for (
auto lazy_weak_door : mapping->doors())
   517                                            "Cannot get Door from mapping");
   518             profile->addAccessSchedule(
   519                 std::make_shared<AuthTarget>(door_ptr->alias()),
   520                 std::static_pointer_cast<const Leosac::Tools::ISchedule>(schedule));
   526         profile->addAccessSchedule(
   528             std::static_pointer_cast<const Leosac::Tools::ISchedule>(schedule));
   536     auto profile(std::make_shared<SimpleAccessProfile>());
   539         if (mapping->has_user(u->id()))
   541             add_schedule_from_mapping_to_profile(mapping, profile);
   551     auto profile(std::make_shared<SimpleAccessProfile>());
   554         if (mapping->has_group(g->id()))
   556             add_schedule_from_mapping_to_profile(mapping, profile);
   567     auto profile(std::make_shared<SimpleAccessProfile>());
   570         if (mapping->has_cred(c->id()))
   572             add_schedule_from_mapping_to_profile(mapping, profile);
 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. 
 
Helper class that merges profile together. 
 
void load_groups(const boost::property_tree::ptree &group_mapping)
Extract group membership. 
 
std::shared_ptr< PinCode > PinCodePtr
 
virtual void mapToUser(Leosac::Cred::ICredentialPtr auth_source)
Must map the ICredential data to a User. 
 
Exception class for modules. 
 
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)
 
Tools::XmlScheduleLoader xml_schedules_
 
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. 
 
Cred::ICredentialPtr find_cred_by_alias(const std::string &alias)
Lookup a credentials by ID. 
 
Tools::XmlNodeNameEnforcer xmlnne_
 
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. 
 
std::shared_ptr< RFIDCard > RFIDCardPtr
 
void set_start_date(const std::string &s)
Set the start validity date. 
 
A simple class that stores (and can be queried for) the validity of some objects. ...
 
std::vector< Tools::ScheduleMappingPtr > mappings_
List of mappings defined in the configuration file. 
 
A authentication group regroup users that share permissions. 
 
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. 
 
const std::string & pin_code() const override
 
const PinCode & pin() const
 
std::map< std::string, Leosac::Auth::GroupPtr > groups_
Maps group name to object. 
 
std::shared_ptr< ICredential > ICredentialPtr
 
std::shared_ptr< IAccessProfile > IAccessProfilePtr
 
std::shared_ptr< Group > GroupPtr
 
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. 
 
Holds classes relevant to the Authentication and Authorization subsystem. 
 
std::vector< Leosac::Auth::DoorPtr > doors_
We store doors object, but really we only use the name property. 
 
std::shared_ptr< User > UserPtr
 
#define LEOSAC_ENFORCE(cond,...)
Similar to enforce, except that it will throw a LEOSACException. 
 
Concrete implementation of a simple access control class. 
 
Authentication backend modules live here. 
 
#define ASSERT_LOG(cond, msg)
 
Leosac::Auth::SimpleAccessProfilePtr build_group_profile(Leosac::Auth::GroupPtr g)
 
FileAuthSourceMapper(const std::string &auth_file)
 
const RFIDCard & card() const
 
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. 
 
unsigned long CredentialId
 
virtual IAccessProfilePtr merge(std::shared_ptr< const IAccessProfile > p1, std::shared_ptr< const IAccessProfile > p2)
Build a new Profile object by merging two profiles. 
 
std::shared_ptr< SimpleAccessProfile > SimpleAccessProfilePtr
 
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. 
 
void set_end_date(const std::string &s)
Set the end validity date. 
 
Leosac::Auth::SimpleAccessProfilePtr build_cred_profile(Leosac::Cred::ICredentialPtr c)
 
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...
 
virtual const std::string & card_id() const override
 
std::enable_if_t< is_shared_ptr_v< Out >, Out > assert_cast(const std::shared_ptr< In > &in)