SET(LIB_CYNARA_SOURCES
${CYNARA_LIB_CYNARA_PATH}/api/client-api.cpp
+ ${CYNARA_LIB_CYNARA_PATH}/cache/NoCache.cpp
${CYNARA_LIB_CYNARA_PATH}/logic/Logic.cpp
)
--- /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 CacheInterface.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains cache interface definition.
+ */
+
+#ifndef SRC_CLIENT_CACHE_CACHEINTERFACE_H_
+#define SRC_CLIENT_CACHE_CACHEINTERFACE_H_
+
+#include <memory>
+#include <string>
+
+#include <types/PolicyKey.h>
+#include <types/PolicyResult.h>
+
+#include <cynara-client.h>
+
+namespace Cynara {
+
+class CacheInterface;
+typedef std::shared_ptr<CacheInterface> CacheInterfacePtr;
+
+class CacheInterface {
+public:
+ CacheInterface() = default;
+ virtual ~CacheInterface() = default;
+
+ virtual cynara_api_result check(const std::string &session, const PolicyKey &key) = 0;
+ virtual cynara_api_result updateAndCheck(const std::string &session, const PolicyKey &key,
+ const PolicyResult &result) = 0;
+ virtual void clear(void) = 0;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_CLIENT_CACHE_CACHEINTERFACE_H_ */
--- /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 NoCache.cpp
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains implementation of NoCache class - stub for no-cache version
+ */
+
+#include <common.h>
+#include <types/PolicyType.h>
+
+#include "NoCache.h"
+
+namespace Cynara {
+
+cynara_api_result NoCache::updateAndCheck(const std::string &session UNUSED,
+ const PolicyKey &key UNUSED,
+ const PolicyResult &result) {
+ if (result.policyType() == PredefinedPolicyType::ALLOW)
+ return cynara_api_result::CYNARA_API_SUCCESS;
+ else
+ return cynara_api_result::CYNARA_API_ACCESS_DENIED;
+}
+
+} // namespace Cynara
--- /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 NoCache.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains definition of NoCache class - stub for no-cache version
+ */
+
+#ifndef SRC_CLIENT_CACHE_NOCACHE_H_
+#define SRC_CLIENT_CACHE_NOCACHE_H_
+
+#include <string.h>
+
+#include <common.h>
+#include <types/PolicyKey.h>
+#include <types/PolicyResult.h>
+
+#include <cache/CacheInterface.h>
+#include <cynara-client.h>
+
+namespace Cynara {
+
+class NoCache : public CacheInterface {
+public:
+ NoCache() = default;
+ virtual ~NoCache() = default;
+
+ virtual cynara_api_result check(const std::string &session UNUSED,
+ const PolicyKey &key UNUSED) {
+ return cynara_api_result::CYNARA_API_SERVICE_NOT_AVAILABLE;
+ }
+
+ virtual cynara_api_result updateAndCheck(const std::string &session, const PolicyKey &key,
+ const PolicyResult &result);
+
+ virtual void clear(void) {
+ }
+};
+
+} // namespace Cynara
+
+#endif /* SRC_CLIENT_CACHE_NOCACHE_H_ */
#include <types/PolicyKey.h>
#include <types/PolicyResult.h>
+#include <cache/NoCache.h>
#include "Logic.h"
namespace Cynara {
Logic::Logic() {
m_socketClient = std::make_shared<SocketClient>(clientSocketPath,
std::make_shared<ProtocolClient>());
+ m_cache = std::make_shared<NoCache>();
}
ProtocolFrameSequenceNumber generateSequenceNumber(void) {
{
PolicyKey key(client, user, privilege);
- //todo Check if answer can be get from cache. Update cache.
- //todo m_cache->check(session, key);
+ auto cacheResponse = m_cache->check(session, key);
+ if(cacheResponse != cynara_api_result::CYNARA_API_SERVICE_NOT_AVAILABLE)
+ return cacheResponse;
ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber();
return cynara_api_result::CYNARA_API_ACCESS_DENIED;
}
- PolicyResult result = checkResponse->m_resultRef;
- //todo Interprete result.
- //todo Update cache.
-
- //todo return result after more detailed interpretation.
- if (result.policyType() == PredefinedPolicyType::ALLOW)
- return cynara_api_result::CYNARA_API_SUCCESS;
- else
- return cynara_api_result::CYNARA_API_ACCESS_DENIED;
+ return m_cache->updateAndCheck(session, key, checkResponse->m_resultRef);
}
void Logic::onDisconnected(void) {
- //todo run special actions when disconnected from cynara service
- // like cleaning cache
+ m_cache->clear();
}
} // namespace Cynara
#include <sockets/SocketClient.h>
#include <api/ApiInterface.h>
+#include <cache/CacheInterface.h>
namespace Cynara {
class Logic : public ApiInterface {
private:
SocketClientPtr m_socketClient;
+ CacheInterfacePtr m_cache;
void onDisconnected(void);