Add caching of App/Pkg data & use faster way to retrieve this data
[platform/core/security/askuser.git] / src / common / policy / Policy.h
1 /*
2  *  Copyright (c) 2016-2018 Samsung Electronics Co.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 /**
17  * @file        src/agent/main/Policy.h
18  * @author      Zofia Grzelewska <z.abramowska@samsung.com>
19  * @brief       Definition of Policy wrappers
20  */
21
22 #pragma once
23
24 #include <set>
25 #include <string>
26 #include <vector>
27
28 #include <policy/PkgInfo.h>
29 #include <types/PolicyTypes.h>
30
31 struct policy_entry;
32 struct policy_update_req;
33
34 namespace AskUser {
35
36 class PolicyEntryCopy;
37
38 std::string getOwnAppId(PkgInfo &pkgInfo);
39 void identifyApp(PkgInfo &pkgInfo, const std::string &client, std::string &appId, std::string &pkgLabel);
40
41 std::set<Privilege> getManifestPrivs(const std::string &appId);
42
43 Policy getPrivilegePolicy(const std::string &appId, const Privilege &corePrivilege);
44
45 std::vector<PolicyEntryCopy> getAppPolicy(const std::string &appId);
46
47 class PolicyEntry {
48 public:
49     PolicyEntry();
50     PolicyEntry(PolicyEntry &&other);
51     PolicyEntry(policy_entry *entry) { m_entry = entry; }
52     ~PolicyEntry();
53     void setApp(const std::string &appId);
54     std::string getAppId();
55     void setUser(const std::string &user);
56     std::string getUser();
57     void setPrivilege(const std::string &privilege);
58     std::string getPrivilege();
59     void setLevel(const std::string &level);
60     std::string getLevel();
61
62     policy_entry *get() const { return m_entry; }
63
64 private:
65     policy_entry *m_entry;
66 };
67
68 class PolicyEntryCopy {
69 public:
70     PolicyEntryCopy() = default;
71     PolicyEntryCopy(PolicyEntryCopy &&other) = default;
72     PolicyEntryCopy(policy_entry *entry);
73     ~PolicyEntryCopy() = default;
74     std::string getAppId() { return m_appId; }
75     std::string getUser() { return m_user; }
76     std::string getPrivilege() { return m_privilege; }
77     std::string getLevel() { return m_level; }
78
79 private:
80     std::string m_appId;
81     std::string m_user;
82     std::string m_privilege;
83     std::string m_level;
84 };
85
86 class PolicyRequest {
87 public:
88     PolicyRequest();
89     ~PolicyRequest();
90     void addEntry(PolicyEntry &&entry);
91     void updatePolicy();
92
93 private:
94     policy_update_req *m_req;
95     std::vector<PolicyEntry> m_entries;
96 };
97
98 class PolicyFetchRequest {
99 public:
100     PolicyFetchRequest(PolicyEntry &&filter) : m_filter(std::move(filter)) {}
101     ~PolicyFetchRequest() {}
102     std::vector<PolicyEntryCopy> fetchPolicy();
103 private:
104     PolicyEntry m_filter;
105 };
106
107 } /* namespace AskUser */