Mercurial > hg > orthanc-authorization
annotate Plugin/Plugin.cpp @ 202:3c56c3f0059a default tip
Fix forbidden access when the PatientID and StudyInstanceUID are identical
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 23 Sep 2024 12:43:33 +0200 |
parents | 21abcb97ff3c |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Advanced authorization plugin for Orthanc | |
68 | 3 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
150 | 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 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #include "AssociativeArray.h" | |
22 #include "DefaultAuthorizationParser.h" | |
23 #include "CachedAuthorizationService.h" | |
24 #include "AuthorizationWebService.h" | |
71 | 25 #include "PermissionParser.h" |
1 | 26 #include "MemoryCache.h" |
34 | 27 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
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 | 30 #include <Logging.h> |
31 #include <Toolbox.h> | |
111 | 32 #include <SerializationToolbox.h> |
71 | 33 #include <EmbeddedResources.h> |
1 | 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 | 37 |
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 | 43 static std::unique_ptr<OrthancPlugins::PermissionParser> permissionParser_; |
1 | 44 static std::set<std::string> uncheckedResources_; |
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 | 47 static std::set<OrthancPlugins::AccessLevel> uncheckedLevels_; |
48 | |
49 | |
71 | 50 static std::string JoinStrings(const std::set<std::string>& values) |
51 { | |
52 std::string out; | |
53 std::set<std::string> copy = values; // TODO: remove after upgrading to OrthancFramework 1.11.3+ | |
54 Orthanc::Toolbox::JoinStrings(out, copy, "|"); | |
55 return out; | |
56 } | |
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 | 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 | 71 private: |
72 OrthancPlugins::Token token_; | |
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 | 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 | 77 token_(token), |
78 value_(value) | |
79 { | |
80 } | |
81 | |
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 | 84 return token_; |
85 } | |
86 | |
87 const std::string& GetValue() const | |
88 { | |
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 | 93 bool HasAccessToAllLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile) |
94 { | |
95 return (profile.authorizedLabels.find("*") != profile.authorizedLabels.end()); | |
96 } | |
97 | |
98 bool HasAccessToSomeLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
99 { | |
100 return (profile.authorizedLabels.size() > 0); | |
101 } | |
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 | 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 | 153 const OrthancPlugins::AssociativeArray& getArguments, |
154 const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
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 | 158 if (HasAccessToAllLabels(profile)) |
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 | 162 } |
163 | |
164 if (authorizationParser_.get() != NULL && | |
165 authorizationService_.get() != NULL) | |
166 { | |
167 // Parse the resources that are accessed through this URI | |
168 OrthancPlugins::IAuthorizationParser::AccessedResources accesses; | |
169 | |
170 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) | |
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 | 179 } |
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 | 182 } |
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 | 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 | 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 | 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 | 276 static int32_t FilterHttpRequests(OrthancPluginHttpMethod method, |
277 const char *uri, | |
278 const char *ip, | |
279 uint32_t headersCount, | |
280 const char *const *headersKeys, | |
281 const char *const *headersValues, | |
282 uint32_t getArgumentsCount, | |
283 const char *const *getArgumentsKeys, | |
284 const char *const *getArgumentsValues) | |
285 { | |
286 try | |
287 { | |
109 | 288 // Allow GET accesses to unchecked resources/folders (usually static resources) |
289 //////////////////////////////////////////////////////////////// | |
290 | |
1 | 291 if (method == OrthancPluginHttpMethod_Get) |
292 { | |
293 if (uncheckedResources_.find(uri) != uncheckedResources_.end()) | |
294 { | |
295 return 1; | |
296 } | |
297 | |
298 for (std::list<std::string>::const_iterator | |
299 it = uncheckedFolders_.begin(); it != uncheckedFolders_.end(); ++it) | |
300 { | |
301 if (Orthanc::Toolbox::StartsWith(uri, *it)) | |
302 { | |
303 return 1; | |
304 } | |
305 } | |
306 } | |
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 | 312 |
109 | 313 // Based on the tokens, check if the user has access based on its permissions and the mapping between urls and permissions |
314 //////////////////////////////////////////////////////////////// | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
315 bool hasUserRequiredPermissions = false; |
109 | 316 |
71 | 317 if (permissionParser_.get() != NULL && |
318 authorizationService_.get() != NULL) | |
319 { | |
320 std::set<std::string> requiredPermissions; | |
321 std::string matchedPattern; | |
322 if (permissionParser_->Parse(requiredPermissions, matchedPattern, method, uri)) | |
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 | 325 { |
103 | 326 std::string msg = std::string("Testing whether anonymous user has any of the required permissions '") + JoinStrings(requiredPermissions) + "'"; |
113 | 327 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
328 LOG(INFO) << msg; |
190 | 329 |
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 | 342 } |
343 else | |
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 | 346 { |
103 | 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 + "'"; |
348 | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
349 // LOG(INFO) << msg; |
113 | 350 OrthancPlugins::IAuthorizationService::UserProfile profile; |
351 unsigned int validityNotUsed; | |
352 authorizationService_->GetUserProfile(validityNotUsed, profile, authTokens[i].GetToken(), authTokens[i].GetValue()); | |
353 | |
190 | 354 unsigned int validity; // ignored |
113 | 355 if (authorizationService_->HasUserPermission(validity, requiredPermissions, profile)) |
71 | 356 { |
103 | 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 | 359 |
360 // check labels permissions | |
190 | 361 msg = std::string("Testing whether user has the authorized_labels to access '") + uri + "' based on the HTTP header '" + authTokens[i].GetToken().GetKey() + "'"; |
362 | |
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 | 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 | 375 } |
71 | 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 | 382 } |
383 } | |
384 } | |
385 } | |
109 | 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 | 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 | 395 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
396 if (resourceTokensEnabled_ && |
1 | 397 authorizationService_.get() != NULL) |
398 { | |
399 // Parse the resources that are accessed through this URI | |
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 | 403 { |
404 return 0; // Unable to parse this URI | |
405 } | |
406 | |
407 // Loop over all the accessed resources to ensure access is | |
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 | 412 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator |
413 access = accesses.begin(); access != accesses.end(); ++access) | |
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 | 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 | 422 } |
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 | 429 } |
430 | |
431 // By default, forbid access to all the resources | |
432 return 0; | |
433 } | |
434 catch (std::runtime_error& e) | |
435 { | |
436 LOG(ERROR) << e.what(); | |
437 return OrthancPluginErrorCode_Success; // Ignore error | |
438 } | |
439 catch (Orthanc::OrthancException& e) | |
440 { | |
441 LOG(ERROR) << e.What(); | |
442 return OrthancPluginErrorCode_Success; // Ignore error | |
443 } | |
444 catch (...) | |
445 { | |
446 LOG(ERROR) << "Unhandled internal exception"; | |
447 return OrthancPluginErrorCode_Success; // Ignore error | |
448 } | |
449 } | |
450 | |
451 | |
452 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) | |
453 static int32_t FilterHttpRequestsFallback(OrthancPluginHttpMethod method, | |
454 const char *uri, | |
455 const char *ip, | |
456 uint32_t headersCount, | |
457 const char *const *headersKeys, | |
458 const char *const *headersValues) | |
459 { | |
460 // Fallback wrapper function for Orthanc <= 1.2.0, where the GET | |
461 // arguments were not available in the HTTP filters | |
462 return FilterHttpRequests(method, uri, ip, | |
463 headersCount, headersKeys, headersValues, | |
464 0, NULL, NULL); | |
465 } | |
466 #endif | |
467 | |
468 | |
469 static OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
470 OrthancPluginResourceType resourceType, | |
471 const char* resourceId) | |
472 { | |
473 try | |
474 { | |
475 if (authorizationParser_.get() == NULL) | |
476 { | |
71 | 477 return OrthancPluginErrorCode_Success; |
1 | 478 } |
479 | |
480 if (changeType == OrthancPluginChangeType_Deleted) | |
481 { | |
482 switch (resourceType) | |
483 { | |
484 case OrthancPluginResourceType_Patient: | |
485 authorizationParser_->Invalidate(Orthanc::ResourceType_Patient, resourceId); | |
486 break; | |
487 | |
488 case OrthancPluginResourceType_Study: | |
489 authorizationParser_->Invalidate(Orthanc::ResourceType_Study, resourceId); | |
490 break; | |
491 | |
492 case OrthancPluginResourceType_Series: | |
493 authorizationParser_->Invalidate(Orthanc::ResourceType_Series, resourceId); | |
494 break; | |
495 | |
496 case OrthancPluginResourceType_Instance: | |
497 authorizationParser_->Invalidate(Orthanc::ResourceType_Instance, resourceId); | |
498 break; | |
499 | |
500 default: | |
501 break; | |
502 } | |
503 } | |
504 | |
505 return OrthancPluginErrorCode_Success; | |
506 } | |
507 catch (std::runtime_error& e) | |
508 { | |
509 LOG(ERROR) << e.what(); | |
510 return OrthancPluginErrorCode_Success; // Ignore error | |
511 } | |
512 catch (Orthanc::OrthancException& e) | |
513 { | |
514 LOG(ERROR) << e.What(); | |
515 return OrthancPluginErrorCode_Success; // Ignore error | |
516 } | |
517 catch (...) | |
518 { | |
519 LOG(ERROR) << "Unhandled internal exception"; | |
520 return OrthancPluginErrorCode_Success; // Ignore error | |
521 } | |
522 } | |
523 | |
111 | 524 |
525 bool GetUserProfileInternal(OrthancPlugins::IAuthorizationService::UserProfile& profile, const OrthancPluginHttpRequest* request) | |
526 { | |
527 OrthancPlugins::AssociativeArray headers | |
528 (request->headersCount, request->headersKeys, request->headersValues, false); | |
529 | |
530 OrthancPlugins::AssociativeArray getArguments | |
531 (request->getCount, request->getKeys, request->getValues, true); | |
532 | |
533 // Loop over all the authorization tokens stored in the HTTP | |
534 // headers, until finding one that is granted | |
535 for (std::set<OrthancPlugins::Token>::const_iterator | |
536 token = tokens_.begin(); token != tokens_.end(); ++token) | |
537 { | |
538 OrthancPlugins::IAuthorizationService::UserProfile tryProfile; | |
539 | |
540 std::string value; | |
541 | |
542 bool hasValue = false; | |
543 switch (token->GetType()) | |
544 { | |
545 case OrthancPlugins::TokenType_HttpHeader: | |
546 hasValue = headers.GetValue(value, token->GetKey()); | |
547 break; | |
548 | |
549 case OrthancPlugins::TokenType_GetArgument: | |
550 hasValue = getArguments.GetValue(value, token->GetKey()); | |
551 break; | |
552 | |
553 default: | |
554 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
555 } | |
556 | |
557 if (hasValue) | |
558 { | |
559 unsigned int validity; // not used | |
560 if (authorizationService_->GetUserProfile(validity, tryProfile, *token, value)) | |
561 { | |
562 profile = tryProfile; | |
563 return true; | |
564 } | |
565 } | |
566 } | |
567 | |
568 return false; | |
569 } | |
570 | |
571 void AdjustToolsFindQueryLabels(Json::Value& query, const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
572 { | |
573 std::set<std::string> labelsToFind; | |
574 std::string labelsConstraint = "Invalid"; | |
575 | |
576 if (query.isMember("Labels") && query.isMember("LabelsConstraint")) | |
577 { | |
578 Orthanc::SerializationToolbox::ReadSetOfStrings(labelsToFind, query, "Labels"); | |
579 labelsConstraint = Orthanc::SerializationToolbox::ReadString(query, "LabelsConstraint"); | |
580 } | |
581 else if (query.isMember("Labels") || query.isMember("LabelsConstraint")) | |
582 { | |
114 | 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 | 584 } |
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 | 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 | 591 { |
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 | 594 { // the user does not have access to all labels -> transform the tools/find body |
595 | |
596 if (labelsToFind.size() == 0) | |
597 { | |
598 if (profile.authorizedLabels.size() > 0) | |
599 { | |
114 | 600 query.removeMember("Labels"); |
111 | 601 Orthanc::SerializationToolbox::WriteSetOfStrings(query, profile.authorizedLabels, "Labels"); |
602 query["LabelsConstraint"] = "Any"; | |
603 } | |
604 } | |
605 else if (labelsConstraint == "All") | |
606 { | |
607 if (profile.authorizedLabels.size() > 0) | |
608 { | |
609 if (!Orthanc::Toolbox::IsSetInSet(labelsToFind, profile.authorizedLabels)) | |
610 { | |
114 | 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 | 612 } |
613 } | |
614 } | |
615 else if (labelsConstraint == "Any") | |
616 { | |
617 if (profile.authorizedLabels.size() > 0) | |
618 { | |
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 | 621 |
622 if (newLabelsToFind.size() == 0) | |
623 { | |
114 | 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 | 625 } |
626 | |
627 query.removeMember("Labels"); | |
628 Orthanc::SerializationToolbox::WriteSetOfStrings(query, newLabelsToFind, "Labels"); | |
629 } | |
630 } | |
631 else if (labelsConstraint == "None") | |
632 { | |
633 if (profile.authorizedLabels.size() > 0) | |
634 { | |
114 | 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 | 636 } |
637 } | |
638 } | |
639 } | |
640 } | |
641 | |
118 | 642 bool GetStudyInstanceUIDFromQuery(std::string& studyInstanceUID, const Json::Value& body) |
643 { | |
644 | |
645 if (!body.isMember("Query")) | |
646 { | |
647 return false; | |
648 } | |
649 | |
650 if (body["Query"].isMember("StudyInstanceUID")) | |
651 { | |
652 studyInstanceUID = body["Query"]["StudyInstanceUID"].asString(); | |
653 } | |
654 else if (body["Query"].isMember("0020,000d")) | |
655 { | |
656 studyInstanceUID = body["Query"]["0020,000d"].asString(); | |
657 } | |
658 else if (body["Query"].isMember("0020,000D")) | |
659 { | |
660 studyInstanceUID = body["Query"]["0020,000D"].asString(); | |
661 } | |
662 else if (body["Query"].isMember("0020000D")) | |
663 { | |
664 studyInstanceUID = body["Query"]["0020000D"].asString(); | |
665 } | |
666 else | |
667 { | |
668 return false; | |
669 } | |
670 | |
671 return true; | |
672 } | |
673 | |
202
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
674 void GetStudyOrthancIdFromStudyInstanceUID(std::vector<std::string>& studyOrthancIds, const std::string& studyInstanceUID) |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
675 { |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
676 studyOrthancIds.clear(); |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
677 Json::Value response; |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
678 if (OrthancPlugins::RestApiPost(response, "/tools/lookup", studyInstanceUID, false)) |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
679 { |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
680 for (Json::ArrayIndex i = 0; i < response.size(); ++i) |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
681 { |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
682 if (response[i]["Type"] == "Study") |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
683 { |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
684 studyOrthancIds.push_back(response[i]["ID"].asString()); |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
685 } |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
686 } |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
687 } |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
688 } |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
689 |
111 | 690 void ToolsFind(OrthancPluginRestOutput* output, |
691 const char* /*url*/, | |
692 const OrthancPluginHttpRequest* request) | |
693 { | |
694 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
695 | |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
696 try |
111 | 697 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
698 if (request->method != OrthancPluginHttpMethod_Post) |
111 | 699 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
700 OrthancPluginSendMethodNotAllowed(context, output, "POST"); |
111 | 701 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
702 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
703 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
704 // The filtering to this route is performed by this plugin as it is done for any other route before we get here. |
111 | 705 |
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
|
706 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
|
707 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
|
708 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
709 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
|
710 } |
111 | 711 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
712 // 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
|
713 OrthancPlugins::IAuthorizationService::UserProfile profile; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
714 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
|
715 { |
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
|
716 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
|
717 |
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
|
718 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
|
719 { |
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
|
720 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
|
721 } |
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
|
722 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
|
723 { |
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 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
|
725 } |
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 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
|
727 { |
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
|
728 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
|
729 |
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
|
730 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
|
731 { |
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
|
732 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
|
733 { |
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
|
734 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
|
735 } |
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
|
736 |
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
|
737 // since this is a series/instance find, make sure the user has access to the parent study |
202
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
738 std::vector<std::string> studyOrthancIds; |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
739 GetStudyOrthancIdFromStudyInstanceUID(studyOrthancIds, studyInstanceUID); |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
740 |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
741 if (studyOrthancIds.size() != 1) |
163 | 742 { |
743 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"); | |
744 } | |
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
|
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 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
|
747 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
|
748 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
|
749 |
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
|
750 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
|
751 { |
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
|
752 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
|
753 } |
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
|
754 |
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 (!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
|
756 { |
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
|
757 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
|
758 } |
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
|
759 } |
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
|
760 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
761 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
762 else // anonymous user profile or resource token |
111 | 763 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
764 std::string studyInstanceUID; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
765 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
766 // 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
|
767 // -> 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
|
768 // 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
|
769 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
|
770 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
771 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
|
772 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
773 |
202
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
774 std::vector<std::string> studyOrthancIds; |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
775 GetStudyOrthancIdFromStudyInstanceUID(studyOrthancIds, studyInstanceUID); |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
776 |
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
777 if (studyOrthancIds.size() != 1) |
163 | 778 { |
779 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"); | |
780 } | |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
781 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
782 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
|
783 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
|
784 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
785 std::set<std::string> labels; |
202
3c56c3f0059a
Fix forbidden access when the PatientID and StudyInstanceUID are identical
Alain Mazy <am@orthanc.team>
parents:
199
diff
changeset
|
786 OrthancPlugins::AccessedResource accessedResource(Orthanc::ResourceType_Study, studyOrthancIds[0], studyInstanceUID, labels); |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
787 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
|
788 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
789 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
|
790 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
791 |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
792 } |
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
793 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
794 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
|
795 |
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
|
796 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
|
797 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
798 OrthancPlugins::AnswerJson(result, output); |
111 | 799 } |
800 | |
801 } | |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
802 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
803 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
804 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
|
805 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
806 // 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
|
807 if (e.GetErrorCode() == Orthanc::ErrorCode_ForbiddenAccess && !OrthancPlugins::CheckMinimalOrthancVersion(1, 12, 2)) |
111 | 808 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
809 SendForbiddenError(e.GetDetails(), output); |
111 | 810 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
811 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
812 { |
190 | 813 throw; |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
814 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
815 } |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
816 |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
817 } |
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 void ToolsLabels(OrthancPluginRestOutput* output, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
820 const char* /*url*/, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
821 const OrthancPluginHttpRequest* request) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
822 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
823 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
824 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
825 try |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
826 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
827 if (request->method != OrthancPluginHttpMethod_Get) |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
828 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
829 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
830 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
831 else |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
832 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
833 // 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
|
834 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
835 // 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
|
836 OrthancPlugins::IAuthorizationService::UserProfile profile; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
837 if (GetUserProfileInternal(profile, request)) |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
838 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
839 if (!HasAccessToSomeLabels(profile)) |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
840 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
841 Json::Value emptyLabels; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
842 OrthancPlugins::AnswerJson(emptyLabels, output); |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
843 return; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
844 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
845 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
846 Json::Value jsonLabels; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
847 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
|
848 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
849 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
|
850 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
|
851 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
852 if (!HasAccessToAllLabels(profile)) |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
853 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
854 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
|
855 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
856 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
|
857 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
|
858 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
859 OrthancPlugins::AnswerJson(jsonLabels, output); |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
860 } |
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 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
863 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
864 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
865 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
|
866 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
867 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
868 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
869 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
|
870 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
871 // 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
|
872 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
|
873 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
874 SendForbiddenError(e.GetDetails(), output); |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
875 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
876 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
877 { |
190 | 878 throw; |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
879 } |
111 | 880 } |
881 } | |
882 | |
883 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
884 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
|
885 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
|
886 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
|
887 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
888 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
|
889 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
890 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
|
891 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
892 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
|
893 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
894 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
895 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
896 // 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
|
897 // 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
|
898 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
899 // 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
|
900 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
|
901 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
|
902 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
903 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
|
904 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
905 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
906 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
907 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
|
908 } |
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 // 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
|
911 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
|
912 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
|
913 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
914 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
|
915 } |
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 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
|
918 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
|
919 std::string expirationDateString; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
920 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
|
921 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
922 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
|
923 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
924 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
|
925 } |
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 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
|
928 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
929 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
|
930 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
|
931 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
932 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
|
933 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
934 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
|
935 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
936 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
937 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
|
938 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
939 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
|
940 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
941 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
942 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
|
943 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
944 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
|
945 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
946 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
947 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
|
948 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
|
949 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
950 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
951 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
|
952 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
953 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
|
954 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
955 |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
956 if (body.isMember("ValidityDuration")) |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
957 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
958 validityDuration = body["ValidityDuration"].asUInt64(); |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
959 } |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
960 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
961 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
|
962 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
|
963 tokenType, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
964 id, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
965 resources, |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
966 expirationDateString, |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
967 validityDuration)) |
72
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 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
|
970 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
|
971 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
972 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
|
973 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
974 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
|
975 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
976 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
977 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
978 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
|
979 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
980 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
981 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
|
982 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
983 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
984 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
985 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
986 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
987 |
74 | 988 void DecodeToken(OrthancPluginRestOutput* output, |
989 const char* /*url*/, | |
990 const OrthancPluginHttpRequest* request) | |
991 { | |
992 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
993 | |
994 if (request->method != OrthancPluginHttpMethod_Post) | |
995 { | |
996 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
997 } | |
998 else | |
999 { | |
1000 // convert from Orthanc flavored API to WebService API | |
1001 Json::Value body; | |
1002 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize)) | |
1003 { | |
1004 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); | |
1005 } | |
1006 | |
1007 OrthancPlugins::IAuthorizationService::DecodedToken decodedToken; | |
1008 if (authorizationService_->DecodeToken(decodedToken, | |
1009 body["TokenKey"].asString(), | |
1010 body["TokenValue"].asString())) | |
1011 { | |
1012 Json::Value decodedJsonToken; | |
1013 | |
1014 if (!decodedToken.redirectUrl.empty()) | |
1015 { | |
1016 decodedJsonToken["RedirectUrl"] = decodedToken.redirectUrl; | |
1017 } | |
1018 | |
1019 if (!decodedToken.errorCode.empty()) | |
1020 { | |
1021 decodedJsonToken["ErrorCode"] = decodedToken.errorCode; | |
1022 } | |
1023 | |
1024 if (!decodedToken.tokenType.empty()) | |
1025 { | |
1026 decodedJsonToken["TokenType"] = decodedToken.tokenType; | |
1027 } | |
1028 | |
1029 OrthancPlugins::AnswerJson(decodedJsonToken, output); | |
1030 } | |
1031 } | |
1032 } | |
1033 | |
111 | 1034 |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1035 void GetUserProfile(OrthancPluginRestOutput* output, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1036 const char* /*url*/, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1037 const OrthancPluginHttpRequest* request) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1038 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1039 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1040 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1041 if (request->method != OrthancPluginHttpMethod_Get) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1042 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1043 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1044 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1045 else |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1046 { |
111 | 1047 OrthancPlugins::IAuthorizationService::UserProfile profile; |
1048 if (GetUserProfileInternal(profile, request)) | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1049 { |
111 | 1050 Json::Value jsonProfile; |
1051 jsonProfile["name"] = profile.name; | |
1052 jsonProfile["permissions"] = Json::arrayValue; | |
1053 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
|
1054 { |
111 | 1055 jsonProfile["permissions"].append(*it); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1056 } |
111 | 1057 for (std::set<std::string>::const_iterator it = profile.authorizedLabels.begin(); it != profile.authorizedLabels.end(); ++it) |
1058 { | |
1059 jsonProfile["authorized-labels"].append(*it); | |
1060 } | |
109 | 1061 |
111 | 1062 OrthancPlugins::AnswerJson(jsonProfile, output); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1063 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1064 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1065 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1066 |
194
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 void AuthSettingsRoles(OrthancPluginRestOutput* output, |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1069 const char* /*url*/, |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1070 const OrthancPluginHttpRequest* request) |
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 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1073 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1074 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
|
1075 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1076 OrthancPlugins::AnswerHttpError(404, output); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1077 return; |
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 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1080 if (request->method == OrthancPluginHttpMethod_Get) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1081 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1082 Json::Value roles; |
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 (!authorizationService_->GetSettingsRoles(roles)) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1085 { |
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
|
1086 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
|
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 OrthancPlugins::AnswerJson(roles, output); |
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 else if (request->method == OrthancPluginHttpMethod_Put) |
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 Json::Value roles; |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1094 Json::Value response; |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1095 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1096 if (!OrthancPlugins::ReadJson(roles, request->body, request->bodySize)) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1097 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1098 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
|
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 if (!authorizationService_->UpdateSettingsRoles(response, roles)) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1102 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1103 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
|
1104 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1105 OrthancPlugins::AnswerJson(response, output); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1106 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1107 else |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1108 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1109 OrthancPluginSendMethodNotAllowed(context, output, "GET,PUT"); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1110 } |
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 |
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 void GetPermissionList(OrthancPluginRestOutput* output, |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1115 const char* /*url*/, |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1116 const OrthancPluginHttpRequest* request) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1117 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1118 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1119 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1120 if (request->method != OrthancPluginHttpMethod_Get) |
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 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1123 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1124 else |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1125 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1126 std::set<std::string> permissionsList = permissionParser_->GetPermissionsList(); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1127 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1128 Json::Value response = Json::arrayValue; |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1129 Orthanc::SerializationToolbox::WriteSetOfStrings(response, permissionsList); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1130 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1131 OrthancPlugins::AnswerJson(response, output); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1132 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1133 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1134 |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1135 |
71 | 1136 void MergeJson(Json::Value &a, const Json::Value &b) { |
1137 | |
1138 if (!a.isObject() || !b.isObject()) | |
1139 { | |
1140 return; | |
1141 } | |
1142 | |
1143 Json::Value::Members members = b.getMemberNames(); | |
1144 | |
1145 for (size_t i = 0; i < members.size(); i++) | |
1146 { | |
1147 std::string key = members[i]; | |
1148 | |
1149 if (!a[key].isNull() && a[key].type() == Json::objectValue && b[key].type() == Json::objectValue) | |
1150 { | |
1151 MergeJson(a[key], b[key]); | |
1152 } | |
1153 else | |
1154 { | |
1155 a[key] = b[key]; | |
1156 } | |
1157 } | |
1158 } | |
1159 | |
1 | 1160 |
1161 extern "C" | |
1162 { | |
1163 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
1164 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1165 OrthancPlugins::SetGlobalContext(context); |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1166 OrthancPluginLogWarning(context, "Initializing the authorization plugin"); |
1 | 1167 |
1168 /* 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
|
1169 if (OrthancPluginCheckVersion(context) == 0) |
1 | 1170 { |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1171 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
1 | 1172 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
1173 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
1174 return -1; | |
1175 } | |
1176 | |
164 | 1177 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4) |
1178 Orthanc::Logging::InitializePluginContext(context, ORTHANC_PLUGIN_NAME); | |
1179 #elif ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) | |
32 | 1180 Orthanc::Logging::InitializePluginContext(context); |
33
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1181 #else |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1182 Orthanc::Logging::Initialize(context); |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1183 #endif |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1184 |
156
43b77aa34468
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
153
diff
changeset
|
1185 OrthancPlugins::SetDescription(ORTHANC_PLUGIN_NAME, "Advanced authorization plugin for Orthanc."); |
1 | 1186 |
1187 try | |
1188 { | |
190 | 1189 static const char* const PLUGIN_SECTION = "Authorization"; |
71 | 1190 |
1191 OrthancPlugins::OrthancConfiguration orthancFullConfiguration; | |
1192 | |
1193 // read default configuration | |
1194 std::string defaultConfigurationFileContent; | |
1195 Orthanc::EmbeddedResources::GetFileResource(defaultConfigurationFileContent, Orthanc::EmbeddedResources::DEFAULT_CONFIGURATION); | |
1196 Json::Value pluginJsonDefaultConfiguration; | |
1197 OrthancPlugins::ReadJsonWithoutComments(pluginJsonDefaultConfiguration, defaultConfigurationFileContent); | |
1198 Json::Value pluginJsonConfiguration = pluginJsonDefaultConfiguration[PLUGIN_SECTION]; | |
1 | 1199 |
71 | 1200 OrthancPlugins::OrthancConfiguration pluginProvidedConfiguration; |
1201 | |
1202 if (orthancFullConfiguration.IsSection(PLUGIN_SECTION)) | |
1 | 1203 { |
71 | 1204 // get the configuration provided by the user |
1205 orthancFullConfiguration.GetSection(pluginProvidedConfiguration, PLUGIN_SECTION); | |
1206 | |
1207 // merge it with the default configuration. This is a way to apply the all default values in a single step | |
1208 MergeJson(pluginJsonConfiguration, pluginProvidedConfiguration.GetJson()); | |
1209 | |
1210 // recreate a OrthancConfiguration object from the merged configuration | |
1211 OrthancPlugins::OrthancConfiguration pluginConfiguration(pluginJsonConfiguration, PLUGIN_SECTION); | |
1 | 1212 |
1213 // TODO - The size of the caches is set to 10,000 items. Maybe add a configuration option? | |
1214 OrthancPlugins::MemoryCache::Factory factory(10000); | |
1215 | |
71 | 1216 std::string dicomWebRoot = "/dicom-web/"; |
1217 std::string oe2Root = "/ui/"; | |
1 | 1218 |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1219 bool hasBasicAuthEnabled = orthancFullConfiguration.GetBooleanValue("AuthenticationEnabled", "true"); |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1220 |
71 | 1221 if (orthancFullConfiguration.IsSection("DicomWeb")) |
1222 { | |
1223 OrthancPlugins::OrthancConfiguration dicomWeb; | |
1224 dicomWeb.GetSection(orthancFullConfiguration, "DicomWeb"); | |
1225 dicomWebRoot = dicomWeb.GetStringValue("Root", "/dicom-web/"); | |
1226 } | |
1 | 1227 |
71 | 1228 if (orthancFullConfiguration.IsSection("OrthancExplorer2")) |
1229 { | |
1230 OrthancPlugins::OrthancConfiguration oe2; | |
1231 oe2.GetSection(orthancFullConfiguration, "OrthancExplorer2"); | |
1232 oe2Root = oe2.GetStringValue("Root", "/ui/"); | |
1 | 1233 } |
1234 | |
1235 std::list<std::string> tmp; | |
1236 | |
71 | 1237 pluginConfiguration.LookupListOfStrings(tmp, "TokenHttpHeaders", true); |
1 | 1238 for (std::list<std::string>::const_iterator |
1239 it = tmp.begin(); it != tmp.end(); ++it) | |
1240 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1241 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, *it)); |
1 | 1242 } |
1243 | |
71 | 1244 pluginConfiguration.LookupListOfStrings(tmp, "TokenGetArguments", true); |
1 | 1245 |
8
4362026afddf
orthanc 1.2.1 renamed as 1.3.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
1246 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 3, 0) |
1 | 1247 for (std::list<std::string>::const_iterator |
1248 it = tmp.begin(); it != tmp.end(); ++it) | |
1249 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1250 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it)); |
1 | 1251 } |
1252 #else | |
1253 if (!tmp.empty()) | |
1254 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1255 throw Orthanc::OrthancException( |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1256 Orthanc::ErrorCode_Plugin, |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1257 "The option \"TokenGetArguments\" of the authorization plugin " |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1258 "is only valid if compiled against Orthanc >= 1.3.0" |
1 | 1259 } |
1260 #endif | |
1261 | |
71 | 1262 pluginConfiguration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false); |
1263 pluginConfiguration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false); | |
1 | 1264 |
74 | 1265 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
|
1266 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
|
1267 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
|
1268 std::string urlUserProfile; |
194
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1269 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
|
1270 std::string urlRoot; |
1 | 1271 |
190 | 1272 static const char* const WEB_SERVICE_ROOT = "WebServiceRootUrl"; |
1273 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1274 if (pluginConfiguration.LookupStringValue(urlRoot, WEB_SERVICE_ROOT)) |
71 | 1275 { |
74 | 1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 urlSettingsRole = Orthanc::Toolbox::JoinUri(urlRoot, "/settings/roles"); |
71 | 1281 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1282 else |
71 | 1283 { |
190 | 1284 static const char* const WEB_SERVICE_TOKEN_DECODER = "WebServiceTokenDecoderUrl"; |
1285 static const char* const WEB_SERVICE_TOKEN_VALIDATION = "WebServiceTokenValidationUrl"; | |
1286 static const char* const WEB_SERVICE_TOKEN_CREATION_BASE = "WebServiceTokenCreationBaseUrl"; | |
1287 static const char* const WEB_SERVICE_USER_PROFILE = "WebServiceUserProfileUrl"; | |
195 | 1288 static const char* const WEB_SERVICE_SETTINGS_ROLES = "WebServiceSettingsRolesUrl"; |
190 | 1289 static const char* const WEB_SERVICE_TOKEN_VALIDATION_LEGACY = "WebService"; |
1290 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1291 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION); |
74 | 1292 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
|
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 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1295 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
|
1296 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1297 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1298 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
|
1299 pluginConfiguration.LookupStringValue(urlUserProfile, WEB_SERVICE_USER_PROFILE); |
194
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1300 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
|
1301 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1302 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1303 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
|
1304 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1305 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
|
1306 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1307 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
|
1308 resourceTokensEnabled_ = true; |
71 | 1309 } |
1310 else | |
1311 { | |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1312 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
|
1313 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
|
1314 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1315 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1316 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
|
1317 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1318 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
|
1319 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
|
1320 |
190 | 1321 static const char* const PERMISSIONS = "Permissions"; |
71 | 1322 if (!pluginConfiguration.GetJson().isMember(PERMISSIONS)) |
1323 { | |
1324 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
|
1325 "\" option since you have defined the \"" + std::string(WEB_SERVICE_ROOT) + "\" option"); |
71 | 1326 } |
1327 permissionParser_.reset | |
1328 (new OrthancPlugins::PermissionParser(dicomWebRoot, oe2Root)); | |
1329 | |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1330 permissionParser_->Add(pluginConfiguration.GetJson()[PERMISSIONS], authorizationParser_.get()); |
71 | 1331 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1332 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1333 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1334 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
|
1335 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
|
1336 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1337 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1338 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
|
1339 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1340 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
|
1341 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1342 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1343 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1344 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
|
1345 } |
71 | 1346 |
194
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1347 if (!urlSettingsRole.empty()) |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1348 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1349 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
|
1350 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1351 else |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1352 { |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1353 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
|
1354 } |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1355 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1356 if (!resourceTokensEnabled_ && permissionParser_.get() == NULL) |
71 | 1357 { |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1358 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1359 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1360 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
|
1361 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1362 else |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1363 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1364 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
|
1365 } |
1 | 1366 } |
1367 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1368 std::set<std::string> standardConfigurations; |
71 | 1369 if (pluginConfiguration.LookupSetOfStrings(standardConfigurations, "StandardConfigurations", false)) |
58
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 if (standardConfigurations.find("osimis-web-viewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1372 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1373 uncheckedFolders_.push_back("/osimis-viewer/app/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1374 uncheckedFolders_.push_back("/osimis-viewer/languages/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1375 uncheckedResources_.insert("/osimis-viewer/config.js"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1376 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1377 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
|
1378 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
|
1379 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1380 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1381 if (standardConfigurations.find("stone-webviewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1382 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1383 uncheckedFolders_.push_back("/stone-webviewer/"); |
65 | 1384 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
|
1385 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1386 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1387 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1388 |
65 | 1389 if (standardConfigurations.find("orthanc-explorer-2") != standardConfigurations.end()) |
1390 { | |
1391 uncheckedFolders_.push_back("/ui/app/"); | |
74 | 1392 uncheckedFolders_.push_back("/ui/landing/"); |
76 | 1393 uncheckedResources_.insert("/"); // for the redirect to /ui/app/ |
66 | 1394 uncheckedResources_.insert("/ui/api/pre-login-configuration"); // for the UI to know, i.e. if Keycloak is enabled or not |
71 | 1395 uncheckedResources_.insert("/ui/api/configuration"); |
120 | 1396 uncheckedResources_.insert("/auth/user/profile"); |
65 | 1397 |
1398 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); // for basic-auth | |
1399 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
|
1400 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in OE2 |
65 | 1401 } |
1402 | |
102 | 1403 if (standardConfigurations.find("ohif") != standardConfigurations.end()) |
1404 { | |
1405 uncheckedFolders_.push_back("/ohif/"); | |
1406 } | |
1407 | |
58
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 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1410 std::string checkedLevelString; |
71 | 1411 if (pluginConfiguration.LookupStringValue(checkedLevelString, "CheckedLevel")) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1412 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1413 OrthancPlugins::AccessLevel checkedLevel = OrthancPlugins::StringToAccessLevel(checkedLevelString); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1414 if (checkedLevel == OrthancPlugins::AccessLevel_Instance) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1415 { |
113 | 1416 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1417 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1418 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1419 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1420 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1421 else if (checkedLevel == OrthancPlugins::AccessLevel_Series) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1422 { |
113 | 1423 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1424 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1425 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1426 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1427 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1428 else if (checkedLevel == OrthancPlugins::AccessLevel_Study) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1429 { |
113 | 1430 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1431 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1432 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1433 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1434 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1435 else if (checkedLevel == OrthancPlugins::AccessLevel_Patient) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1436 { |
113 | 1437 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1438 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1439 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1440 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
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 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1443 |
71 | 1444 if (pluginConfiguration.LookupListOfStrings(tmp, "UncheckedLevels", false)) |
1 | 1445 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1446 if (uncheckedLevels_.size() == 0) |
1 | 1447 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1448 for (std::list<std::string>::const_iterator |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1449 it = tmp.begin(); it != tmp.end(); ++it) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1450 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1451 uncheckedLevels_.insert(OrthancPlugins::StringToAccessLevel(*it)); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1452 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1453 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1454 else |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1455 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1456 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
|
1457 return -1; |
1 | 1458 } |
1459 } | |
1460 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1461 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
|
1462 urlTokenCreationBase, |
74 | 1463 urlUserProfile, |
194
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1464 urlTokenDecoder, |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1465 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
|
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 std::string webServiceIdentifier; |
71 | 1468 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
|
1469 { |
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->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
|
1471 } |
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
|
1472 |
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
|
1473 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
|
1474 std::string webServicePassword; |
71 | 1475 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
|
1476 { |
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
|
1477 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
|
1478 } |
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
|
1479 |
1 | 1480 authorizationService_.reset |
1481 (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
|
1482 (webService.release(), factory)); |
1 | 1483 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1484 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
|
1485 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1486 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
|
1487 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1488 |
74 | 1489 if (!urlTokenDecoder.empty()) |
1490 { | |
1491 OrthancPlugins::RegisterRestCallback<DecodeToken>("/auth/tokens/decode", true); | |
1492 } | |
1493 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1494 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
|
1495 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1496 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
|
1497 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
|
1498 OrthancPlugins::RegisterRestCallback<ToolsLabels>("/tools/labels", true); |
194
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1499 OrthancPlugins::RegisterRestCallback<AuthSettingsRoles>("/auth/settings/roles", true); |
85859ec3aa7e
added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents:
188
diff
changeset
|
1500 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
|
1501 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1502 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1503 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
|
1504 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1505 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
|
1506 } |
74 | 1507 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1508 if (resourceTokensEnabled_ || userTokensEnabled_) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1509 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1510 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1511 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1512 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
|
1513 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1514 |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1515 LOG(WARNING) << "Authorization plugin: Registering Incoming HTTP Request Filter"; |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1516 |
1 | 1517 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1518 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests); |
1 | 1519 #else |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1520 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback); |
1 | 1521 #endif |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1522 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1523 |
1 | 1524 } |
1525 else | |
1526 { | |
71 | 1527 LOG(WARNING) << "No section \"" << PLUGIN_SECTION << "\" in the configuration file, " |
1 | 1528 << "the authorization plugin is disabled"; |
1529 } | |
1530 } | |
1531 catch (Orthanc::OrthancException& e) | |
1532 { | |
1533 LOG(ERROR) << e.What(); | |
1534 return -1; | |
1535 } | |
1536 | |
1537 return 0; | |
1538 } | |
1539 | |
1540 | |
1541 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
1542 { | |
1543 authorizationParser_.reset(NULL); | |
1544 } | |
1545 | |
1546 | |
1547 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
1548 { | |
156
43b77aa34468
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
153
diff
changeset
|
1549 return ORTHANC_PLUGIN_NAME; |
1 | 1550 } |
1551 | |
1552 | |
1553 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
1554 { | |
22
c44013681a51
now using the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
1555 return ORTHANC_PLUGIN_VERSION; |
1 | 1556 } |
1557 } |