2 * security-manager, database access
4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Rafal Krypa <r.krypa@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * @file privilege_db.h
24 * @author Krzysztof Sasiak <k.sasiak@samsung.com>
25 * @author Rafal Krypa <r.krypa@samsung.com>
27 * @brief This file contains declaration of the API to privilges database.
36 #include <dpl/db/sql_connection.h>
38 #ifndef PRIVILEGE_DB_H_
39 #define PRIVILEGE_DB_H_
41 namespace SecurityManager {
43 enum class QueryType {
54 * PrivilegeDb database class
58 SecurityManager::DB::SqlConnection *mSqlConnection;
59 const std::map<QueryType, const char * const > Queries = {
60 { QueryType::EGetPkgPrivileges, "SELECT privilege_name FROM app_privilege_view WHERE pkg_name=?"},
61 { QueryType::EAddApplication, "INSERT INTO app_pkg_view (app_name, pkg_name) VALUES (?, ?)" },
62 { QueryType::ERemoveApplication, "DELETE FROM app_pkg_view WHERE app_name=? AND pkg_name=?" },
63 { QueryType::EAddAppPrivileges, "INSERT INTO app_privilege_view (app_name, privilege_name) VALUES (?, ?)" },
64 { QueryType::ERemoveAppPrivileges, "DELETE FROM app_privilege_view WHERE app_name=?" },
65 { QueryType::EPkgIdExists, "SELECT * FROM pkg WHERE name=?" }
69 * Check if pkgId is already registered in database
71 * @param pkgId - package identifier
72 * @exception DB::SqlConnection::Exception::InternalError on internal error
73 * @return true if pkgId exists in the database
76 bool PkgIdExists(const std::string &pkgId);
82 DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
83 DECLARE_EXCEPTION_TYPE(Base, IOError)
84 DECLARE_EXCEPTION_TYPE(Base, InternalError)
89 * @exception DB::SqlConnection::Exception::IOError on problems with database access
92 PrivilegeDb(const std::string &path);
97 * @exception DB::SqlConnection::Exception::InternalError on internal error
100 void BeginTransaction(void);
104 * @exception DB::SqlConnection::Exception::InternalError on internal error
107 void CommitTransaction(void);
110 * Rollback transaction
111 * @exception DB::SqlConnection::Exception::InternalError on internal error
114 void RollbackTransaction(void);
117 * Retrieve list of privileges assigned to a pkgId
119 * @param pkgId - package identifier
120 * @param[out] currentPrivileges - list of current privileges assigned to pkgId
121 * @exception DB::SqlConnection::Exception::InternalError on internal error
123 void GetPkgPrivileges(const std::string &pkgId,
124 std::vector<std::string> ¤tPrivilege);
127 * Add an application into the database
129 * @param appId - application identifier
130 * @param pkgId - package identifier
131 * @param[out] pkgIdIsNew - return info if pkgId is new to the database
132 * @exception DB::SqlConnection::Exception::InternalError on internal error
134 void AddApplication(const std::string &appId, const std::string &pkgId,
138 * Remove an application from the database
140 * @param appId - application identifier
141 * @param pkgId - package identifier
142 * @param[out] pkgIdIsNoMore - return info if pkgId is in the database
143 * @exception DB::SqlConnection::Exception::InternalError on internal error
145 void RemoveApplication(const std::string &appId, const std::string &pkgId,
146 bool &pkgIdIsNoMore);
149 * Remove privileges assigned to application
151 * @param appId - application identifier
152 * @exception DB::SqlConnection::Exception::InternalError on internal error
154 void RemoveAppPrivileges(const std::string &appId);
157 * Update privileges assigned to application
158 * To assure data integrity this method must be called inside db transaction.
160 * @param appId - application identifier
161 * @param privileges - list of privileges to assign
162 * @exception DB::SqlConnection::Exception::InternalError on internal error
164 void UpdateAppPrivileges(const std::string &appId,
165 const std::vector<std::string> &privileges);
169 } //namespace SecurityManager
171 #endif // PRIVILEGE_DB_H_