Mercurial > hg > orthanc-authorization
changeset 191:55435a4dd2c6
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 15:23:55 +0200 |
parents | de232f9b3a60 |
children | ccfd44ec3c9b |
files | Plugin/PermissionParser.cpp Plugin/PermissionParser.h Plugin/Token.h |
diffstat | 3 files changed, 54 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugin/PermissionParser.cpp Wed Jun 05 15:08:41 2024 +0200 +++ b/Plugin/PermissionParser.cpp Wed Jun 05 15:23:55 2024 +0200 @@ -26,9 +26,11 @@ namespace OrthancPlugins { - PermissionPattern::PermissionPattern(const OrthancPluginHttpMethod& method, const std::string& patternRegex, const std::string& permissions) : - method(method), - pattern(patternRegex) + PermissionPattern::PermissionPattern(const OrthancPluginHttpMethod& method, + const std::string& patternRegex, + const std::string& permissions) : + method_(method), + pattern_(patternRegex) { if (!permissions.empty()) { @@ -37,7 +39,7 @@ for (size_t i = 0; i < permissionsVector.size(); ++i) { - this->permissions.insert(permissionsVector[i]); + permissions_.insert(permissionsVector[i]); } } } @@ -72,6 +74,16 @@ { } + PermissionParser::~PermissionParser() + { + for (std::list<PermissionPattern*>::iterator it = permissionsPattern_.begin(); + it != permissionsPattern_.begin(); ++it) + { + assert(*it != NULL); + delete *it; + } + } + void PermissionParser::Add(const Json::Value& configuration, const IAuthorizationParser* authorizationParser) { if (configuration.type() != Json::arrayValue) @@ -150,7 +162,7 @@ LOG(WARNING) << "Authorization plugin: adding a new permission pattern: " << lowerCaseMethod << " " << regex << " - " << permission; - permissionsPattern_.push_back(PermissionPattern(parsedMethod, regex, permission)); + permissionsPattern_.push_back(new PermissionPattern(parsedMethod, regex, permission)); } bool PermissionParser::Parse(std::set<std::string>& permissions, @@ -163,16 +175,16 @@ boost::mutex::scoped_lock lock(mutex_); - for (std::list<PermissionPattern>::const_iterator it = permissionsPattern_.begin(); - it != permissionsPattern_.end(); ++it) + for (std::list<PermissionPattern*>::const_iterator it = permissionsPattern_.begin(); + it != permissionsPattern_.end(); ++it) { - if (method == it->method) + if (method == (*it)->GetMethod()) { boost::smatch what; - if (boost::regex_match(uri, what, it->pattern)) + if (boost::regex_match(uri, what, (*it)->GetPattern())) { - matchedPattern = it->pattern.expression(); - permissions = it->permissions; + matchedPattern = (*it)->GetPattern().expression(); + permissions = (*it)->GetPermissions(); return true; } }
--- a/Plugin/PermissionParser.h Wed Jun 05 15:08:41 2024 +0200 +++ b/Plugin/PermissionParser.h Wed Jun 05 15:23:55 2024 +0200 @@ -27,20 +27,39 @@ namespace OrthancPlugins { - struct PermissionPattern + class PermissionPattern : public boost::noncopyable { - OrthancPluginHttpMethod method; - boost::regex pattern; - std::set<std::string> permissions; + private: + OrthancPluginHttpMethod method_; + boost::regex pattern_; + std::set<std::string> permissions_; + + public: + PermissionPattern(const OrthancPluginHttpMethod& method, + const std::string& patternRegex, + const std::string& permissions); - PermissionPattern(const OrthancPluginHttpMethod& method, const std::string& patternRegex, const std::string& permissions); + OrthancPluginHttpMethod GetMethod() const + { + return method_; + } + + const boost::regex& GetPattern() const + { + return pattern_; + } + + const std::set<std::string>& GetPermissions() const + { + return permissions_; + } }; - class PermissionParser + class PermissionParser : public boost::noncopyable { private: mutable boost::mutex mutex_; - std::list<PermissionPattern> permissionsPattern_; + std::list<PermissionPattern*> permissionsPattern_; std::string dicomWebRoot_; std::string oe2Root_; @@ -48,6 +67,8 @@ PermissionParser(const std::string& dicomWebRoot, const std::string& oe2Root); + ~PermissionParser(); + void Add(const std::string& method, const std::string& patternRegex, const std::string& permission);