--- /dev/null
+/*
+ * 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 PluginNotFoundException.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief Implementation of PluginNotFoundException
+ */
+
+#ifndef SRC_COMMON_EXCEPTIONS_PLUGINNOTFOUNDEXCEPTION_H_
+#define SRC_COMMON_EXCEPTIONS_PLUGINNOTFOUNDEXCEPTION_H_
+
+#include <exception>
+#include <sstream>
+
+#include <types/PolicyResult.h>
+#include "Exception.h"
+
+namespace Cynara {
+
+class PluginNotFoundException : public Exception {
+private:
+ std::string m_whatMessage;
+
+public:
+ PluginNotFoundException() = delete;
+ PluginNotFoundException(const PolicyResult &result) {
+ std::ostringstream stream;
+ stream << "No proper plugin found to interprete PolicyResult {type = ["
+ << result.policyType() << "], metadata = <"
+ << result.metadata().substr(0, 20) << ">}";
+ m_whatMessage = stream.str();
+ }
+
+ virtual ~PluginNotFoundException() = default;
+
+ virtual const char *what(void) const noexcept {
+ return m_whatMessage.c_str();
+ }
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_EXCEPTIONS_PLUGINNOTFOUNDEXCEPTION_H_ */
* @brief This file implements main class of logic layer in cynara service
*/
+#include <log/log.h>
#include <common.h>
+#include <exceptions/PluginNotFoundException.h>
+
+#include <main/Cynara.h>
+#include <storage/Storage.h>
#include "Logic.h"
Logic::~Logic() {
}
-PolicyResult Logic::check(const RequestContext &context UNUSED, const PolicyKey &key UNUSED) {
-//todo this is only a stub
- return PolicyResult(PredefinedPolicyType::ALLOW);
+PolicyResult Logic::check(const RequestContext &context UNUSED, const PolicyKey &key) {
+ PolicyResult result = Cynara::getStorage()->checkPolicy(key);
+
+ switch (result.policyType()) {
+ case PredefinedPolicyType::ALLOW :
+ LOGD("check of policy key <%s> returned ALLOW", key.toString().c_str());
+ return result;
+ case PredefinedPolicyType::DENY :
+ LOGD("check of policy key <%s> returned DENY", key.toString().c_str());
+ return result;
+ }
+ //todo pass question to proper plugin that:
+ // 1) might throw NoResponseGeneratedException when answer has to be waited for (UI)
+ // 2) might return PolicyResult
+ // In case 1) context should be saved in plugin in order to return answer when ready.
+
+ //in case no proper plugin is found
+ throw PluginNotFoundException(result);
}
} // namespace Cynara