2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
20 * @brief This file implements main class of logic layer in cynara service
25 #include <exceptions/PluginNotFoundException.h>
27 #include <main/Cynara.h>
28 #include <request/CheckRequest.h>
29 #include <response/CheckResponse.h>
30 #include <storage/Storage.h>
41 void Logic::execute(const RequestContext &context, CheckRequestPtr request) {
42 PolicyResult result(PredefinedPolicyType::DENY);
43 if (check(context, request->key(), result)) {
44 context.returnResponse(CheckResponse(result));
48 bool Logic::check(const RequestContext &context UNUSED, const PolicyKey &key,
49 PolicyResult& result) {
50 result = Cynara::getStorage()->checkPolicy(key);
52 switch (result.policyType()) {
53 case PredefinedPolicyType::ALLOW :
54 LOGD("check of policy key <%s> returned ALLOW", key.toString().c_str());
56 case PredefinedPolicyType::DENY :
57 LOGD("check of policy key <%s> returned DENY", key.toString().c_str());
60 //todo pass question to proper plugin that:
61 // 1) returns false when answer has to be waited for (UI)
62 // 2) returns true if Response is to be generated
63 // In case 1) context should be saved in plugin in order to return answer when ready.
65 //in case no proper plugin is found
66 throw PluginNotFoundException(result);