6cdb51c2e0dfe7dcaf94e0c0c1efb215a5a53c6a
[platform/core/security/cynara.git] / src / common / types / PolicyBucket.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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        PolicyBucket.h
18  * @author      Lukasz Wojciechowski <l.wojciechowski@partner.samsung.com>
19  * @author      Aleksander Zdyb <a.zdyb@partner.samsung.com>
20  * @version     1.0
21  * @brief       This file defines PolicyBucket type - a policy aggregation
22                 entity name
23  */
24
25 #ifndef CYNARA_COMMON_TYPES_POLICYBUCKET_H
26 #define CYNARA_COMMON_TYPES_POLICYBUCKET_H
27
28 #include "PolicyCollection.h"
29 #include "PolicyKey.h"
30 #include "Policy.h"
31 #include "exceptions/NotImplementedException.h"
32 #include "types/pointers.h"
33 #include "types/PolicyType.h"
34 #include "PolicyBucketId.h"
35
36 #include <string>
37 #include <memory>
38 #include <algorithm>
39
40 namespace Cynara {
41
42 // TODO: Move this const somewhere else
43 const PolicyBucketId defaultPolicyBucketId("");
44
45 class PolicyBucket {
46 public:
47
48     PolicyBucket() : m_defaultPolicy(PolicyResult(PolicyType::DENY)) {}
49     PolicyBucket(const PolicyCollection &policies)
50         : m_policyCollection(policies),
51           m_defaultPolicy(PolicyResult(PolicyType::DENY)) {}
52
53     PolicyBucket filtered(const PolicyKey &key) const;
54
55 private:
56     PolicyCollection m_policyCollection;
57     PolicyResult m_defaultPolicy;
58     PolicyBucketId m_id;
59
60 public:
61     const PolicyResult &defaultPolicy() const {
62         return m_defaultPolicy;
63     }
64
65     const PolicyBucketId &id() const {
66         return m_id;
67     }
68
69     PolicyCollection &policyCollection() {
70         return m_policyCollection;
71     }
72
73     const PolicyCollection &policyCollection() const {
74         return m_policyCollection;
75     }
76
77     void setDefaultPolicy(const PolicyResult &defaultPolicy) {
78         m_defaultPolicy = defaultPolicy;
79     }
80 };
81
82 } /* namespace Cynara */
83 #endif /* CYNARA_COMMON_TYPES_POLICYBUCKET_H */