2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
21 * @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
22 * @brief Implementation of a class for checking permissions of proxy calls
28 #include "proxy-call-policy.hpp"
34 const std::string ANY = "*";
36 inline bool match(const std::string& rule, const std::string& value) {
37 // simple matching, change to regex if it turns out to be insufficient
38 return rule == ANY || rule == value;
44 ProxyCallPolicy::ProxyCallPolicy(const std::vector<ProxyCallRule>& proxyCallRules)
45 : mProxyCallRules(proxyCallRules)
49 bool ProxyCallPolicy::isProxyCallAllowed(const std::string& caller,
50 const std::string& target,
51 const std::string& targetBusName,
52 const std::string& targetObjectPath,
53 const std::string& targetInterface,
54 const std::string& targetMethod) const
56 for (const ProxyCallRule& rule : mProxyCallRules) {
57 if (match(rule.caller, caller)
58 && match(rule.target, target)
59 && match(rule.targetBusName, targetBusName)
60 && match(rule.targetObjectPath, targetObjectPath)
61 && match(rule.targetInterface, targetInterface)
62 && match(rule.targetMethod, targetMethod)) {