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 <request/RequestContext.h>
30 #include <response/CheckResponse.h>
31 #include <storage/Storage.h>
42 void Logic::execute(RequestContextPtr context, CheckRequestPtr request) {
43 PolicyResult result(PredefinedPolicyType::DENY);
44 if (check(context, request->key(), result)) {
45 context->returnResponse(context, CheckResponse(result));
49 bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key,
50 PolicyResult& result) {
51 result = Cynara::getStorage()->checkPolicy(key);
53 switch (result.policyType()) {
54 case PredefinedPolicyType::ALLOW :
55 LOGD("check of policy key <%s> returned ALLOW", key.toString().c_str());
57 case PredefinedPolicyType::DENY :
58 LOGD("check of policy key <%s> returned DENY", key.toString().c_str());
61 //todo pass question to proper plugin that:
62 // 1) returns false when answer has to be waited for (UI)
63 // 2) returns true if Response is to be generated
64 // In case 1) context should be saved in plugin in order to return answer when ready.
66 //in case no proper plugin is found
67 throw PluginNotFoundException(result);