Kea 3.3.4
rbac.h
Go to the documentation of this file.
1// Copyright (C) 2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef RBAC_H
8#define RBAC_H
9
10#include <cc/simple_parser.h>
11
12#include <rbac/rbac_acl.h>
14#include <rbac/rbac_role.h>
15
16namespace isc {
17namespace rbac {
18
20class RoleConfig;
21
23typedef boost::shared_ptr<RoleConfig> RoleConfigPtr;
24
26typedef std::map<std::string, RoleConfigPtr> RoleConfigTable;
27
35public:
38
47 RoleConfig(const std::string& name,
48 const AclPtr& accept, const AclPtr& reject,
49 bool others, bool preference,
50 const ResponseFilterList& response_filters)
51 : name_(name), accept_(accept), reject_(reject),
52 others_(others), preference_(preference),
53 response_filters_(response_filters) {
54 }
55
57 virtual ~RoleConfig() = default;
58
60 std::string name_;
61
64
67
69 bool others_;
70
73
76
81 bool match(const std::string& command) const {
82 if (preference_) {
83 if (accept_ && accept_->match(command)) {
84 return (true);
85 }
86 if (reject_ && reject_->match(command)) {
87 return (false);
88 }
89 } else {
90 if (reject_ && reject_->match(command)) {
91 return (false);
92 }
93 if (accept_ && accept_->match(command)) {
94 return (true);
95 }
96 }
97 return (others_);
98 }
99
105 bool filter(const std::string& command, data::ConstElementPtr body) const {
106 bool modified = false;
107 for (auto const& response_filter : response_filters_) {
108 if (response_filter) {
109 if (response_filter->filter(command, *this, body)) {
110 modified = true;
111 }
112 }
113 }
114 return (modified);
115 }
116
121 static RoleConfigPtr getConfig(const std::string& role);
122
129 std::string name = "");
130
136 createReject(const http::HttpRequestPtr& request,
137 const http::HttpStatusCode& status_code);
138};
139
141extern RolePtr roleAssign;
142
145
148
151
152} // end of namespace rbac
153} // end of namespace isc
154#endif
Per role configuration class.
Definition rbac.h:34
AclPtr accept_
Accept command access control list.
Definition rbac.h:63
RoleConfig(const std::string &name, const AclPtr &accept, const AclPtr &reject, bool others, bool preference, const ResponseFilterList &response_filters)
Constructor.
Definition rbac.h:47
ResponseFilterList response_filters_
Response filters.
Definition rbac.h:75
bool filter(const std::string &command, data::ConstElementPtr body) const
Filter a response.
Definition rbac.h:105
static http::HttpResponseJsonPtr createReject(const http::HttpRequestPtr &request, const http::HttpStatusCode &status_code)
Create a reject response.
Definition rbac.cc:129
std::string name_
Role name.
Definition rbac.h:60
static const data::SimpleKeywords ROLE_PARAMETERS
Role configuration parameters.
Definition rbac.h:37
static RoleConfigPtr parse(data::ConstElementPtr cfg, std::string name="")
Parse a role config.
Definition rbac.cc:53
static RoleConfigPtr getConfig(const std::string &role)
Return the role config.
Definition rbac.cc:41
bool preference_
Action for both matching.
Definition rbac.h:72
bool match(const std::string &command) const
Match access control list.
Definition rbac.h:81
AclPtr reject_
Reject command access control list.
Definition rbac.h:66
bool others_
Action for other commands.
Definition rbac.h:69
virtual ~RoleConfig()=default
Destructor.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
HttpStatusCode
HTTP status codes (cf RFC 2068).
Definition response.h:31
boost::shared_ptr< HttpResponseJson > HttpResponseJsonPtr
Pointer to the HttpResponseJson object.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition request.h:30
boost::shared_ptr< RoleConfig > RoleConfigPtr
Type of shared pointers to role configurations.
Definition rbac.h:23
RolePtr roleAssign
The role assignment.
Definition rbac.cc:22
boost::shared_ptr< Acl > AclPtr
Type of shared pointers to Acl.
Definition rbac_acl.h:29
std::list< ResponseFilterPtr > ResponseFilterList
The type of list of shared pointers to response filters.
boost::shared_ptr< Role > RolePtr
Type of shared pointers to Role.
Definition rbac_role.h:20
std::map< std::string, RoleConfigPtr > RoleConfigTable
Type of the role configurations table.
Definition rbac.h:26
RoleConfigPtr defaultRoleConfig
The default (role is "") role configuration.
Definition rbac.cc:26
RoleConfigPtr unknownRoleConfig
The unknown (role is not in the table) role configuration.
Definition rbac.cc:28
RoleConfigTable roleConfigTable
The role configurations table.
Definition rbac.cc:24
Defines the logger used by the top-level component of kea-lfc.