24 using namespace boost::filesystem;
37 if (r.parse(jsonInput,
m_root,
false))
48 boost::mutex::scoped_lock lock(
m_mutex);
55 if (val == Value::null || val.asString() ==
"null") {
57 }
else return val.asString();
64 std::set<std::string> grp;
66 boost::mutex::scoped_lock lock(
m_mutex);
73 if (groups != Value::null) {
74 for (
int i = 0; i < groups.size(); ++i) {
75 grp.insert(groups[i].asString());
84 std::set<string> nodeGroups =
getGroups();
86 boost::mutex::scoped_lock lock(
m_mutex);
93 string admgrp = props->
get(
"global",
"admin_group",
"");
95 if (gids.count(admgrp) > 0 ) {
96 LOG(
DEBUG) <<
"WsNodeProperties::isAllowed() : User is Admin. Access allowed for " <<
getPath();
99 std::set<string>::iterator itGids;
102 for (itGids = gids.begin(); itGids != gids.end(); ++itGids) {
103 if (nodeGroups.count(*itGids) > 0) {
106 string edtgrp = props->
get(
"global",
"editor_group",
"");
107 if (gids.count(edtgrp) > 0 ) {
108 LOG(
DEBUG) <<
"WsNodeProperties::isAllowed() User is Editor. Access allowed for " <<
getPath();
111 LOG(
DEBUG) <<
"WsNodeProperties::isAllowed() : User not editor";
113 time_t pnode = boost::lexical_cast<time_t>(this->
get(
"global",
"publish_date",
"0"));
114 time_t pnow = time(NULL);
118 LOG(
DEBUG) <<
"WsNodeProperties::isAllowed() : File is not published yet. Access Denied for " <<
getPath();
121 }
catch (boost::bad_lexical_cast&) {
122 LOG(
ERROR) <<
"WsNodeProperties::isAllowed() : Cannot parse publish date for " << this->
getPath();
128 LOG(
DEBUG) <<
"WsNodeProperties :: User has no access ";
136 boost::mutex::scoped_lock lock(
m_mutex);
155 boost::mutex::scoped_lock lock(
m_mutex);
157 if (r.parse(jsonInput,
m_root,
false))
166 if (key.size() == 0 || value.size() == 0)
169 boost::mutex::scoped_lock lock(
m_mutex);
175 m_root[section][key] = value;
182 boost::mutex::scoped_lock lock(
m_mutex);
188 m_root[
"global"][
"groups"].clear();
189 std::set<string>::iterator it;
191 for (it = grps.begin(), i = 0; it != grps.end(); ++it, ++i) {
192 m_root[
"global"][
"groups"][i] = *it;
200 boost::mutex::scoped_lock try_lock(
m_mutex);
210 }
catch (exception& e) {
211 LOG(
ERROR) <<
"WsNodeProperties::createPropertiesDirectories() : " << e.what();
219 boost::mutex::scoped_lock lock(
m_mutex);
222 conf.open(p.c_str(), ios::out | ios::trunc | ios::binary);
223 if (conf.is_open()) {
224 conf <<
m_root.toStyledString();
std::string getPath()
Get path of the node which the configuration belongs to.
const std::string SubFolders[NbItems]
boost::filesystem::path m_nodePath
int createPropertiesDirectories()
Creates the directories for the properties.
std::set< std::string > getGroups()
Returns the groups that have access to the node If no groups are found in the file, an empty set is returned.
int save()
save the properties to the disk The path of the file is set in m_nodePath and is set when building th...
int parse(const std::string &path)
parse the Json config file
const std::string PathToNodeProperties
void setRoot(Json::Value root)
set the root of the Json tree
Json::Value getRoot()
Return the root of the Json tree.
Abstract Properties class.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
WsNodeProperties(boost::filesystem::path nodePath, Type t)
Constructor.
static WsGlobalProperties * instance()
const std::string PathToDirProperties
void set(const std::string §ion, const std::string &key, const std::string &value)
Changes or sets the propety with key 'key' to value 'value' If the property already exist...
bool isAllowed(std::set< std::string > gids)
Compare the gids with the node groups. If the user has access, true is returned, otherwise false is r...
const std::string ConfExt
void setGroups(std::set< std::string > grps)
Sets the groups of the node to grps. All groups will be overriden. This method does not however...
std::string get(const std::string §ion, const std::string &id, const std::string &def)