Implement SecurityManager::DataProvider 39/43739/1
authorAleksander Zdyb <a.zdyb@samsung.com>
Tue, 23 Jun 2015 09:25:13 +0000 (11:25 +0200)
committerAleksander Zdyb <a.zdyb@samsung.com>
Fri, 10 Jul 2015 12:50:28 +0000 (14:50 +0200)
This class retrieves resource groups from SecurityManager.

Change-Id: Ic1c80d9cb10b5095738773e90d8f957c6d120525

src/SecurityManager/DataProvider.cpp [new file with mode: 0644]
src/SecurityManager/DataProvider.h [new file with mode: 0644]
src/SecurityManager/ErrorException.h [new file with mode: 0644]

diff --git a/src/SecurityManager/DataProvider.cpp b/src/SecurityManager/DataProvider.cpp
new file mode 100644 (file)
index 0000000..d861cec
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 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/SecurityManager/DataProvider.cpp
+ * @author      Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version     1.0
+ */
+
+#include <functional>
+#include <memory>
+
+#include <Log/log.h>
+
+#include <SecurityManager/ErrorException.h>
+
+#include "DataProvider.h"
+
+namespace SecurityManager {
+
+DataProvider::DataProvider(BaseSecurityManagerWrapper &smApi) : m_smApi(smApi) {}
+
+Lad::DataProvider::GroupsList DataProvider::getResourceGroups(void) {
+    Lad::DataProvider::GroupsList retGroups;
+
+    char **groups = nullptr;
+    size_t groupsLen = 0;
+
+    auto getRet = m_smApi.security_manager_groups_get(&groups, &groupsLen);
+
+    if (getRet != m_smApi.SECURITY_MANAGER_SUCCESS_CONST()) {
+        throw ErrorException("Could not get groups from Security Manager");
+    }
+
+    auto groupsDeleter = std::bind(&BaseSecurityManagerWrapper::security_manager_groups_free,
+                                   &m_smApi, std::placeholders::_1, groupsLen);
+    std::unique_ptr<char *, std::function<void(char **)>> groupsPtr(groups, groupsDeleter);
+
+    for (size_t i = 0; i < groupsLen; ++i) {
+        retGroups.push_back(groups[i]);
+    }
+
+    return retGroups;
+}
+
+} /* namespace SecurityManager */
diff --git a/src/SecurityManager/DataProvider.h b/src/SecurityManager/DataProvider.h
new file mode 100644 (file)
index 0000000..8e759c8
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 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/SecurityManager/DataProvider.h
+ * @author      Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version     1.0
+ */
+
+#ifndef SRC_SECURITYMANAGER_DATAPROVIDER_H
+#define SRC_SECURITYMANAGER_DATAPROVIDER_H
+
+#include <list>
+#include <string>
+
+#include <Lad/DataProvider.h>
+#include <SecurityManager/BaseSecurityManagerWrapper.h>
+
+namespace SecurityManager {
+
+class DataProvider : public Lad::DataProvider {
+public:
+    DataProvider(BaseSecurityManagerWrapper &smApi);
+    virtual ~DataProvider() = default;
+
+    Lad::DataProvider::GroupsList getResourceGroups(void);
+
+private:
+    BaseSecurityManagerWrapper &m_smApi;
+};
+
+} /* namespace SecurityManager */
+
+#endif /* SRC_SECURITYMANAGER_DATAPROVIDER_H */
diff --git a/src/SecurityManager/ErrorException.h b/src/SecurityManager/ErrorException.h
new file mode 100644 (file)
index 0000000..89d07b0
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 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/SecurityManager/ErrorException.h
+ * @author      Aleksander Zdyb <a.zdyb@samsung.com>
+ * @version     1.0
+ */
+
+#ifndef SRC_SECURITYMANAGER_ERROREXCEPTION_H
+#define SRC_SECURITYMANAGER_ERROREXCEPTION_H
+
+#include <Utils/WithMessageException.h>
+
+namespace SecurityManager {
+
+class ErrorException : public Utils::WithMessageException {
+public:
+    ErrorException(const std::string &message)
+        : WithMessageException("Security Manager: " + message) {}
+};
+
+} // namespace SecurityManager
+
+
+#endif // SRC_SECURITYMANAGER_ERROREXCEPTION_H