annotate Plugin/Plugin.cpp @ 201:8c79c3b026ce default tip

back to mainline
author Alain Mazy <am@orthanc.team>
date Wed, 03 Jul 2024 09:00:01 +0200
parents 21abcb97ff3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Advanced authorization plugin for Orthanc
68
1a13c4fbc9a1 copyrights
Alain Mazy <am@osimis.io>
parents: 66
diff changeset
3 * Copyright (C) 2017-2023 Osimis S.A., Belgium
150
Alain Mazy <am@osimis.io>
parents: 149
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
188
c4b908970ae4 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #include "AssociativeArray.h"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "DefaultAuthorizationParser.h"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "CachedAuthorizationService.h"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "AuthorizationWebService.h"
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
25 #include "PermissionParser.h"
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "MemoryCache.h"
34
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
27 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
28
36
8ada1b669194 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 35
diff changeset
29 #include <Compatibility.h> // For std::unique_ptr<>
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
30 #include <Logging.h>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
31 #include <Toolbox.h>
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
32 #include <SerializationToolbox.h>
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
33 #include <EmbeddedResources.h>
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
156
43b77aa34468 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 153
diff changeset
35 #define ORTHANC_PLUGIN_NAME "authorization"
43b77aa34468 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 153
diff changeset
36
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 // Configuration of the authorization plugin
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
39 static bool resourceTokensEnabled_ = false;
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
40 static bool userTokensEnabled_ = false;
36
8ada1b669194 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 35
diff changeset
41 static std::unique_ptr<OrthancPlugins::IAuthorizationParser> authorizationParser_;
8ada1b669194 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 35
diff changeset
42 static std::unique_ptr<OrthancPlugins::IAuthorizationService> authorizationService_;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
43 static std::unique_ptr<OrthancPlugins::PermissionParser> permissionParser_;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 static std::set<std::string> uncheckedResources_;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 static std::list<std::string> uncheckedFolders_;
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
46 static std::set<OrthancPlugins::Token> tokens_;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static std::set<OrthancPlugins::AccessLevel> uncheckedLevels_;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
50 static std::string JoinStrings(const std::set<std::string>& values)
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
51 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
52 std::string out;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
53 std::set<std::string> copy = values; // TODO: remove after upgrading to OrthancFramework 1.11.3+
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
54 Orthanc::Toolbox::JoinStrings(out, copy, "|");
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
55 return out;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
56 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
57
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
58
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
59 // For Orthanc prior to 1.12.2, we can not use the Forbidden error code and report the error ourselves
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
60 static void SendForbiddenError(const char* message, OrthancPluginRestOutput* output)
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
61 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
62 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
63
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
64 OrthancPluginSendHttpStatus(context, output, 403, message, strlen(message));
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
65 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
66
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
67
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
68
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
69 class TokenAndValue
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
70 {
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
71 private:
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
72 OrthancPlugins::Token token_;
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
73 std::string value_;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
74
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
75 public:
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
76 TokenAndValue(const OrthancPlugins::Token& token, const std::string& value) :
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
77 token_(token),
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
78 value_(value)
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
79 {
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
80 }
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
81
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
82 const OrthancPlugins::Token& GetToken() const
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
83 {
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
84 return token_;
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
85 }
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
86
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
87 const std::string& GetValue() const
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
88 {
e2c3c497eb8d fix LSB build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
89 return value_;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
90 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
91 };
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
92
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
93 bool HasAccessToAllLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile)
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
94 {
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
95 return (profile.authorizedLabels.find("*") != profile.authorizedLabels.end());
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
96 }
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
97
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
98 bool HasAccessToSomeLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile)
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
99 {
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
100 return (profile.authorizedLabels.size() > 0);
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
101 }
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
102
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
103 static bool HasAuthorizedLabelsForResource(bool& granted,
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
104 const OrthancPlugins::IAuthorizationParser::AccessedResources& accesses,
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
105 const OrthancPlugins::IAuthorizationService::UserProfile& profile)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
106 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
107 granted = false;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
108
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
109 if (HasAccessToAllLabels(profile))
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
110 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
111 granted = true;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
112 return true; // we could check labels
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
113 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
114
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
115 // Loop over all the accessed resources to ensure access is
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
116 // granted to each of them
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
117 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
118 access = accesses.begin(); access != accesses.end(); ++access)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
119 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
120 // Ignored the access levels that are unchecked
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
121 // (cf. "UncheckedLevels" option)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
122 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end())
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
123 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
124 std::string msg = std::string("Testing whether access to ") + OrthancPlugins::EnumerationToString(access->GetLevel()) + " \"" + access->GetOrthancId() + "\" is allowed wrt Labels for User '" + profile.name + "'";
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
125 const std::set<std::string>& resourceLabels = access->GetLabels();
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
126 std::set<std::string> authorizedResourceLabels;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
127
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
128 Orthanc::Toolbox::GetIntersection(authorizedResourceLabels, resourceLabels, profile.authorizedLabels);
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
129
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
130 if (authorizedResourceLabels.size() == 0)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
131 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
132 LOG(INFO) << msg << " -> not granted, no authorized labels";
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
133 granted = false;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
134 return true; // we could check labels
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
135 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
136 else
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
137 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
138 LOG(INFO) << msg << " -> granted, at least one authorized labels";
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
139 granted = true;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
140 return true; // we could check labels
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
141 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
142 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
143 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
144
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
145 // This method only checks if a resource is accessible thanks to its labels. If we could not check it, we always return false !!
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
146 return false; // we could not check labels
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
147 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
148
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
149
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
150 static bool CheckAuthorizedLabelsForResource(bool& granted,
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
151 const std::string& uri,
196
55760c465c3a Fix wrong access to POST /instances that was considered as a resource list
Alain Mazy <am@orthanc.team>
parents: 195
diff changeset
152 OrthancPluginHttpMethod method,
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
153 const OrthancPlugins::AssociativeArray& getArguments,
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
154 const OrthancPlugins::IAuthorizationService::UserProfile& profile)
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
155 {
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
156 granted = false;
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
157
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
158 if (HasAccessToAllLabels(profile))
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
159 {
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
160 granted = true;
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
161 return true; // we could check labels
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
162 }
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
163
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
164 if (authorizationParser_.get() != NULL &&
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
165 authorizationService_.get() != NULL)
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
166 {
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
167 // Parse the resources that are accessed through this URI
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
168 OrthancPlugins::IAuthorizationParser::AccessedResources accesses;
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
169
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
170 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap()))
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
171 {
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
172 return false; // Unable to parse this URI, we could not check labels
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
173 }
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
174
196
55760c465c3a Fix wrong access to POST /instances that was considered as a resource list
Alain Mazy <am@orthanc.team>
parents: 195
diff changeset
175 if (authorizationParser_->IsListOfResources(uri) && method == OrthancPluginHttpMethod_Get)
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
176 {
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
177 granted = false; // if a user does not have access to all labels, he can not have access to a list of resources
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
178 return true; // we could check labels
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
179 }
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
180
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
181 return HasAuthorizedLabelsForResource(granted, accesses, profile);
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
182 }
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
183
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
184 // This method only checks if a resource is accessible thanks to its labels. If we could not check it, we always return false !!
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
185 return false; // we could not check labels
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
186 }
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
187
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
188
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
189 static void GetAuthTokens(std::vector<TokenAndValue>& authTokens,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
190 uint32_t headersCount,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
191 const char *const *headersKeys,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
192 const char *const *headersValues,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
193 uint32_t getArgumentsCount,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
194 const char *const *getArgumentsKeys,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
195 const char *const *getArgumentsValues) // the tokens that are set in this request
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
196 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
197 // Extract auth tokens from headers and url get arguments
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
198 ////////////////////////////////////////////////////////////////
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
199
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
200 OrthancPlugins::AssociativeArray headers(headersCount, headersKeys, headersValues, false);
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
201 OrthancPlugins::AssociativeArray getArguments(getArgumentsCount, getArgumentsKeys, getArgumentsValues, true);
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
202
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
203 for (std::set<OrthancPlugins::Token>::const_iterator token = tokens_.begin(); token != tokens_.end(); ++token)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
204 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
205 std::string value;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
206
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
207 bool hasValue = false;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
208 switch (token->GetType())
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
209 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
210 case OrthancPlugins::TokenType_HttpHeader:
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
211 hasValue = headers.GetValue(value, token->GetKey());
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
212 break;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
213
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
214 case OrthancPlugins::TokenType_GetArgument:
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
215 hasValue = getArguments.GetValue(value, token->GetKey());
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
216 break;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
217
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
218 default:
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
219 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
220 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
221
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
222 if (hasValue)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
223 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
224 authTokens.push_back(TokenAndValue(*token, value));
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
225 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
226 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
227 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
228
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
229 static bool IsResourceAccessGranted(const std::vector<TokenAndValue>& authTokens,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
230 OrthancPluginHttpMethod method,
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
231 const OrthancPlugins::AccessedResource& access)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
232 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
233 // Ignored the access levels that are unchecked
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
234 // (cf. "UncheckedLevels" option)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
235 if (uncheckedLevels_.find(access.GetLevel()) == uncheckedLevels_.end())
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
236 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
237 std::string msg = std::string("Testing whether access to ") + OrthancPlugins::EnumerationToString(access.GetLevel()) + " \"" + access.GetOrthancId() + "\" is allowed with a resource token";
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
238 LOG(INFO) << msg;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
239
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
240 bool granted = false;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
241
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
242 if (authTokens.empty())
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
243 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
244 unsigned int validity; // ignored
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
245 granted = authorizationService_->IsGrantedToAnonymousUser(validity, method, access);
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
246 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
247 else
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
248 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
249 // Loop over all the authorization tokens in the request until finding one that is granted
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
250 for (size_t i = 0; i < authTokens.size(); ++i)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
251 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
252 unsigned int validity; // ignored
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
253 if (authorizationService_->IsGranted(validity, method, access, authTokens[i].GetToken(), authTokens[i].GetValue()))
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
254 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
255 granted = true;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
256 break;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
257 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
258 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
259 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
260
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
261 if (!granted)
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
262 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
263 LOG(INFO) << msg << " -> not granted";
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
264 return false;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
265 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
266 else
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
267 {
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
268 LOG(INFO) << msg << " -> granted";
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
269 return true;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
270 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
271 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
272
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
273 return false;
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
274 }
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
275
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 static int32_t FilterHttpRequests(OrthancPluginHttpMethod method,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 const char *uri,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 const char *ip,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 uint32_t headersCount,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 const char *const *headersKeys,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 const char *const *headersValues,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 uint32_t getArgumentsCount,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 const char *const *getArgumentsKeys,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 const char *const *getArgumentsValues)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 try
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
288 // Allow GET accesses to unchecked resources/folders (usually static resources)
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
289 ////////////////////////////////////////////////////////////////
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
290
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 if (method == OrthancPluginHttpMethod_Get)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 if (uncheckedResources_.find(uri) != uncheckedResources_.end())
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 return 1;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 for (std::list<std::string>::const_iterator
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 it = uncheckedFolders_.begin(); it != uncheckedFolders_.end(); ++it)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 if (Orthanc::Toolbox::StartsWith(uri, *it))
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 return 1;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
308 std::vector<TokenAndValue> authTokens; // the tokens that are set in this request
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
309 GetAuthTokens(authTokens, headersCount, headersKeys, headersValues, getArgumentsCount, getArgumentsKeys, getArgumentsValues);
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
310
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
311 OrthancPlugins::AssociativeArray getArguments(getArgumentsCount, getArgumentsKeys, getArgumentsValues, true);
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
312
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
313 // Based on the tokens, check if the user has access based on its permissions and the mapping between urls and permissions
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
314 ////////////////////////////////////////////////////////////////
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
315 bool hasUserRequiredPermissions = false;
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
316
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
317 if (permissionParser_.get() != NULL &&
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
318 authorizationService_.get() != NULL)
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
319 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
320 std::set<std::string> requiredPermissions;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
321 std::string matchedPattern;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
322 if (permissionParser_->Parse(requiredPermissions, matchedPattern, method, uri))
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
323 {
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
324 if (authTokens.empty())
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
325 {
103
fcc4542a0c38 cleanup
Alain Mazy <am@osimis.io>
parents: 102
diff changeset
326 std::string msg = std::string("Testing whether anonymous user has any of the required permissions '") + JoinStrings(requiredPermissions) + "'";
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
327
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
328 LOG(INFO) << msg;
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
329
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
330 unsigned int validity; // ignored
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
331 if (authorizationService_->HasAnonymousUserPermission(validity, requiredPermissions))
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
332 {
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
333 LOG(INFO) << msg << " -> granted";
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
334 hasUserRequiredPermissions = true;
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
335 }
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
336 else
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
337 {
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
338 LOG(INFO) << msg << " -> not granted";
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
339 hasUserRequiredPermissions = false;
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
340 // continue in order to check if there is a resource token that could grant access to the resource
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
341 }
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
342 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
343 else
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
344 {
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
345 for (size_t i = 0; i < authTokens.size(); ++i)
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
346 {
103
fcc4542a0c38 cleanup
Alain Mazy <am@osimis.io>
parents: 102
diff changeset
347 std::string msg = std::string("Testing whether user has the required permissions '") + JoinStrings(requiredPermissions) + "' based on the HTTP header '" + authTokens[i].GetToken().GetKey() + "' required to match '" + matchedPattern + "'";
fcc4542a0c38 cleanup
Alain Mazy <am@osimis.io>
parents: 102
diff changeset
348
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
349 // LOG(INFO) << msg;
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
350 OrthancPlugins::IAuthorizationService::UserProfile profile;
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
351 unsigned int validityNotUsed;
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
352 authorizationService_->GetUserProfile(validityNotUsed, profile, authTokens[i].GetToken(), authTokens[i].GetValue());
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
353
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
354 unsigned int validity; // ignored
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
355 if (authorizationService_->HasUserPermission(validity, requiredPermissions, profile))
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
356 {
103
fcc4542a0c38 cleanup
Alain Mazy <am@osimis.io>
parents: 102
diff changeset
357 LOG(INFO) << msg << " -> granted";
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
358 hasUserRequiredPermissions = true;
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
359
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
360 // check labels permissions
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
361 msg = std::string("Testing whether user has the authorized_labels to access '") + uri + "' based on the HTTP header '" + authTokens[i].GetToken().GetKey() + "'";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
362
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
363 bool hasAuthorizedLabelsForResource = false;
196
55760c465c3a Fix wrong access to POST /instances that was considered as a resource list
Alain Mazy <am@orthanc.team>
parents: 195
diff changeset
364 if (CheckAuthorizedLabelsForResource(hasAuthorizedLabelsForResource, uri, method, getArguments, profile))
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
365 {
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
366 if (hasAuthorizedLabelsForResource)
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
367 {
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
368 LOG(INFO) << msg << " -> granted";
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
369 }
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
370 else
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
371 {
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
372 LOG(INFO) << msg << " -> not granted";
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
373 return 0; // the labels for this resource prevents access -> stop checking now !
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
374 }
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
375 }
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
376 }
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
377 else
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
378 {
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
379 LOG(INFO) << msg << " -> not granted";
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
380 hasUserRequiredPermissions = false;
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
381 }
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
382 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
383 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
384 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
385 }
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
386
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
387 // no need to check for resource token if the user has access and if the labels checking has not prevented access
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
388 if (hasUserRequiredPermissions)
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
389 {
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
390 return 1;
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
391 }
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
392
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
393 // If we get till here, it means that we have a resource token -> check that the resource is accessible
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 114
diff changeset
394 ////////////////////////////////////////////////////////////////
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
395
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
396 if (resourceTokensEnabled_ &&
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 authorizationService_.get() != NULL)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 // Parse the resources that are accessed through this URI
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 OrthancPlugins::IAuthorizationParser::AccessedResources accesses;
56
c02f0646297d added support for /dicom-web/studies?0020000D=1.2.3&...
Alain Mazy <am@osimis.io>
parents: 54
diff changeset
401
57
55539d564f4f added support for /dicom-web/series? & /dicom-web/instances?
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
402 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap()))
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 return 0; // Unable to parse this URI
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 // Loop over all the accessed resources to ensure access is
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 // granted to each of them
138
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
409 int checkedResources = 0;
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
410 int grantedResources = 0;
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
411
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 access = accesses.begin(); access != accesses.end(); ++access)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 {
138
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
415 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end())
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
138
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
417 checkedResources++;
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
418 if (IsResourceAccessGranted(authTokens, method, *access))
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
419 {
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
420 grantedResources++;
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
421 }
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
138
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
424
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
425 if (checkedResources > 0 && grantedResources == checkedResources)
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
426 {
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
427 return 1;
f448e8626f1a Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents: 126
diff changeset
428 }
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 // By default, forbid access to all the resources
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 return 0;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 catch (std::runtime_error& e)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 LOG(ERROR) << e.what();
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 catch (Orthanc::OrthancException& e)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 LOG(ERROR) << e.What();
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 catch (...)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 LOG(ERROR) << "Unhandled internal exception";
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 static int32_t FilterHttpRequestsFallback(OrthancPluginHttpMethod method,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 const char *uri,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 const char *ip,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 uint32_t headersCount,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 const char *const *headersKeys,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 const char *const *headersValues)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 // Fallback wrapper function for Orthanc <= 1.2.0, where the GET
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 // arguments were not available in the HTTP filters
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 return FilterHttpRequests(method, uri, ip,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 headersCount, headersKeys, headersValues,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 0, NULL, NULL);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 #endif
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 static OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 OrthancPluginResourceType resourceType,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 const char* resourceId)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 try
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 if (authorizationParser_.get() == NULL)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 {
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
477 return OrthancPluginErrorCode_Success;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 if (changeType == OrthancPluginChangeType_Deleted)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 switch (resourceType)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 case OrthancPluginResourceType_Patient:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 authorizationParser_->Invalidate(Orthanc::ResourceType_Patient, resourceId);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 break;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 case OrthancPluginResourceType_Study:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 authorizationParser_->Invalidate(Orthanc::ResourceType_Study, resourceId);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 break;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 case OrthancPluginResourceType_Series:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 authorizationParser_->Invalidate(Orthanc::ResourceType_Series, resourceId);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 break;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 case OrthancPluginResourceType_Instance:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 authorizationParser_->Invalidate(Orthanc::ResourceType_Instance, resourceId);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 break;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 default:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 break;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 return OrthancPluginErrorCode_Success;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 catch (std::runtime_error& e)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 LOG(ERROR) << e.what();
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 catch (Orthanc::OrthancException& e)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 LOG(ERROR) << e.What();
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 catch (...)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 LOG(ERROR) << "Unhandled internal exception";
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 return OrthancPluginErrorCode_Success; // Ignore error
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
524
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
525 bool GetUserProfileInternal(OrthancPlugins::IAuthorizationService::UserProfile& profile, const OrthancPluginHttpRequest* request)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
526 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
527 OrthancPlugins::AssociativeArray headers
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
528 (request->headersCount, request->headersKeys, request->headersValues, false);
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
529
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
530 OrthancPlugins::AssociativeArray getArguments
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
531 (request->getCount, request->getKeys, request->getValues, true);
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
532
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
533 // Loop over all the authorization tokens stored in the HTTP
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
534 // headers, until finding one that is granted
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
535 for (std::set<OrthancPlugins::Token>::const_iterator
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
536 token = tokens_.begin(); token != tokens_.end(); ++token)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
537 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
538 OrthancPlugins::IAuthorizationService::UserProfile tryProfile;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
539
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
540 std::string value;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
541
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
542 bool hasValue = false;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
543 switch (token->GetType())
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
544 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
545 case OrthancPlugins::TokenType_HttpHeader:
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
546 hasValue = headers.GetValue(value, token->GetKey());
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
547 break;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
548
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
549 case OrthancPlugins::TokenType_GetArgument:
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
550 hasValue = getArguments.GetValue(value, token->GetKey());
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
551 break;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
552
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
553 default:
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
554 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
555 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
556
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
557 if (hasValue)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
558 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
559 unsigned int validity; // not used
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
560 if (authorizationService_->GetUserProfile(validity, tryProfile, *token, value))
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
561 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
562 profile = tryProfile;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
563 return true;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
564 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
565 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
566 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
567
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
568 return false;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
569 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
570
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
571 void AdjustToolsFindQueryLabels(Json::Value& query, const OrthancPlugins::IAuthorizationService::UserProfile& profile)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
572 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
573 std::set<std::string> labelsToFind;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
574 std::string labelsConstraint = "Invalid";
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
575
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
576 if (query.isMember("Labels") && query.isMember("LabelsConstraint"))
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
577 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
578 Orthanc::SerializationToolbox::ReadSetOfStrings(labelsToFind, query, "Labels");
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
579 labelsConstraint = Orthanc::SerializationToolbox::ReadString(query, "LabelsConstraint");
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
580 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
581 else if (query.isMember("Labels") || query.isMember("LabelsConstraint"))
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
582 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
583 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to transform tools/find query, both 'Labels' and 'LabelsConstraint' must be defined together if one of them is defined.");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
584 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
585
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
586 if (!HasAccessToSomeLabels(profile))
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
587 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
588 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to call tools/find when the user does not have access to any labels.");
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
589 }
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
590 else if (profile.authorizedLabels.size() > 0)
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
591 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
592 // if the user has access to all labels: no need to transform the tools/find body, we keep it as is
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
593 if (!HasAccessToAllLabels(profile))
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
594 { // the user does not have access to all labels -> transform the tools/find body
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
595
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
596 if (labelsToFind.size() == 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
597 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
598 if (profile.authorizedLabels.size() > 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
599 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
600 query.removeMember("Labels");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
601 Orthanc::SerializationToolbox::WriteSetOfStrings(query, profile.authorizedLabels, "Labels");
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
602 query["LabelsConstraint"] = "Any";
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
603 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
604 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
605 else if (labelsConstraint == "All")
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
606 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
607 if (profile.authorizedLabels.size() > 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
608 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
609 if (!Orthanc::Toolbox::IsSetInSet(labelsToFind, profile.authorizedLabels))
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
610 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
611 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to transform tools/find query with 'All' labels constraint when the user does not have access to all listed labels.");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
612 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
613 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
614 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
615 else if (labelsConstraint == "Any")
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
616 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
617 if (profile.authorizedLabels.size() > 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
618 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
619 std::set<std::string> newLabelsToFind;
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
620 Orthanc::Toolbox::GetIntersection(newLabelsToFind, labelsToFind, profile.authorizedLabels);
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
621
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
622 if (newLabelsToFind.size() == 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
623 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
624 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to transform tools/find query with 'All' labels constraint when none of the labels to find is authorized for the user.");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
625 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
626
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
627 query.removeMember("Labels");
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
628 Orthanc::SerializationToolbox::WriteSetOfStrings(query, newLabelsToFind, "Labels");
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
629 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
630 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
631 else if (labelsConstraint == "None")
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
632 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
633 if (profile.authorizedLabels.size() > 0)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
634 {
114
546aea509427 fix + Forbidden error code
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
635 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to transform tools/find query with 'None' labels constraint when the user only has authorized_labels.");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
636 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
637 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
638 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
639 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
640 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
641
118
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
642 bool GetStudyInstanceUIDFromQuery(std::string& studyInstanceUID, const Json::Value& body)
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
643 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
644
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
645 if (!body.isMember("Query"))
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
646 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
647 return false;
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
648 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
649
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
650 if (body["Query"].isMember("StudyInstanceUID"))
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
651 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
652 studyInstanceUID = body["Query"]["StudyInstanceUID"].asString();
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
653 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
654 else if (body["Query"].isMember("0020,000d"))
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
655 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
656 studyInstanceUID = body["Query"]["0020,000d"].asString();
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
657 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
658 else if (body["Query"].isMember("0020,000D"))
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
659 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
660 studyInstanceUID = body["Query"]["0020,000D"].asString();
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
661 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
662 else if (body["Query"].isMember("0020000D"))
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
663 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
664 studyInstanceUID = body["Query"]["0020000D"].asString();
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
665 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
666 else
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
667 {
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
668 return false;
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
669 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
670
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
671 return true;
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
672 }
6fa53f624e1c fix studyInstanceUid parsing
Alain Mazy <am@osimis.io>
parents: 117
diff changeset
673
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
674 void ToolsFind(OrthancPluginRestOutput* output,
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
675 const char* /*url*/,
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
676 const OrthancPluginHttpRequest* request)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
677 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
678 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
679
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
680 try
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
681 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
682 if (request->method != OrthancPluginHttpMethod_Post)
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
683 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
684 OrthancPluginSendMethodNotAllowed(context, output, "POST");
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
685 }
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
686 else
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
687 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
688 // The filtering to this route is performed by this plugin as it is done for any other route before we get here.
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
689
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
690 Json::Value query;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
691 if (!OrthancPlugins::ReadJson(query, request->body, request->bodySize))
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
692 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
693 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected");
116
89eddd4b2f6a tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents: 115
diff changeset
694 }
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
695
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
696 // If the logged in user has restrictions on the labels he can access, modify the tools/find payload before reposting it to Orthanc
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
697 OrthancPlugins::IAuthorizationService::UserProfile profile;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
698 if (GetUserProfileInternal(profile, request) && HasAccessToSomeLabels(profile))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
699 {
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
700 Orthanc::ResourceType queryLevel = Orthanc::StringToResourceType(query["Level"].asString().c_str());
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
701
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
702 if (queryLevel == Orthanc::ResourceType_Study)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
703 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
704 AdjustToolsFindQueryLabels(query, profile);
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
705 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
706 else if (queryLevel == Orthanc::ResourceType_Patient && !HasAccessToAllLabels(profile))
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
707 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
708 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to call tools/find at Patient level when the user does not have access to ALL labels.");
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
709 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
710 else if (queryLevel == Orthanc::ResourceType_Series || queryLevel == Orthanc::ResourceType_Instance)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
711 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
712 std::string studyInstanceUID;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
713
165
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
714 if (!HasAccessToAllLabels(profile)) // no need to adjust anything if the user has access to all labels
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
715 {
165
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
716 if (!GetStudyInstanceUIDFromQuery(studyInstanceUID, query))
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
717 {
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
718 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to call tools/find at Series or Instance level when the user does not have access to ALL labels or when there is no StudyInstanceUID in the query.");
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
719 }
99bdc05012c0 fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents: 163
diff changeset
720
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
721 // since this is a series/instance find, make sure the user has access to the parent study
162
db1a5d1634e0 fix typo
Alain Mazy <am@orthanc.team>
parents: 156
diff changeset
722 Json::Value studyOrthancIds;
163
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
723 if (!OrthancPlugins::RestApiPost(studyOrthancIds, "/tools/lookup", studyInstanceUID, false))
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
724 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
725 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find at Series or Instance level, unable to get the orthanc ID of StudyInstanceUID specified in the query.");
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
726 }
163
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
727 else if (studyOrthancIds.size() != 1)
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
728 {
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
729 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find at Series or Instance level, unable to get the orthanc ID of StudyInstanceUID specified in the query. Found " + boost::lexical_cast<std::string>(studyOrthancIds.size()) + " orthanc studies with this StudyInstanceUID");
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
730 }
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
731
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
732 bool granted = false;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
733 OrthancPlugins::IAuthorizationParser::AccessedResources accessedResources;
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
734 authorizationParser_->AddDicomStudy(accessedResources, studyInstanceUID);
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
735
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
736 if (!HasAuthorizedLabelsForResource(granted, accessedResources, profile))
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
737 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
738 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find at Series or Instance level, unable to check resource access based on the authorized_labels.");
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
739 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
740
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
741 if (!granted)
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
742 {
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
743 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find at Series or Instance level, the user shall have access to the parent study.");
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
744 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
745 }
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
746 }
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
747 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
748 else // anonymous user profile or resource token
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
749 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
750 std::string studyInstanceUID;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
751
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
752 // If anonymous user profile, it might be a resource token e.g accessing /dicom-web/studies/.../metadata
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
753 // -> extract the StudyInstanceUID from the query and send the token for validation to the auth-service
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
754 // If there is no StudyInstanceUID, then, return a 403 because we don't know what resource it relates to
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
755 if (!GetStudyInstanceUIDFromQuery(studyInstanceUID, query))
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
756 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
757 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: unable to call tools/find when the user does not have access to any labels and if there is no StudyInstanceUID in the query.");
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
758 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
759
162
db1a5d1634e0 fix typo
Alain Mazy <am@orthanc.team>
parents: 156
diff changeset
760 Json::Value studyOrthancIds;
163
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
761 if (!OrthancPlugins::RestApiPost(studyOrthancIds, "/tools/lookup", studyInstanceUID, false))
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
762 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
763 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find with a resource token, unable to get the orthanc ID of StudyInstanceUID specified in the query.");
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
764 }
163
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
765 else if (studyOrthancIds.size() != 1)
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
766 {
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
767 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find with a resource token, unable to get the orthanc ID of StudyInstanceUID specified in the query. Found " + boost::lexical_cast<std::string>(studyOrthancIds.size()) + " orthanc studies with this StudyInstanceUID");
4f5c7acb626f more detailed error message
Alain Mazy <am@orthanc.team>
parents: 162
diff changeset
768 }
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
769
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
770 std::vector<TokenAndValue> authTokens; // the tokens that are set in this request
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
771 GetAuthTokens(authTokens, request->headersCount, request->headersKeys, request->headersValues, request->getCount, request->getKeys, request->getValues);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
772
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
773 std::set<std::string> labels;
162
db1a5d1634e0 fix typo
Alain Mazy <am@orthanc.team>
parents: 156
diff changeset
774 OrthancPlugins::AccessedResource accessedResource(Orthanc::ResourceType_Study, studyOrthancIds[0]["ID"].asString(), studyInstanceUID, labels);
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
775 if (!IsResourceAccessGranted(authTokens, request->method, accessedResource))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
776 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
777 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find with a resource token, the resource must grant access to the StudyInstanceUID specified in the query.");
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
778 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
779
119
66b2b938c43e fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents: 118
diff changeset
780 }
66b2b938c43e fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents: 118
diff changeset
781
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
782 Json::Value result;
153
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
783
3683f3d083bd fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents: 150
diff changeset
784 if (OrthancPlugins::RestApiPost(result, "/tools/find", query, false))
119
66b2b938c43e fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents: 118
diff changeset
785 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
786 OrthancPlugins::AnswerJson(result, output);
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
787 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
788
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
789 }
119
66b2b938c43e fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents: 118
diff changeset
790
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
791 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
792 catch(const Orthanc::OrthancException& e)
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
793 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
794 // this error is not yet supported in Orthanc 1.12.1
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
795 if (e.GetErrorCode() == Orthanc::ErrorCode_ForbiddenAccess && !OrthancPlugins::CheckMinimalOrthancVersion(1, 12, 2))
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
796 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
797 SendForbiddenError(e.GetDetails(), output);
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
798 }
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
799 else
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
800 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
801 throw;
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
802 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
803 }
119
66b2b938c43e fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents: 118
diff changeset
804
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
805 }
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
806
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
807 void ToolsLabels(OrthancPluginRestOutput* output,
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
808 const char* /*url*/,
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
809 const OrthancPluginHttpRequest* request)
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
810 {
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
811 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
812
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
813 try
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
814 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
815 if (request->method != OrthancPluginHttpMethod_Get)
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
816 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
817 OrthancPluginSendMethodNotAllowed(context, output, "GET");
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
818 }
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
819 else
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
820 {
124
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
821 // The filtering to this route is performed by this plugin as it is done for any other route before we get here.
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
822
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
823 // If the logged in user has restrictions on the labels he can access, modify the tools/labels response before answering
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
824 OrthancPlugins::IAuthorizationService::UserProfile profile;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
825 if (GetUserProfileInternal(profile, request))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
826 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
827 if (!HasAccessToSomeLabels(profile))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
828 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
829 Json::Value emptyLabels;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
830 OrthancPlugins::AnswerJson(emptyLabels, output);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
831 return;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
832 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
833
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
834 Json::Value jsonLabels;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
835 if (OrthancPlugins::RestApiGet(jsonLabels, "/tools/labels", false))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
836 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
837 std::set<std::string> allLabels;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
838 Orthanc::SerializationToolbox::ReadSetOfStrings(allLabels, jsonLabels);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
839
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
840 if (!HasAccessToAllLabels(profile))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
841 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
842 std::set<std::string> authorizedLabels;
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
843
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
844 Orthanc::Toolbox::GetIntersection(authorizedLabels, allLabels, profile.authorizedLabels);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
845 Orthanc::SerializationToolbox::WriteSetOfStrings(jsonLabels, authorizedLabels);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
846 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
847 OrthancPlugins::AnswerJson(jsonLabels, output);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
848 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
849
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
850 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
851 else
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
852 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
853 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: no user profile found, access to tools/labels is forbidden.");
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
854 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
855 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
856 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
857 catch(const Orthanc::OrthancException& e)
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
858 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
859 // this error is not yet supported in Orthanc 1.12.1
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
860 if (e.GetErrorCode() == Orthanc::ErrorCode_ForbiddenAccess && !OrthancPlugins::CheckMinimalOrthancVersion(1, 12, 2))
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
861 {
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
862 SendForbiddenError(e.GetDetails(), output);
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
863 }
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
864 else
d5232d374fd8 Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents: 120
diff changeset
865 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
866 throw;
112
572955904411 added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents: 111
diff changeset
867 }
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
868 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
869 }
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
870
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
871
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
872 void CreateToken(OrthancPluginRestOutput* output,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
873 const char* /*url*/,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
874 const OrthancPluginHttpRequest* request)
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
875 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
876 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
877
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
878 if (request->method != OrthancPluginHttpMethod_Put)
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
879 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
880 OrthancPluginSendMethodNotAllowed(context, output, "PUT");
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
881 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
882 else
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
883 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
884 // The filtering to this route is performed by this plugin as it is done for any other route before we get here.
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
885 // Since the route contains the tokenType, we can allow/forbid creating them based on the url
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
886
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
887 // simply forward the request to the auth-service
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
888 std::string tokenType;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
889 if (request->groupsCount == 1)
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
890 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
891 tokenType = request->groups[0];
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
892 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
893 else
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
894 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
895 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
896 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
897
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
898 // convert from Orthanc flavored API to WebService API
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
899 Json::Value body;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
900 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
901 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
902 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected");
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
903 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
904
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
905 std::string id;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
906 std::vector<OrthancPlugins::IAuthorizationService::OrthancResource> resources;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
907 std::string expirationDateString;
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
908 uint64_t validityDuration;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
909
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
910 if (body.isMember("ID"))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
911 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
912 id = body["ID"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
913 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
914
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
915 for (Json::ArrayIndex i = 0; i < body["Resources"].size(); ++i)
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
916 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
917 const Json::Value& jsonResource = body["Resources"][i];
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
918 OrthancPlugins::IAuthorizationService::OrthancResource resource;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
919
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
920 if (jsonResource.isMember("DicomUid"))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
921 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
922 resource.dicomUid = jsonResource["DicomUid"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
923 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
924
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
925 if (jsonResource.isMember("OrthancId"))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
926 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
927 resource.orthancId = jsonResource["OrthancId"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
928 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
929
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
930 if (jsonResource.isMember("Url"))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
931 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
932 resource.url = jsonResource["Url"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
933 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
934
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
935 resource.level = jsonResource["Level"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
936 resources.push_back(resource);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
937 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
938
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
939 if (body.isMember("ExpirationDate"))
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
940 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
941 expirationDateString = body["ExpirationDate"].asString();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
942 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
943
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
944 if (body.isMember("ValidityDuration"))
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
945 {
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
946 validityDuration = body["ValidityDuration"].asUInt64();
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
947 }
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
948
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
949 OrthancPlugins::IAuthorizationService::CreatedToken createdToken;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
950 if (authorizationService_->CreateToken(createdToken,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
951 tokenType,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
952 id,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
953 resources,
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
954 expirationDateString,
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
955 validityDuration))
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
956 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
957 Json::Value createdJsonToken;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
958 createdJsonToken["Token"] = createdToken.token;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
959
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
960 if (!createdToken.url.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
961 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
962 createdJsonToken["Url"] = createdToken.url;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
963 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
964 else
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
965 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
966 createdJsonToken["Url"] = Json::nullValue;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
967 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
968
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
969 OrthancPlugins::AnswerJson(createdJsonToken, output);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
970 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
971
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
972
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
973 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
974 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
975
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
976 void DecodeToken(OrthancPluginRestOutput* output,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
977 const char* /*url*/,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
978 const OrthancPluginHttpRequest* request)
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
979 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
980 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
981
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
982 if (request->method != OrthancPluginHttpMethod_Post)
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
983 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
984 OrthancPluginSendMethodNotAllowed(context, output, "POST");
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
985 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
986 else
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
987 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
988 // convert from Orthanc flavored API to WebService API
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
989 Json::Value body;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
990 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize))
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
991 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
992 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected");
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
993 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
994
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
995 OrthancPlugins::IAuthorizationService::DecodedToken decodedToken;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
996 if (authorizationService_->DecodeToken(decodedToken,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
997 body["TokenKey"].asString(),
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
998 body["TokenValue"].asString()))
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
999 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1000 Json::Value decodedJsonToken;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1001
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1002 if (!decodedToken.redirectUrl.empty())
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1003 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1004 decodedJsonToken["RedirectUrl"] = decodedToken.redirectUrl;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1005 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1006
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1007 if (!decodedToken.errorCode.empty())
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1008 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1009 decodedJsonToken["ErrorCode"] = decodedToken.errorCode;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1010 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1011
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1012 if (!decodedToken.tokenType.empty())
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1013 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1014 decodedJsonToken["TokenType"] = decodedToken.tokenType;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1015 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1016
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1017 OrthancPlugins::AnswerJson(decodedJsonToken, output);
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1018 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1019 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1020 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1021
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1022
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1023 void GetUserProfile(OrthancPluginRestOutput* output,
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1024 const char* /*url*/,
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1025 const OrthancPluginHttpRequest* request)
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1026 {
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1027 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1028
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1029 if (request->method != OrthancPluginHttpMethod_Get)
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1030 {
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1031 OrthancPluginSendMethodNotAllowed(context, output, "GET");
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1032 }
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1033 else
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1034 {
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1035 OrthancPlugins::IAuthorizationService::UserProfile profile;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1036 if (GetUserProfileInternal(profile, request))
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1037 {
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1038 Json::Value jsonProfile;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1039 jsonProfile["name"] = profile.name;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1040 jsonProfile["permissions"] = Json::arrayValue;
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1041 for (std::set<std::string>::const_iterator it = profile.permissions.begin(); it != profile.permissions.end(); ++it)
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1042 {
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1043 jsonProfile["permissions"].append(*it);
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1044 }
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1045 for (std::set<std::string>::const_iterator it = profile.authorizedLabels.begin(); it != profile.authorizedLabels.end(); ++it)
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1046 {
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1047 jsonProfile["authorized-labels"].append(*it);
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1048 }
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 103
diff changeset
1049
111
2b1a95c7d263 wip: adjust tools/find queries
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
1050 OrthancPlugins::AnswerJson(jsonProfile, output);
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1051 }
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1052 }
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1053 }
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
1054
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1055
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1056 void AuthSettingsRoles(OrthancPluginRestOutput* output,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1057 const char* /*url*/,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1058 const OrthancPluginHttpRequest* request)
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1059 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1060 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1061
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1062 if (authorizationService_.get() == NULL) // this is not suppposed to happen
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1063 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1064 OrthancPlugins::AnswerHttpError(404, output);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1065 return;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1066 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1067
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1068 if (request->method == OrthancPluginHttpMethod_Get)
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1069 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1070 Json::Value roles;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1071
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1072 if (!authorizationService_->GetSettingsRoles(roles))
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1073 {
199
21abcb97ff3c Fix internal error when the auth-service was not configured to implement the role/permission API
Alain Mazy <am@orthanc.team>
parents: 196
diff changeset
1074 LOG(WARNING) << "Could not retrieve roles from the auth-service. The auth-service might not provide this feature or is not configured correctly.";
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1075 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1076
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1077 OrthancPlugins::AnswerJson(roles, output);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1078 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1079 else if (request->method == OrthancPluginHttpMethod_Put)
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1080 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1081 Json::Value roles;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1082 Json::Value response;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1083
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1084 if (!OrthancPlugins::ReadJson(roles, request->body, request->bodySize))
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1085 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1086 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected");
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1087 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1088
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1089 if (!authorizationService_->UpdateSettingsRoles(response, roles))
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1090 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1091 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Could not update roles in the auth-service", true);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1092 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1093 OrthancPlugins::AnswerJson(response, output);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1094 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1095 else
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1096 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1097 OrthancPluginSendMethodNotAllowed(context, output, "GET,PUT");
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1098 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1099 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1100
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1101
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1102 void GetPermissionList(OrthancPluginRestOutput* output,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1103 const char* /*url*/,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1104 const OrthancPluginHttpRequest* request)
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1105 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1106 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext();
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1107
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1108 if (request->method != OrthancPluginHttpMethod_Get)
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1109 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1110 OrthancPluginSendMethodNotAllowed(context, output, "GET");
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1111 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1112 else
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1113 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1114 std::set<std::string> permissionsList = permissionParser_->GetPermissionsList();
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1115
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1116 Json::Value response = Json::arrayValue;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1117 Orthanc::SerializationToolbox::WriteSetOfStrings(response, permissionsList);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1118
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1119 OrthancPlugins::AnswerJson(response, output);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1120 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1121 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1122
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1123
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1124 void MergeJson(Json::Value &a, const Json::Value &b) {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1125
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1126 if (!a.isObject() || !b.isObject())
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1127 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1128 return;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1129 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1130
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1131 Json::Value::Members members = b.getMemberNames();
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1132
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1133 for (size_t i = 0; i < members.size(); i++)
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1134 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1135 std::string key = members[i];
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1136
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1137 if (!a[key].isNull() && a[key].type() == Json::objectValue && b[key].type() == Json::objectValue)
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1138 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1139 MergeJson(a[key], b[key]);
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1140 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1141 else
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1142 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1143 a[key] = b[key];
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1144 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1145 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1146 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1147
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 extern "C"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 {
29
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1153 OrthancPlugins::SetGlobalContext(context);
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1154 OrthancPluginLogWarning(context, "Initializing the authorization plugin");
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 /* Check the version of the Orthanc core */
29
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1157 if (OrthancPluginCheckVersion(context) == 0)
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 {
29
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1159 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 return -1;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164
164
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
1165 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
1166 Orthanc::Logging::InitializePluginContext(context, ORTHANC_PLUGIN_NAME);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 163
diff changeset
1167 #elif ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2)
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
1168 Orthanc::Logging::InitializePluginContext(context);
33
b9c536bf598b improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
1169 #else
b9c536bf598b improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
1170 Orthanc::Logging::Initialize(context);
b9c536bf598b improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
1171 #endif
b9c536bf598b improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 32
diff changeset
1172
156
43b77aa34468 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 153
diff changeset
1173 OrthancPlugins::SetDescription(ORTHANC_PLUGIN_NAME, "Advanced authorization plugin for Orthanc.");
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 try
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1177 static const char* const PLUGIN_SECTION = "Authorization";
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1178
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1179 OrthancPlugins::OrthancConfiguration orthancFullConfiguration;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1180
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1181 // read default configuration
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1182 std::string defaultConfigurationFileContent;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1183 Orthanc::EmbeddedResources::GetFileResource(defaultConfigurationFileContent, Orthanc::EmbeddedResources::DEFAULT_CONFIGURATION);
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1184 Json::Value pluginJsonDefaultConfiguration;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1185 OrthancPlugins::ReadJsonWithoutComments(pluginJsonDefaultConfiguration, defaultConfigurationFileContent);
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1186 Json::Value pluginJsonConfiguration = pluginJsonDefaultConfiguration[PLUGIN_SECTION];
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1188 OrthancPlugins::OrthancConfiguration pluginProvidedConfiguration;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1189
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1190 if (orthancFullConfiguration.IsSection(PLUGIN_SECTION))
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 {
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1192 // get the configuration provided by the user
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1193 orthancFullConfiguration.GetSection(pluginProvidedConfiguration, PLUGIN_SECTION);
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1194
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1195 // merge it with the default configuration. This is a way to apply the all default values in a single step
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1196 MergeJson(pluginJsonConfiguration, pluginProvidedConfiguration.GetJson());
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1197
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1198 // recreate a OrthancConfiguration object from the merged configuration
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1199 OrthancPlugins::OrthancConfiguration pluginConfiguration(pluginJsonConfiguration, PLUGIN_SECTION);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 // TODO - The size of the caches is set to 10,000 items. Maybe add a configuration option?
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 OrthancPlugins::MemoryCache::Factory factory(10000);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1204 std::string dicomWebRoot = "/dicom-web/";
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1205 std::string oe2Root = "/ui/";
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1207 bool hasBasicAuthEnabled = orthancFullConfiguration.GetBooleanValue("AuthenticationEnabled", "true");
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1208
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1209 if (orthancFullConfiguration.IsSection("DicomWeb"))
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1210 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1211 OrthancPlugins::OrthancConfiguration dicomWeb;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1212 dicomWeb.GetSection(orthancFullConfiguration, "DicomWeb");
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1213 dicomWebRoot = dicomWeb.GetStringValue("Root", "/dicom-web/");
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1214 }
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1216 if (orthancFullConfiguration.IsSection("OrthancExplorer2"))
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1217 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1218 OrthancPlugins::OrthancConfiguration oe2;
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1219 oe2.GetSection(orthancFullConfiguration, "OrthancExplorer2");
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1220 oe2Root = oe2.GetStringValue("Root", "/ui/");
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 std::list<std::string> tmp;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1225 pluginConfiguration.LookupListOfStrings(tmp, "TokenHttpHeaders", true);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 for (std::list<std::string>::const_iterator
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 it = tmp.begin(); it != tmp.end(); ++it)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 {
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1229 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, *it));
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1232 pluginConfiguration.LookupListOfStrings(tmp, "TokenGetArguments", true);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233
8
4362026afddf orthanc 1.2.1 renamed as 1.3.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
1234 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 3, 0)
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 for (std::list<std::string>::const_iterator
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 it = tmp.begin(); it != tmp.end(); ++it)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 {
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1238 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it));
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 #else
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 if (!tmp.empty())
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 {
29
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1243 throw Orthanc::OrthancException(
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1244 Orthanc::ErrorCode_Plugin,
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1245 "The option \"TokenGetArguments\" of the authorization plugin "
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
1246 "is only valid if compiled against Orthanc >= 1.3.0"
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 #endif
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1250 pluginConfiguration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false);
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1251 pluginConfiguration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1253 std::string urlTokenDecoder;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1254 std::string urlTokenValidation;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1255 std::string urlTokenCreationBase;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1256 std::string urlUserProfile;
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1257 std::string urlSettingsRole;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1258 std::string urlRoot;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1260 static const char* const WEB_SERVICE_ROOT = "WebServiceRootUrl";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1261
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1262 if (pluginConfiguration.LookupStringValue(urlRoot, WEB_SERVICE_ROOT))
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1263 {
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1264 urlTokenDecoder = Orthanc::Toolbox::JoinUri(urlRoot, "/tokens/decode");
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1265 urlTokenValidation = Orthanc::Toolbox::JoinUri(urlRoot, "/tokens/validate");
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1266 urlTokenCreationBase = Orthanc::Toolbox::JoinUri(urlRoot, "/tokens/");
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1267 urlUserProfile = Orthanc::Toolbox::JoinUri(urlRoot, "/user/get-profile");
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1268 urlSettingsRole = Orthanc::Toolbox::JoinUri(urlRoot, "/settings/roles");
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1269 }
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1270 else
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1271 {
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1272 static const char* const WEB_SERVICE_TOKEN_DECODER = "WebServiceTokenDecoderUrl";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1273 static const char* const WEB_SERVICE_TOKEN_VALIDATION = "WebServiceTokenValidationUrl";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1274 static const char* const WEB_SERVICE_TOKEN_CREATION_BASE = "WebServiceTokenCreationBaseUrl";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1275 static const char* const WEB_SERVICE_USER_PROFILE = "WebServiceUserProfileUrl";
195
Alain Mazy <am@orthanc.team>
parents: 194 190
diff changeset
1276 static const char* const WEB_SERVICE_SETTINGS_ROLES = "WebServiceSettingsRolesUrl";
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1277 static const char* const WEB_SERVICE_TOKEN_VALIDATION_LEGACY = "WebService";
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1278
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1279 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION);
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1280 pluginConfiguration.LookupStringValue(urlTokenDecoder, WEB_SERVICE_TOKEN_DECODER);
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1281 if (urlTokenValidation.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1282 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1283 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION_LEGACY);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1284 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1285
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1286 pluginConfiguration.LookupStringValue(urlTokenCreationBase, WEB_SERVICE_TOKEN_CREATION_BASE);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1287 pluginConfiguration.LookupStringValue(urlUserProfile, WEB_SERVICE_USER_PROFILE);
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1288 pluginConfiguration.LookupStringValue(urlSettingsRole, WEB_SERVICE_SETTINGS_ROLES);
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1289 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1290
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1291 authorizationParser_.reset(new OrthancPlugins::DefaultAuthorizationParser(factory, dicomWebRoot));
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1292
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1293 if (!urlTokenValidation.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1294 {
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1295 LOG(WARNING) << "Authorization plugin: url defined for Token Validation: " << urlTokenValidation << ", resource tokens validation is enabled";
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1296 resourceTokensEnabled_ = true;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1297 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1298 else
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1299 {
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1300 LOG(WARNING) << "Authorization plugin: no url defined for Token Validation, resource tokens validation is disabled";
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1301 resourceTokensEnabled_ = false;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1302 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1303
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1304 if (!urlUserProfile.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1305 {
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1306 LOG(WARNING) << "Authorization plugin: url defined for User Profile: " << urlUserProfile << ", user tokens validation is enabled";
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1307 userTokensEnabled_ = true;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1308
190
de232f9b3a60 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
1309 static const char* const PERMISSIONS = "Permissions";
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1310 if (!pluginConfiguration.GetJson().isMember(PERMISSIONS))
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1311 {
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1312 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Authorization plugin: Missing required \"" + std::string(PERMISSIONS) +
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1313 "\" option since you have defined the \"" + std::string(WEB_SERVICE_ROOT) + "\" option");
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1314 }
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1315 permissionParser_.reset
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1316 (new OrthancPlugins::PermissionParser(dicomWebRoot, oe2Root));
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1317
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1318 permissionParser_->Add(pluginConfiguration.GetJson()[PERMISSIONS], authorizationParser_.get());
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1319 }
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1320 else
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1321 {
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1322 LOG(WARNING) << "Authorization plugin: no url defined for User Profile" << ", user tokens validation is disabled";
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1323 userTokensEnabled_ = false;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1324 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1325
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1326 if (!urlTokenCreationBase.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1327 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1328 LOG(WARNING) << "Authorization plugin: base url defined for Token Creation : " << urlTokenCreationBase;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1329 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1330 else
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1331 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1332 LOG(WARNING) << "Authorization plugin: no base url defined for Token Creation";
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1333 }
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1334
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1335 if (!urlSettingsRole.empty())
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1336 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1337 LOG(WARNING) << "Authorization plugin: settings-roles url defined : " << urlSettingsRole;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1338 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1339 else
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1340 {
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1341 LOG(WARNING) << "Authorization plugin: no settings-roles url defined";
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1342 }
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1343
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1344 if (!resourceTokensEnabled_ && permissionParser_.get() == NULL)
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1345 {
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1346 if (hasBasicAuthEnabled)
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1347 {
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1348 LOG(WARNING) << "Authorization plugin: No Token Validation or User Profile url defined -> will only be able to generate tokens. All API routes are accessible to all registered users.";
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1349 }
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1350 else
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1351 {
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1352 LOG(WARNING) << "Authorization plugin: ----------- insecure setup ---------- No Token Validation or User Profile url defined -> will only be able to generate tokens. Authentication is not enabled -> anyone will have access to all API routes.";
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1353 }
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1356 std::set<std::string> standardConfigurations;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1357 if (pluginConfiguration.LookupSetOfStrings(standardConfigurations, "StandardConfigurations", false))
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1358 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1359 if (standardConfigurations.find("osimis-web-viewer") != standardConfigurations.end())
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1360 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1361 uncheckedFolders_.push_back("/osimis-viewer/app/");
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1362 uncheckedFolders_.push_back("/osimis-viewer/languages/");
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1363 uncheckedResources_.insert("/osimis-viewer/config.js");
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1364
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1365 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "token"));
95
dff72e397f90 fix standard configuration 'orthanc-explorer-2' for TokenGetArguments
Alain Mazy <am@osimis.io>
parents: 86
diff changeset
1366 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in Webviewer
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1367 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1368
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1369 if (standardConfigurations.find("stone-webviewer") != standardConfigurations.end())
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1370 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1371 uncheckedFolders_.push_back("/stone-webviewer/");
65
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1372 uncheckedResources_.insert("/system"); // for Stone to check that Orthanc is the server providing the data
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1373
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1374 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization"));
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1375 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1376
65
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1377 if (standardConfigurations.find("orthanc-explorer-2") != standardConfigurations.end())
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1378 {
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1379 uncheckedFolders_.push_back("/ui/app/");
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1380 uncheckedFolders_.push_back("/ui/landing/");
76
d301047ee3c4 fix unchecked resource
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
1381 uncheckedResources_.insert("/"); // for the redirect to /ui/app/
66
b7fd466764cc fix path for oe2 keycloak
Alain Mazy <am@osimis.io>
parents: 65
diff changeset
1382 uncheckedResources_.insert("/ui/api/pre-login-configuration"); // for the UI to know, i.e. if Keycloak is enabled or not
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1383 uncheckedResources_.insert("/ui/api/configuration");
120
Alain Mazy <am@osimis.io>
parents: 119
diff changeset
1384 uncheckedResources_.insert("/auth/user/profile");
65
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1385
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1386 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); // for basic-auth
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1387 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "token")); // for keycloak
95
dff72e397f90 fix standard configuration 'orthanc-explorer-2' for TokenGetArguments
Alain Mazy <am@osimis.io>
parents: 86
diff changeset
1388 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in OE2
65
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1389 }
a89e1fcf56b1 new oe2 standard configuration
Alain Mazy <am@osimis.io>
parents: 62
diff changeset
1390
102
18d3f7bd18db new standard configuration 'ohif'
Alain Mazy <am@osimis.io>
parents: 95
diff changeset
1391 if (standardConfigurations.find("ohif") != standardConfigurations.end())
18d3f7bd18db new standard configuration 'ohif'
Alain Mazy <am@osimis.io>
parents: 95
diff changeset
1392 {
18d3f7bd18db new standard configuration 'ohif'
Alain Mazy <am@osimis.io>
parents: 95
diff changeset
1393 uncheckedFolders_.push_back("/ohif/");
18d3f7bd18db new standard configuration 'ohif'
Alain Mazy <am@osimis.io>
parents: 95
diff changeset
1394 }
18d3f7bd18db new standard configuration 'ohif'
Alain Mazy <am@osimis.io>
parents: 95
diff changeset
1395
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1396 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1397
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1398 std::string checkedLevelString;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1399 if (pluginConfiguration.LookupStringValue(checkedLevelString, "CheckedLevel"))
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1400 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1401 OrthancPlugins::AccessLevel checkedLevel = OrthancPlugins::StringToAccessLevel(checkedLevelString);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1402 if (checkedLevel == OrthancPlugins::AccessLevel_Instance)
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1403 {
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
1404 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System);
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1405 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1406 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1407 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1408 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1409 else if (checkedLevel == OrthancPlugins::AccessLevel_Series)
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1410 {
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
1411 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System);
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1412 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1413 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1414 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1415 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1416 else if (checkedLevel == OrthancPlugins::AccessLevel_Study)
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1417 {
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
1418 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System);
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1419 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1420 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1421 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1422 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1423 else if (checkedLevel == OrthancPlugins::AccessLevel_Patient)
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1424 {
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
1425 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System);
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1426 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1427 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1428 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance);
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1429 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1430 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1431
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1432 if (pluginConfiguration.LookupListOfStrings(tmp, "UncheckedLevels", false))
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433 {
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1434 if (uncheckedLevels_.size() == 0)
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435 {
58
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1436 for (std::list<std::string>::const_iterator
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1437 it = tmp.begin(); it != tmp.end(); ++it)
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1438 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1439 uncheckedLevels_.insert(OrthancPlugins::StringToAccessLevel(*it));
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1440 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1441 }
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1442 else
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1443 {
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1444 LOG(ERROR) << "Authorization plugin: you may only provide one of 'CheckedLevel' or 'UncheckedLevels' configurations";
ad279c70c22d added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
1445 return -1;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1449 std::unique_ptr<OrthancPlugins::AuthorizationWebService> webService(new OrthancPlugins::AuthorizationWebService(urlTokenValidation,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1450 urlTokenCreationBase,
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1451 urlUserProfile,
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1452 urlTokenDecoder,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1453 urlSettingsRole));
54
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1454
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1455 std::string webServiceIdentifier;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1456 if (pluginConfiguration.LookupStringValue(webServiceIdentifier, "WebServiceIdentifier"))
54
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1457 {
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1458 webService->SetIdentifier(webServiceIdentifier);
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1459 }
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1460
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1461 std::string webServiceUsername;
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1462 std::string webServicePassword;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1463 if (pluginConfiguration.LookupStringValue(webServiceUsername, "WebServiceUsername") && pluginConfiguration.LookupStringValue(webServicePassword, "WebServicePassword"))
54
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1464 {
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1465 webService->SetCredentials(webServiceUsername, webServicePassword);
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1466 }
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1467
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 authorizationService_.reset
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 (new OrthancPlugins::CachedAuthorizationService
54
317b31e99501 Added 3 new configurations: WebServiceUsername, WebServicePassword, WebServiceIdentifier. WebServiceIdentifier is now included in the payload as the 'identifier' field
Alain Mazy <am@osimis.io>
parents: 51
diff changeset
1470 (webService.release(), factory));
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1472 if (!urlTokenValidation.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1473 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1474 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1475 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1476
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1477 if (!urlTokenDecoder.empty())
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1478 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1479 OrthancPlugins::RegisterRestCallback<DecodeToken>("/auth/tokens/decode", true);
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1480 }
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1481
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1482 if (!urlUserProfile.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1483 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1484 OrthancPlugins::RegisterRestCallback<GetUserProfile>("/auth/user/profile", true);
126
8b123c2adb69 now overriding /tools/find and /tools/labels only if the auth-service is providing user profile
Alain Mazy <am@osimis.io>
parents: 124
diff changeset
1485 OrthancPlugins::RegisterRestCallback<ToolsFind>("/tools/find", true);
8b123c2adb69 now overriding /tools/find and /tools/labels only if the auth-service is providing user profile
Alain Mazy <am@osimis.io>
parents: 124
diff changeset
1486 OrthancPlugins::RegisterRestCallback<ToolsLabels>("/tools/labels", true);
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1487 OrthancPlugins::RegisterRestCallback<AuthSettingsRoles>("/auth/settings/roles", true);
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
1488 OrthancPlugins::RegisterRestCallback<GetPermissionList>("/auth/settings/permissions", true);
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1489 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1490
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1491 if (!urlTokenCreationBase.empty())
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1492 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1493 OrthancPlugins::RegisterRestCallback<CreateToken>("/auth/tokens/(.*)", true);
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
1494 }
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
1495
149
423531fb1200 SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents: 138
diff changeset
1496 if (resourceTokensEnabled_ || userTokensEnabled_)
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1497 {
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1498 if (hasBasicAuthEnabled)
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1499 {
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1500 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Authorization plugin: you are using the plugin to grant access to resources or handle user permissions. This is not compatible with \"AuthenticationEnabled\" = true");
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1501 }
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1502
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1503 LOG(WARNING) << "Authorization plugin: Registering Incoming HTTP Request Filter";
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1504
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1)
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1506 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 #else
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1508 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback);
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 #endif
81
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1510 }
fac45493d547 more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
1511
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 else
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1514 {
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
1515 LOG(WARNING) << "No section \"" << PLUGIN_SECTION << "\" in the configuration file, "
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 << "the authorization plugin is disabled";
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519 catch (Orthanc::OrthancException& e)
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521 LOG(ERROR) << e.What();
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 return -1;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525 return 0;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 authorizationParser_.reset(NULL);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536 {
156
43b77aa34468 fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 153
diff changeset
1537 return ORTHANC_PLUGIN_NAME;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 {
22
c44013681a51 now using the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
1543 return ORTHANC_PLUGIN_VERSION;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 }