2 * Copyright (c) 2011 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.
16 #ifndef _FUNCTION_DECLARATION_
17 #define _FUNCTION_DECLARATION_
20 #include <Commons/WrtAccess/WrtAccess.h>
21 #include <Commons/Exception.h>
22 #include <JavaScriptCore/JavaScript.h>
23 #include <Commons/TypesDeclaration.h>
24 #include <Commons/TypeTraits.h>
25 #include <dpl/log/log.h>
27 namespace WrtDeviceApis {
28 namespace CommonsJavaScript {
29 enum class AceSecurityStatus
37 template <typename ... Args>
38 class DefaultArgsVerifier
41 void operator()(WrtDeviceApis::Commons::AceFunction& aceFunction,
42 Args && ... args) const
45 WrtDeviceApis::Commons::AlwaysFalse<Args ...>::value,
46 "Please provide a specialization for these argument types!");
51 class DefaultArgsVerifier<>
54 void operator()(WrtDeviceApis::Commons::AceFunction& /*aceFunction*/) const
58 template <typename ArgumentsVerifier,
60 AceSecurityStatus aceCheckAccess2(
61 WrtDeviceApis::Commons::AceFunction aceFunction,
64 using namespace WrtDeviceApis::Commons;
66 ArgumentsVerifier argsVerify;
67 argsVerify(aceFunction, args ...);
69 WrtAccess::CheckAccessReturnType ret =
70 WrtAccessSingleton::Instance().checkAccessControl(aceFunction);
72 if (ret == WrtAccess::CHECK_ACCESS_PRIVILEGE_DENIED) {
73 LogError("Function is not allowed to run - AccessDenied");
74 return AceSecurityStatus::AccessDenied;
76 else if (ret == WrtAccess::CHECK_ACCESS_PRIVACY_DENIED) {
77 LogError("Function is not allowed to run - PrivacyDenied");
78 return AceSecurityStatus::PrivacyDenied;
80 else if (ret == WrtAccess::CHECK_ACCESS_INTERNAL_ERROR) {
81 LogError("InternalError");
82 return AceSecurityStatus::InternalError;
85 LogDebug("Function accepted!");
87 return AceSecurityStatus::AccessGranted;
90 //The simplest version
91 AceSecurityStatus aceCheckAccessSimple(
92 WrtDeviceApis::Commons::AceFunction aceFunction);
96 #endif // _FUNCTION_DECLARARION_