More refactoring. Implement an ACL file. Care about token timeouts.
This commit is contained in:
1 parent
deb1cef30f
commit
4f60efa87a
12 files changed
+236
-50
No files matched your search
@@ -12,19 +12,22 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
#include <forward_list>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using time_T = std::chrono::time_point<std::chrono::system_clock>;
|
||||
|
||||
// A list with easily checkable contents.
|
||||
class AuthList
|
||||
{
|
||||
public:
|
||||
AuthList();
|
||||
|
||||
void add(const std::string& username);
|
||||
void add(const std::string& username, const time_T& expr_time);
|
||||
void remove(const std::string& username);
|
||||
bool confirm(const std::string& username);
|
||||
|
||||
private:
|
||||
std::forward_list<std::string> _allowedUsernames;
|
||||
std::map<std::string, time_T> _map;
|
||||
};
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include <j7s-plugin/AuthList.hpp>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -22,7 +24,7 @@
|
||||
class Authorizer
|
||||
{
|
||||
public:
|
||||
Authorizer(const std::string& pub_key, const std::string& issuer);
|
||||
Authorizer(const std::string& pub_key, const std::string& issuer, const std::string& aclFilePath);
|
||||
static std::optional<std::string> read_key(const std::string& key_file);
|
||||
void add_unknown(const std::string& username);
|
||||
bool is_unknown(const std::string& username);
|
||||
@@ -35,6 +37,8 @@ private:
|
||||
AuthList _readList;
|
||||
AuthList _unknownList;
|
||||
|
||||
YAML::Node _aclFile;
|
||||
|
||||
std::string _pub_key;
|
||||
std::string _issuer;
|
||||
};
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
std::optional<std::string> read_key(const std::string & key_file);
|
||||
|
||||
bool validate(
|
||||
std::tuple<bool, std::chrono::time_point<std::chrono::system_clock>> validate(
|
||||
const std::string & token,
|
||||
const std::string & username,
|
||||
const std::string & issuer,
|
||||
|
||||
Reference in new issue
Block a user