olp-cpp-sdk  1.22.0
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 <boost/optional.hpp>
23 #include <string>
24 #include <vector>
25 
26 #include <olp/authentication/AuthenticationApi.h>
27 
28 namespace olp {
29 namespace authentication {
30 
47 class 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  inline const std::string& GetServiceId() const { return service_id_; }
87 
95  inline AuthorizeRequest& WithServiceId(std::string service_id) {
96  service_id_ = std::move(service_id);
97  return *this;
98  }
99 
112  inline const boost::optional<std::string>& GetContractId() const {
113  return contract_id_;
114  }
115 
126  boost::optional<std::string> contract_id) {
127  contract_id_ = std::move(contract_id);
128  return *this;
129  }
130 
140  inline 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  inline AuthorizeRequest& WithAction(std::string action,
163  std::string resource = "") {
164  actions_.emplace_back(std::move(action), std::move(resource));
165  return *this;
166  }
167 
177  inline DecisionOperatorType GetOperatorType() const { return operator_type_; }
178 
189  DecisionOperatorType operator_type) {
190  operator_type_ = operator_type;
191  return *this;
192  }
193 
199  inline bool GetDiagnostics() const { return diagnostics_; }
200 
209  inline AuthorizeRequest& WithDiagnostics(bool diagnostics) {
210  diagnostics_ = diagnostics;
211  return *this;
212  }
213 
219  std::string CreateKey() const;
220 
221  private:
222  std::string service_id_;
223  boost::optional<std::string> contract_id_;
224  Actions actions_;
225  DecisionOperatorType operator_type_{DecisionOperatorType::kAnd};
226  bool diagnostics_{false};
227 };
228 
229 } // namespace authentication
230 } // namespace olp
Encapsulates the fields required to make a policy decision for a given request context against the HE...
Definition: AuthorizeRequest.h:47
std::vector< Action > Actions
An alias for the vector of actions.
Definition: AuthorizeRequest.h:63
const Actions & GetActions() const
Gets all actions.
Definition: AuthorizeRequest.h:150
const boost::optional< std::string > & GetContractId() const
Gets the contract ID.
Definition: AuthorizeRequest.h:112
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
AuthorizeRequest & WithContractId(boost::optional< std::string > contract_id)
Sets the contract ID.
Definition: AuthorizeRequest.h:125
AuthorizeRequest & WithOperatorType(DecisionOperatorType operator_type)
Sets the operator type for the request.
Definition: AuthorizeRequest.h:188
DecisionOperatorType GetOperatorType() const
Gets the operator type.
Definition: AuthorizeRequest.h:177
AuthorizeRequest & WithContractId(std::string contract_id)
Sets the contract ID.
Definition: AuthorizeRequest.h:140
std::string CreateKey() const
Creates a readable format for the request.
bool GetDiagnostics() const
Gets the diagnostics flag.
Definition: AuthorizeRequest.h:199
AuthorizeRequest & WithServiceId(std::string service_id)
Sets the service ID.
Definition: AuthorizeRequest.h:95
std::pair< std::string, std::string > Action
An alias for the action pair.
Definition: AuthorizeRequest.h:58
AuthorizeRequest & WithDiagnostics(bool diagnostics)
Sets the diagnostics flag for the request.
Definition: AuthorizeRequest.h:209
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