MantisBase v0.4.9
Loading...
Searching...
No Matches
access_rules.h
Go to the documentation of this file.
1
5
6#ifndef MANTISBASE_ACCESS_RULES_H
7#define MANTISBASE_ACCESS_RULES_H
8
9#include <string>
10#include <utility>
11#include <nlohmann/json.hpp>
13
14namespace mb {
15 class MbRequest;
16
18 [[nodiscard]] MANTISBASE_API bool isGuestAuth(const nlohmann::json &auth);
20 [[nodiscard]] MANTISBASE_API bool isAdminAuth(const nlohmann::json &auth);
22 [[nodiscard]] MANTISBASE_API bool isUserAuth(const nlohmann::json &auth);
23
31
34 const nlohmann::json &auth;
35 const nlohmann::json &verification;
36 MbRequest *req = nullptr;
37 };
38
46 public:
48 explicit MbAccessRule(const std::string &mode = "", const std::string &expr = "",
49 const std::string &entity = "");
50
52 [[nodiscard]] nlohmann::json toJSON() const;
54 static MbAccessRule fromJSON(const nlohmann::json &j);
55
57 [[nodiscard]] std::string mode() const;
58 void setMode(const std::string &_mode);
59
61 [[nodiscard]] std::string expr() const;
62 void setExpr(const std::string &_expr);
63
65 [[nodiscard]] std::string entity() const;
66 void setEntity(const std::string &_entity);
67
69 [[nodiscard]] bool matchesAuthEntity(const std::string &userEntity) const;
70
71 private:
72 static void validateEntityFilter(const std::string &entity);
73 static void validateEntityFilterForMode(const std::string &mode, const std::string &entity);
74
75 std::string m_mode, m_expr, m_entity;
76 };
77
80
82 [[nodiscard]] MANTISBASE_API nlohmann::json buildAccessExprVars(const MbRequest &req, const nlohmann::json &auth);
83
85 [[nodiscard]] MANTISBASE_API nlohmann::json buildAccessExprVars(const nlohmann::json &auth, const std::string &remote_addr,
86 int remote_port, const std::string &local_addr, int local_port,
87 const nlohmann::json &body = nlohmann::json::object());
88
90 [[nodiscard]] MANTISBASE_API std::pair<int, std::string> accessEvalHttpError(MbAccessEvalResult result,
91 const MbAccessRule &rule = MbAccessRule{});
92} // mb
93
94#endif //MANTISBASE_ACCESS_RULES_H
Access control rule for entity permissions.
Definition access_rules.h:45
void setEntity(const std::string &_entity)
Definition access_rules.cpp:173
MbAccessRule(const std::string &mode="", const std::string &expr="", const std::string &entity="")
Definition access_rules.cpp:113
bool matchesAuthEntity(const std::string &userEntity) const
Definition access_rules.cpp:178
std::string expr() const
Definition access_rules.cpp:165
nlohmann::json toJSON() const
Definition access_rules.cpp:125
void setExpr(const std::string &_expr)
Definition access_rules.cpp:167
std::string mode() const
Definition access_rules.cpp:151
void setMode(const std::string &_mode)
Definition access_rules.cpp:153
static MbAccessRule fromJSON(const nlohmann::json &j)
Definition access_rules.cpp:136
std::string entity() const
Definition access_rules.cpp:171
HTTP request wrapper bound to a MantisBase instance.
Definition http.h:66
#define MANTISBASE_API
Definition export.h:31
Definition api_keys.h:35
MbAccessEvalResult
Definition access_rules.h:25
@ DenyUnauthenticated
Credentials required but missing/invalid.
Definition access_rules.h:27
@ Allow
Rule permits access.
Definition access_rules.h:26
@ DenyUnknownRule
Unrecognized rule mode or malformed config.
Definition access_rules.h:29
@ DenyForbidden
Authenticated but rule rejected the caller.
Definition access_rules.h:28
MANTISBASE_API bool isUserAuth(const nlohmann::json &auth)
Definition access_rules.cpp:77
MANTISBASE_API nlohmann::json buildAccessExprVars(const MbRequest &req, const nlohmann::json &auth)
Definition access_rules.cpp:212
MANTISBASE_API bool isGuestAuth(const nlohmann::json &auth)
Definition access_rules.cpp:62
MANTISBASE_API std::pair< int, std::string > accessEvalHttpError(MbAccessEvalResult result, const MbAccessRule &rule=MbAccessRule{})
Definition access_rules.cpp:296
MANTISBASE_API bool isAdminAuth(const nlohmann::json &auth)
Definition access_rules.cpp:72
MANTISBASE_API MbAccessEvalResult evaluateAccessRule(const MbAccessRule &rule, const MbAccessEvalContext &ctx)
Definition access_rules.cpp:244
Definition access_rules.h:33
const nlohmann::json & auth
Resolved auth block from middleware.
Definition access_rules.h:34
const nlohmann::json & verification
JWT/API-key verification metadata.
Definition access_rules.h:35
MbRequest * req
Optional HTTP request (custom rules).
Definition access_rules.h:36
Core type aliases, handler signatures, and the MbAppMixin DI mixin.