From: Zofia Abramowska Date: Tue, 16 Dec 2014 15:48:58 +0000 (+0100) Subject: Add listing types of policies X-Git-Tag: accepted/tizen/common/20150119.084431~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=582e79ea7c430629a9ee5fa432839956174c736d;p=platform%2Fcore%2Fsecurity%2Fcynara.git Add listing types of policies Change-Id: Iab51f7ec232fb711ac6945be1ce71effa7e59ef1 --- diff --git a/src/client-async/logic/Logic.cpp b/src/client-async/logic/Logic.cpp index 48b8bad..7504c7e 100644 --- a/src/client-async/logic/Logic.cpp +++ b/src/client-async/logic/Logic.cpp @@ -50,8 +50,8 @@ Logic::Logic(cynara_status_callback callback, void *userStatusData) m_cache = std::make_shared(); auto naiveInterpreter = std::make_shared(); - for (auto &type : naiveInterpreter->getSupportedPolicyTypes()) { - m_cache->registerPlugin(type, naiveInterpreter); + for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) { + m_cache->registerPlugin(descr, naiveInterpreter); } } diff --git a/src/client-common/CMakeLists.txt b/src/client-common/CMakeLists.txt index bb02eca..2c60ca9 100644 --- a/src/client-common/CMakeLists.txt +++ b/src/client-common/CMakeLists.txt @@ -28,7 +28,6 @@ INCLUDE_DIRECTORIES( SET(LIB_CYNARA_COMMON_SOURCES ${LIB_CYNARA_COMMON_PATH}/cache/CapacityCache.cpp - ${LIB_CYNARA_COMMON_PATH}/plugins/NaiveInterpreter.cpp ) ADD_DEFINITIONS("-fvisibility=default") diff --git a/src/client-common/cache/CacheInterface.h b/src/client-common/cache/CacheInterface.h index 03b7624..bbd18c8 100644 --- a/src/client-common/cache/CacheInterface.h +++ b/src/client-common/cache/CacheInterface.h @@ -31,9 +31,9 @@ #include #include #include +#include #include #include -#include namespace Cynara { @@ -48,8 +48,8 @@ public: const PolicyKey &key, const PolicyResult &result) = 0; - void registerPlugin(const PolicyType policyType, ClientPluginInterfacePtr plugin) { - m_plugins[policyType] = plugin; + void registerPlugin(const PolicyDescription &policyDescr, ClientPluginInterfacePtr plugin) { + m_plugins[policyDescr] = plugin; } virtual void clear(void) { @@ -59,7 +59,7 @@ public: virtual ~PluginCache() {}; protected: - std::map m_plugins; + std::map m_plugins; }; } // namespace Cynara diff --git a/src/client-common/plugins/NaiveInterpreter.cpp b/src/client-common/plugins/NaiveInterpreter.cpp deleted file mode 100644 index 7141cb7..0000000 --- a/src/client-common/plugins/NaiveInterpreter.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ -/** - * @file src/client-common/plugins/NaiveInterpreter.cpp - * @author Zofia Abramowska - * @version 1.0 - * @brief This file contains NaiveInterpreter supported types definition. - */ - -#include - -namespace Cynara { - - const std::vector NaiveInterpreter::s_supportedTypes = - {PredefinedPolicyType::ALLOW, PredefinedPolicyType::DENY}; - -} diff --git a/src/client-common/plugins/NaiveInterpreter.h b/src/client-common/plugins/NaiveInterpreter.h index 059554d..a0e2d67 100644 --- a/src/client-common/plugins/NaiveInterpreter.h +++ b/src/client-common/plugins/NaiveInterpreter.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace Cynara { @@ -45,13 +46,11 @@ public: return CYNARA_API_ACCESS_DENIED; } - const std::vector &getSupportedPolicyTypes(void) { - return s_supportedTypes; + const std::vector &getSupportedPolicyDescr(void) { + return predefinedPolicyDescr; } void invalidate(void) {} -private: - static const std::vector s_supportedTypes; }; } // namespace Cynara diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index 498e53c..f8fc543 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -52,8 +52,8 @@ Logic::Logic() { std::make_shared()); m_cache = std::make_shared(); auto naiveInterpreter = std::make_shared(); - for (auto &type : naiveInterpreter->getSupportedPolicyTypes()) { - m_cache->registerPlugin(type, naiveInterpreter); + for (auto &descr : naiveInterpreter->getSupportedPolicyDescr()) { + m_cache->registerPlugin(descr, naiveInterpreter); } } diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 37073ad..fe2f727 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -62,9 +62,11 @@ SET(COMMON_SOURCES ${COMMON_PATH}/sockets/Socket.cpp ${COMMON_PATH}/sockets/SocketClient.cpp ${COMMON_PATH}/types/PolicyBucket.cpp + ${COMMON_PATH}/types/PolicyDescription.cpp ${COMMON_PATH}/types/PolicyKey.cpp ${COMMON_PATH}/types/PolicyKeyHelpers.cpp ${COMMON_PATH}/types/PolicyResult.cpp + ${COMMON_PATH}/types/PolicyType.cpp ) IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") diff --git a/src/common/plugin/ExternalPluginInterface.h b/src/common/plugin/ExternalPluginInterface.h index ddd8363..f4e8a63 100644 --- a/src/common/plugin/ExternalPluginInterface.h +++ b/src/common/plugin/ExternalPluginInterface.h @@ -25,7 +25,7 @@ #include -#include +#include namespace Cynara { @@ -47,11 +47,10 @@ typedef void (*destroy_t)(ExternalPluginInterface *); class ExternalPluginInterface { public: - /** - * Policy type supported by plugin. + * Policy types supported by plugin. */ - virtual const std::vector &getSupportedPolicyTypes(void) = 0; + virtual const std::vector &getSupportedPolicyDescr(void) = 0; /** * Informs, that every data stored based on previously given input diff --git a/src/common/plugin/PluginManager.cpp b/src/common/plugin/PluginManager.cpp index c8a38c5..300dc7f 100644 --- a/src/common/plugin/PluginManager.cpp +++ b/src/common/plugin/PluginManager.cpp @@ -65,6 +65,15 @@ ExternalPluginPtr PluginManager::getPlugin(PolicyType pType) { return m_plugins[pType]; } +std::vector PluginManager::getPolicyDescriptions(void) const { + std::vector descriptions; + descriptions.reserve(m_plugins.size()); + for (auto &plugin : m_plugins) { + descriptions.push_back(plugin.first); + } + return descriptions; +} + void PluginManager::invalidateAll(void) { for (auto &plugin : m_plugins) { plugin.second->invalidate(); @@ -125,14 +134,15 @@ void PluginManager::openPlugin(const std::string &path) { return; } - auto policies = pluginPtr->getSupportedPolicyTypes(); + auto policies = pluginPtr->getSupportedPolicyDescr(); if (policies.empty()) { LOGE("Plugin <%s> does not support any type!", path.c_str()); return; } - for (auto type : policies) { - if (!m_plugins.insert(std::make_pair(type, pluginPtr)).second) { - LOGW("policyType [%" PRIu16 "] was already supported.", type); + for (auto &desc : policies) { + if (!m_plugins.insert(std::make_pair(desc, pluginPtr)).second) { + LOGW("policy type: [%" PRIu16 "] name: <%s> was already supported.", + desc.type, desc.name.c_str()); } } diff --git a/src/common/plugin/PluginManager.h b/src/common/plugin/PluginManager.h index 8de33ae..87b0597 100644 --- a/src/common/plugin/PluginManager.h +++ b/src/common/plugin/PluginManager.h @@ -28,8 +28,10 @@ #include #include #include +#include #include +#include namespace Cynara { typedef std::shared_ptr ExternalPluginPtr; @@ -38,6 +40,7 @@ class PluginManager { public: PluginManager(const std::string &pluginDir); ExternalPluginPtr getPlugin(PolicyType pType); + std::vector getPolicyDescriptions(void) const; void invalidateAll(void); ~PluginManager(); @@ -46,7 +49,7 @@ private: typedef std::list PluginLibs; std::string m_dir; - std::map m_plugins; + std::map m_plugins; PluginLibs m_pluginLibs; void loadPlugins(void); diff --git a/src/common/types/PolicyDescription.cpp b/src/common/types/PolicyDescription.cpp new file mode 100644 index 0000000..1c06137 --- /dev/null +++ b/src/common/types/PolicyDescription.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file src/common/types/PolicyDescription.cpp + * @author Zofia Abramowska + * @version 1.0 + * @brief Implementation of functions for Cynara::PolicyDescription + */ + +#include "PolicyDescription.h" + +namespace Cynara { + +const std::vector predefinedPolicyDescr = { + PolicyDescription(PredefinedPolicyType::ALLOW, "Allow"), + PolicyDescription(PredefinedPolicyType::DENY, "Deny") +}; + +bool operator<(const PolicyDescription &left, const PolicyDescription &right) { + return left.type < right.type; +} + +} // namespace Cynara diff --git a/src/common/types/PolicyDescription.h b/src/common/types/PolicyDescription.h new file mode 100644 index 0000000..b4d27d5 --- /dev/null +++ b/src/common/types/PolicyDescription.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file src/common/types/PolicyDescription.h + * @author Zofia Abramowska + * @version 1.0 + * @brief This file defines PolicyDescription for storing policy type + * description. + */ + +#ifndef SRC_COMMON_TYPES_POLICYDESCRIPTION_H_ +#define SRC_COMMON_TYPES_POLICYDESCRIPTION_H_ + +#include + +#include +#include + +namespace Cynara { + +struct PolicyDescription { + PolicyDescription(const PolicyType &pType, const std::string &pName) : type(pType), name(pName) + {}; + PolicyDescription(const PolicyType &pType) : type(pType) {}; + PolicyType type; + std::string name; +}; + +extern const std::vector predefinedPolicyDescr; + +bool operator<(const PolicyDescription &left, const PolicyDescription &right); + +} // namespace Cynara + +#endif /* SRC_COMMON_TYPES_POLICYDESCRIPTION_H_ */ diff --git a/src/include/cynara-client-plugin.h b/src/include/cynara-client-plugin.h index 3d39ad7..29e32ce 100644 --- a/src/include/cynara-client-plugin.h +++ b/src/include/cynara-client-plugin.h @@ -51,13 +51,12 @@ typedef std::shared_ptr ClientPluginInterfacePtr; */ class ClientPluginInterface : public ExternalPluginInterface { public: - /** * Return entry cacheability */ virtual bool isCacheable(const ClientSession &session, const PolicyResult &result) = 0; /** - * Return entry cacheability + * Return entry usability */ virtual bool isUsable(const ClientSession &session, const ClientSession &prevSession, bool &updateSession, PolicyResult &result) = 0;