This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccessStrategy.h
142 lines (112 loc) · 5.06 KB
/
AccessStrategy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (c) 2019 Riccardo Zaccone, Ksenia Del Conte Akimova, Alice Morano, Martina Bellissimo
*
* This file is part of Symposium.
* Symposium is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Symposium is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Symposium. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File: AccessStrategy.h
* Project: Symposium
* Authors:
* Riccardo Zaccone <riccardo.zaccone at studenti.polito.it>
* Ksenia Del Conte Akimova <s256669 at studenti.polito.it>
* Alice Morano <s259158 at studenti.polito.it>
* Martina Bellissimo <s257307 at studenti.polito.it>
*
* Created on 05 Luglio 2019, 16.22
*/
#ifndef SYMPOSIUM_ACCESSSTRATEGY_H
#define SYMPOSIUM_ACCESSSTRATEGY_H
#include "privilege.h"
#include <unordered_map>
#include "Symposium.h"
#include <string>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include "boost/serialization/unordered_map.hpp"
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/export.hpp>
namespace Symposium {
/**
* @brief Defines how the permissions on objects of type @link filesystem are handled
*/
class AccessStrategy {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &, const unsigned int){}
public:
/**
* @brief validate an action from user @ref targetUser that requires @ref requested
* @param targetUser the user who is doing the action
* @param requested the permission requested by the action
* @return true if the user is granted the privilege @ref requested
*/
virtual bool validateAction(const std::string &targetUser, privilege requested)const =0 ;
/**
* @brief set the privilege of an user
* @param targetUser the user the privilege is to be granted
* @param toGrant the privilege to grant to @ref targetUser
* @return the privilege previously owned by @ref targetUser, none if no privilege previously owned
*/
virtual privilege setPrivilege(const std::string &targetUser, privilege toGrant) =0;
virtual privilege getPrivilege(const std::string &targetUser) const =0;
virtual std::unordered_map<std::string, privilege> getPermission() const =0;
virtual bool moreOwner(std::string username) const =0;
virtual ~AccessStrategy()= default;
};
BOOST_SERIALIZATION_ASSUME_ABSTRACT(AccessStrategy)
/**
* @brief class used to model a ReadModifyOwn privilege handling on a resource.
*/
class RMOAccess : public AccessStrategy {
std::unordered_map<std::string, privilege> permission; /**< username and related privilege for the resource */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::AccessStrategy>(*this);
ar & permission;
}
public:
bool validateAction(const std::string &targetUser, privilege requested) const override;
privilege setPrivilege(const std::string &targetUser, privilege toGrant) override;
privilege getPrivilege(const std::string &targetUser) const override;
std::unordered_map<std::string, privilege> getPermission() const override;
bool moreOwner(std::string username) const override;
bool operator==(const RMOAccess &rhs) const;
bool operator!=(const RMOAccess &rhs) const;
~RMOAccess() override = default;
};
/**
* @brief class used to model the absence of privilege handling on a resource
*/
class TrivialAccess : public AccessStrategy {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int)
{
// save/load base class information
ar & boost::serialization::base_object<Symposium::AccessStrategy>(*this);
}
public:
bool validateAction(const std::string &targetUser, privilege requested) const override;
privilege setPrivilege(const std::string &targetUser, privilege toGrant) override;
privilege getPrivilege(const std::string &targetUser) const override;
std::unordered_map<std::string, privilege> getPermission() const override;
bool moreOwner(std::string username) const override;
~TrivialAccess() override = default;
};
}
#endif //SYMPOSIUM_ACCESSSTRATEGY_H