Leosac  0.8.0
Open Source Access Control
ValidityInfo.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 "AuthFwd.hpp"
23 #include <chrono>
24 #include <string>
25 
26 namespace Leosac
27 {
28 namespace Auth
29 {
41 #pragma db value
43 {
44  public:
45  using TimePoint = std::chrono::system_clock::time_point;
46 
50  ValidityInfo();
51 
52  ValidityInfo(const ValidityInfo &) = default;
53 
59  bool is_valid() const;
60 
64  bool is_enabled() const;
65 
69  bool is_in_range() const;
70 
78  void set_start_date(const std::string &s);
79 
87  void set_end_date(const std::string &s);
88 
89  void set_enabled(bool v);
90 
91  const TimePoint &start() const;
92  void start(const TimePoint &tp);
93 
94  const TimePoint &end() const;
95  void end(const TimePoint &tp);
96 
97  private:
98  friend class odb::access;
99 
101 
103 
104  bool enabled_;
105 };
106 }
107 }
Leosac::Auth::ValidityInfo::set_start_date
void set_start_date(const std::string &s)
Set the start validity date.
Definition: ValidityInfo.cpp:51
AuthFwd.hpp
Leosac::Auth::ValidityInfo::enabled_
bool enabled_
Definition: ValidityInfo.hpp:104
Leosac::Auth::ValidityInfo::is_enabled
bool is_enabled() const
Is the credential enabled ?
Definition: ValidityInfo.cpp:39
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::ValidityInfo::ValidityInfo
ValidityInfo()
Default status is: enabled and no time-based limitation.
Definition: ValidityInfo.cpp:27
Leosac::Auth::ValidityInfo::set_enabled
void set_enabled(bool v)
Definition: ValidityInfo.cpp:93
Leosac::Auth::ValidityInfo::end
const TimePoint & end() const
Definition: ValidityInfo.cpp:103
Leosac::Auth::ValidityInfo::TimePoint
std::chrono::system_clock::time_point TimePoint
Definition: ValidityInfo.hpp:45
Leosac::Auth::ValidityInfo::is_valid
bool is_valid() const
Check that the current date is between validity start and end and make sure its enabled too.
Definition: ValidityInfo.cpp:34
Leosac::Auth::ValidityInfo::end_
TimePoint end_
Definition: ValidityInfo.hpp:102
Leosac::Auth::ValidityInfo::access
friend class odb::access
Definition: ValidityInfo.hpp:98
Leosac::Auth::ValidityInfo::start
const TimePoint & start() const
Definition: ValidityInfo.cpp:98
Leosac::Auth::ValidityInfo::start_
TimePoint start_
Definition: ValidityInfo.hpp:100
Leosac::Auth::ValidityInfo::set_end_date
void set_end_date(const std::string &s)
Set the end validity date.
Definition: ValidityInfo.cpp:72
Leosac::Auth::ValidityInfo
A simple class that stores (and can be queried for) the validity of some objects.
Definition: ValidityInfo.hpp:42
Leosac::Auth::ValidityInfo::is_in_range
bool is_in_range() const
Are we currently is the validity range of the credential ?
Definition: ValidityInfo.cpp:44