Leosac  0.8.0
Open Source Access Control
SimpleAccessProfile.cpp
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 #include "SimpleAccessProfile.hpp"
21 #include <assert.h>
22 #include <tools/log.hpp>
23 
24 using namespace Leosac::Auth;
26 
28  const std::chrono::system_clock::time_point &date, AuthTargetPtr target)
29 {
30  // check "general" permissions that apply to all target
31  for (const auto &sched : default_schedule_)
32  {
33  if (sched->is_in_schedule(date))
34  {
35  INFO("Access is granted through schedule '" << sched->name() << "'");
36  return true;
37  }
38  }
39 
40  // check door specific permissions.
41  if (target && schedules_[target->name()].size())
42  {
43  for (const auto &sched : schedules_[target->name()])
44  {
45  if (sched->is_in_schedule(date))
46  {
47  INFO("Access is granted through schedule '" << sched->name() << "'");
48  return true;
49  }
50  }
51  }
52  return false;
53 }
54 
56  AuthTargetPtr target, Leosac::Tools::IScheduleCPtr const &sched)
57 {
58  if (target)
59  schedules_[target->name()].push_back(sched);
60  else
61  default_schedule_.push_back(sched);
62 }
63 
64 std::map<std::string, std::vector<Leosac::Tools::IScheduleCPtr>> const &
66 {
67  return schedules_;
68 }
69 
70 std::vector<Leosac::Tools::IScheduleCPtr> const &
72 {
73  return default_schedule_;
74 }
75 
77 {
78  return default_schedule_.size() + schedules_.size();
79 }
Leosac::Auth
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
SimpleAccessProfile.hpp
INFO
@ INFO
Definition: log.hpp:34
Leosac::Auth::SimpleAccessProfile::schedules_
std::map< std::string, std::vector< Tools::IScheduleCPtr > > schedules_
Map target name to target's schedules.
Definition: SimpleAccessProfile.hpp:68
Leosac::Auth::SimpleAccessProfile::defaultSchedules
virtual const std::vector< Tools::IScheduleCPtr > & defaultSchedules() const
Definition: SimpleAccessProfile.cpp:71
Leosac::Auth::SimpleAccessProfile::default_schedule_
std::vector< Tools::IScheduleCPtr > default_schedule_
Schedule for default target.
Definition: SimpleAccessProfile.hpp:73
Leosac::Auth::AuthTargetPtr
std::shared_ptr< AuthTarget > AuthTargetPtr
Definition: AuthFwd.hpp:93
Leosac::Auth::SimpleAccessProfile::addAccessSchedule
virtual void addAccessSchedule(AuthTargetPtr target, const Tools::IScheduleCPtr &sched)
Adds a schedule where access to a given target is allowed.
Definition: SimpleAccessProfile.cpp:55
Leosac::Tools::IScheduleCPtr
std::shared_ptr< const ISchedule > IScheduleCPtr
Definition: ToolsFwd.hpp:38
Leosac::Auth::SimpleAccessProfile::schedules
virtual const std::map< std::string, std::vector< Tools::IScheduleCPtr > > & schedules() const
Returns the map of schedule for each target (except the default target)
Definition: SimpleAccessProfile.cpp:65
Leosac::Auth::SimpleAccessProfile::schedule_count
virtual size_t schedule_count() const override
Returns the number of schedule associated with the profile.
Definition: SimpleAccessProfile.cpp:76
Leosac::Auth::SimpleAccessProfile::isAccessGranted
virtual bool isAccessGranted(const std::chrono::system_clock::time_point &date, AuthTargetPtr target) override
Does the profile allow access to the user.
Definition: SimpleAccessProfile.cpp:27
SingleTimeFrame
Leosac::Tools::SingleTimeFrame SingleTimeFrame
Definition: SimpleAccessProfile.cpp:25
log.hpp
Leosac::Tools::SingleTimeFrame
This struct abstracts what we call a single time frame.
Definition: SingleTimeFrame.hpp:38