olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
AuthorizeRequest.h
1/*
2 * Copyright (C) 2020 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include <string>
23#include <vector>
24
25#include <olp/authentication/AuthenticationApi.h>
26#include <olp/core/porting/optional.h>
27
28namespace olp {
29namespace authentication {
30
47class AUTHENTICATION_API AuthorizeRequest final {
48 public:
58 using Action = std::pair<std::string, std::string>;
59
63 using Actions = std::vector<Action>;
64
79 enum class DecisionOperatorType { kAnd, kOr };
80
86 const std::string& GetServiceId() const { return service_id_; }
87
95 AuthorizeRequest& WithServiceId(std::string service_id) {
96 service_id_ = std::move(service_id);
97 return *this;
98 }
99
112 const porting::optional<std::string>& GetContractId() const {
113 return contract_id_;
114 }
115
125 template <class T = porting::optional<std::string>>
127 contract_id_ = std::forward<T>(contract_id);
128 return *this;
129 }
130
140 AuthorizeRequest& WithContractId(std::string contract_id) {
141 contract_id_ = std::move(contract_id);
142 return *this;
143 }
144
150 inline const Actions& GetActions() const { return actions_; }
151
162 AuthorizeRequest& WithAction(std::string action, std::string resource = "") {
163 actions_.emplace_back(std::move(action), std::move(resource));
164 return *this;
165 }
166
176 DecisionOperatorType GetOperatorType() const { return operator_type_; }
177
188 operator_type_ = operator_type;
189 return *this;
190 }
191
197 bool GetDiagnostics() const { return diagnostics_; }
198
208 diagnostics_ = diagnostics;
209 return *this;
210 }
211
217 std::string CreateKey() const;
218
219 private:
220 std::string service_id_;
221 porting::optional<std::string> contract_id_;
222 Actions actions_;
223 DecisionOperatorType operator_type_{DecisionOperatorType::kAnd};
224 bool diagnostics_{false};
225};
226
227} // namespace authentication
228} // namespace olp
Encapsulates the fields required to make a policy decision for a given request context against the HE...
Definition AuthorizeRequest.h:47
const porting::optional< std::string > & GetContractId() const
Gets the contract ID.
Definition AuthorizeRequest.h:112
std::vector< Action > Actions
An alias for the vector of actions.
Definition AuthorizeRequest.h:63
AuthorizeRequest & WithContractId(std::string contract_id)
Sets the contract ID.
Definition AuthorizeRequest.h:140
AuthorizeRequest & WithContractId(T &&contract_id)
Sets the contract ID.
Definition AuthorizeRequest.h:126
AuthorizeRequest & WithOperatorType(DecisionOperatorType operator_type)
Sets the operator type for the request.
Definition AuthorizeRequest.h:187
DecisionOperatorType GetOperatorType() const
Gets the operator type.
Definition AuthorizeRequest.h:176
std::string CreateKey() const
Creates a readable format for the request.
AuthorizeRequest & WithServiceId(std::string service_id)
Sets the service ID.
Definition AuthorizeRequest.h:95
AuthorizeRequest & WithDiagnostics(bool diagnostics)
Sets the diagnostics flag for the request.
Definition AuthorizeRequest.h:207
const Actions & GetActions() const
Gets all actions.
Definition AuthorizeRequest.h:150
bool GetDiagnostics() const
Gets the diagnostics flag.
Definition AuthorizeRequest.h:197
std::pair< std::string, std::string > Action
An alias for the action pair.
Definition AuthorizeRequest.h:58
const std::string & GetServiceId() const
Gets the ID of the requested service.
Definition AuthorizeRequest.h:86
AuthorizeRequest & WithAction(std::string action, std::string resource="")
Adds the action-resource pair.
Definition AuthorizeRequest.h:162
DecisionOperatorType
Determines the overall policy decision based on individual decisions for each action.
Definition AuthorizeRequest.h:79
Rules all the other namespaces.
Definition AppleSignInProperties.h:24