Mercurial > hg > orthanc-authorization
annotate Plugin/Plugin.cpp @ 188:c4b908970ae4
updated copyright, as Orthanc Team now replaces Osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 May 2024 21:59:01 +0200 |
parents | 3c99bb6fd309 |
children | de232f9b3a60 85859ec3aa7e |
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, |
113 | 152 const OrthancPlugins::AssociativeArray& getArguments, |
153 const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
154 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
155 granted = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
156 |
113 | 157 if (HasAccessToAllLabels(profile)) |
158 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
159 granted = true; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
160 return true; // we could check labels |
113 | 161 } |
162 | |
163 if (authorizationParser_.get() != NULL && | |
164 authorizationService_.get() != NULL) | |
165 { | |
166 // Parse the resources that are accessed through this URI | |
167 OrthancPlugins::IAuthorizationParser::AccessedResources accesses; | |
168 | |
169 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) | |
170 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
171 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
|
172 } |
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 if (authorizationParser_->IsListOfResources(uri)) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
175 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
176 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
|
177 return true; // we could check labels |
113 | 178 } |
179 | |
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
|
180 return HasAuthorizedLabelsForResource(granted, accesses, profile); |
113 | 181 } |
182 | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
183 // 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
|
184 return false; // we could not check labels |
113 | 185 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
186 |
116
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
187 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
188 static void GetAuthTokens(std::vector<TokenAndValue>& authTokens, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
189 uint32_t headersCount, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
190 const char *const *headersKeys, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
191 const char *const *headersValues, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
192 uint32_t getArgumentsCount, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
193 const char *const *getArgumentsKeys, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
194 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
|
195 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
196 // 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
|
197 //////////////////////////////////////////////////////////////// |
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 OrthancPlugins::AssociativeArray headers(headersCount, headersKeys, headersValues, false); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
200 OrthancPlugins::AssociativeArray getArguments(getArgumentsCount, getArgumentsKeys, getArgumentsValues, true); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
201 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
202 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
|
203 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
204 std::string value; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
205 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
206 bool hasValue = false; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
207 switch (token->GetType()) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
208 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
209 case OrthancPlugins::TokenType_HttpHeader: |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
210 hasValue = headers.GetValue(value, token->GetKey()); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
211 break; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
212 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
213 case OrthancPlugins::TokenType_GetArgument: |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
214 hasValue = getArguments.GetValue(value, token->GetKey()); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
215 break; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
216 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
217 default: |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
218 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
219 } |
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 if (hasValue) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
222 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
223 authTokens.push_back(TokenAndValue(*token, value)); |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
224 } |
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 static bool IsResourceAccessGranted(const std::vector<TokenAndValue>& authTokens, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
229 OrthancPluginHttpMethod method, |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
230 const OrthancPlugins::AccessedResource& access) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
231 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
232 unsigned int validity; // ignored |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
233 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
234 // Ignored the access levels that are unchecked |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
235 // (cf. "UncheckedLevels" option) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
236 if (uncheckedLevels_.find(access.GetLevel()) == uncheckedLevels_.end()) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
237 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
238 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
|
239 LOG(INFO) << msg; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
240 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
241 bool granted = false; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
242 |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
243 if (authTokens.empty()) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
244 { |
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 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
252 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
|
253 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
254 granted = true; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
255 break; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
256 } |
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 if (!granted) |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
261 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
262 LOG(INFO) << msg << " -> not granted"; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
263 return false; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
264 } |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
265 else |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
266 { |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
267 LOG(INFO) << msg << " -> granted"; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
268 return true; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
269 } |
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 return false; |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
273 } |
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
274 |
1 | 275 static int32_t FilterHttpRequests(OrthancPluginHttpMethod method, |
276 const char *uri, | |
277 const char *ip, | |
278 uint32_t headersCount, | |
279 const char *const *headersKeys, | |
280 const char *const *headersValues, | |
281 uint32_t getArgumentsCount, | |
282 const char *const *getArgumentsKeys, | |
283 const char *const *getArgumentsValues) | |
284 { | |
285 try | |
286 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
287 unsigned int validity; // ignored |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
288 |
109 | 289 // Allow GET accesses to unchecked resources/folders (usually static resources) |
290 //////////////////////////////////////////////////////////////// | |
291 | |
1 | 292 if (method == OrthancPluginHttpMethod_Get) |
293 { | |
294 if (uncheckedResources_.find(uri) != uncheckedResources_.end()) | |
295 { | |
296 return 1; | |
297 } | |
298 | |
299 for (std::list<std::string>::const_iterator | |
300 it = uncheckedFolders_.begin(); it != uncheckedFolders_.end(); ++it) | |
301 { | |
302 if (Orthanc::Toolbox::StartsWith(uri, *it)) | |
303 { | |
304 return 1; | |
305 } | |
306 } | |
307 } | |
308 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
309 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
|
310 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
|
311 |
116
89eddd4b2f6a
tested resource token for WADO-RS
Alain Mazy <am@osimis.io>
parents:
115
diff
changeset
|
312 OrthancPlugins::AssociativeArray getArguments(getArgumentsCount, getArgumentsKeys, getArgumentsValues, true); |
71 | 313 |
109 | 314 // Based on the tokens, check if the user has access based on its permissions and the mapping between urls and permissions |
315 //////////////////////////////////////////////////////////////// | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
316 bool hasUserRequiredPermissions = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
317 bool hasAuthorizedLabelsForResource = false; |
109 | 318 |
71 | 319 if (permissionParser_.get() != NULL && |
320 authorizationService_.get() != NULL) | |
321 { | |
322 std::set<std::string> requiredPermissions; | |
323 std::string matchedPattern; | |
324 if (permissionParser_->Parse(requiredPermissions, matchedPattern, method, uri)) | |
325 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
326 if (authTokens.empty()) |
71 | 327 { |
103 | 328 std::string msg = std::string("Testing whether anonymous user has any of the required permissions '") + JoinStrings(requiredPermissions) + "'"; |
113 | 329 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
330 LOG(INFO) << msg; |
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 | |
354 if (authorizationService_->HasUserPermission(validity, requiredPermissions, profile)) | |
71 | 355 { |
103 | 356 LOG(INFO) << msg << " -> granted"; |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
357 hasUserRequiredPermissions = true; |
113 | 358 |
359 // check labels permissions | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
360 std::string msg = std::string("Testing whether user has the authorized_labels to access '") + uri + "' based on the HTTP header '" + authTokens[i].GetToken().GetKey() + "'"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
361 if (CheckAuthorizedLabelsForResource(hasAuthorizedLabelsForResource, uri, getArguments, profile)) |
113 | 362 { |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
363 if (hasAuthorizedLabelsForResource) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
364 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
365 LOG(INFO) << msg << " -> granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
366 } |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
367 else |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
368 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
369 LOG(INFO) << msg << " -> not granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
370 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
|
371 } |
113 | 372 } |
71 | 373 } |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
374 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
375 { |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
376 LOG(INFO) << msg << " -> not granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
377 hasUserRequiredPermissions = false; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
378 } |
71 | 379 } |
380 } | |
381 } | |
382 } | |
109 | 383 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
384 // 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
|
385 if (hasUserRequiredPermissions) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
386 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
387 return 1; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
388 } |
109 | 389 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
390 // 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
|
391 //////////////////////////////////////////////////////////////// |
109 | 392 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
393 if (resourceTokensEnabled_ && |
1 | 394 authorizationService_.get() != NULL) |
395 { | |
396 // Parse the resources that are accessed through this URI | |
397 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
|
398 |
57
55539d564f4f
added support for /dicom-web/series? & /dicom-web/instances?
Alain Mazy <am@osimis.io>
parents:
56
diff
changeset
|
399 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) |
1 | 400 { |
401 return 0; // Unable to parse this URI | |
402 } | |
403 | |
404 // Loop over all the accessed resources to ensure access is | |
405 // 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
|
406 int checkedResources = 0; |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
407 int grantedResources = 0; |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
408 |
1 | 409 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator |
410 access = accesses.begin(); access != accesses.end(); ++access) | |
411 { | |
138
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
412 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end()) |
1 | 413 { |
138
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
414 checkedResources++; |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
415 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
|
416 { |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
417 grantedResources++; |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
418 } |
1 | 419 } |
420 } | |
138
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
421 |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
422 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
|
423 { |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
424 return 1; |
f448e8626f1a
Now handling new GET /tools/create-archive and sibling routes
Alain Mazy <am@osimis.io>
parents:
126
diff
changeset
|
425 } |
1 | 426 } |
427 | |
428 // By default, forbid access to all the resources | |
429 return 0; | |
430 } | |
431 catch (std::runtime_error& e) | |
432 { | |
433 LOG(ERROR) << e.what(); | |
434 return OrthancPluginErrorCode_Success; // Ignore error | |
435 } | |
436 catch (Orthanc::OrthancException& e) | |
437 { | |
438 LOG(ERROR) << e.What(); | |
439 return OrthancPluginErrorCode_Success; // Ignore error | |
440 } | |
441 catch (...) | |
442 { | |
443 LOG(ERROR) << "Unhandled internal exception"; | |
444 return OrthancPluginErrorCode_Success; // Ignore error | |
445 } | |
446 } | |
447 | |
448 | |
449 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) | |
450 static int32_t FilterHttpRequestsFallback(OrthancPluginHttpMethod method, | |
451 const char *uri, | |
452 const char *ip, | |
453 uint32_t headersCount, | |
454 const char *const *headersKeys, | |
455 const char *const *headersValues) | |
456 { | |
457 // Fallback wrapper function for Orthanc <= 1.2.0, where the GET | |
458 // arguments were not available in the HTTP filters | |
459 return FilterHttpRequests(method, uri, ip, | |
460 headersCount, headersKeys, headersValues, | |
461 0, NULL, NULL); | |
462 } | |
463 #endif | |
464 | |
465 | |
466 static OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
467 OrthancPluginResourceType resourceType, | |
468 const char* resourceId) | |
469 { | |
470 try | |
471 { | |
472 if (authorizationParser_.get() == NULL) | |
473 { | |
71 | 474 return OrthancPluginErrorCode_Success; |
1 | 475 } |
476 | |
477 if (changeType == OrthancPluginChangeType_Deleted) | |
478 { | |
479 switch (resourceType) | |
480 { | |
481 case OrthancPluginResourceType_Patient: | |
482 authorizationParser_->Invalidate(Orthanc::ResourceType_Patient, resourceId); | |
483 break; | |
484 | |
485 case OrthancPluginResourceType_Study: | |
486 authorizationParser_->Invalidate(Orthanc::ResourceType_Study, resourceId); | |
487 break; | |
488 | |
489 case OrthancPluginResourceType_Series: | |
490 authorizationParser_->Invalidate(Orthanc::ResourceType_Series, resourceId); | |
491 break; | |
492 | |
493 case OrthancPluginResourceType_Instance: | |
494 authorizationParser_->Invalidate(Orthanc::ResourceType_Instance, resourceId); | |
495 break; | |
496 | |
497 default: | |
498 break; | |
499 } | |
500 } | |
501 | |
502 return OrthancPluginErrorCode_Success; | |
503 } | |
504 catch (std::runtime_error& e) | |
505 { | |
506 LOG(ERROR) << e.what(); | |
507 return OrthancPluginErrorCode_Success; // Ignore error | |
508 } | |
509 catch (Orthanc::OrthancException& e) | |
510 { | |
511 LOG(ERROR) << e.What(); | |
512 return OrthancPluginErrorCode_Success; // Ignore error | |
513 } | |
514 catch (...) | |
515 { | |
516 LOG(ERROR) << "Unhandled internal exception"; | |
517 return OrthancPluginErrorCode_Success; // Ignore error | |
518 } | |
519 } | |
520 | |
111 | 521 |
522 bool GetUserProfileInternal(OrthancPlugins::IAuthorizationService::UserProfile& profile, const OrthancPluginHttpRequest* request) | |
523 { | |
524 OrthancPlugins::AssociativeArray headers | |
525 (request->headersCount, request->headersKeys, request->headersValues, false); | |
526 | |
527 OrthancPlugins::AssociativeArray getArguments | |
528 (request->getCount, request->getKeys, request->getValues, true); | |
529 | |
530 // Loop over all the authorization tokens stored in the HTTP | |
531 // headers, until finding one that is granted | |
532 for (std::set<OrthancPlugins::Token>::const_iterator | |
533 token = tokens_.begin(); token != tokens_.end(); ++token) | |
534 { | |
535 OrthancPlugins::IAuthorizationService::UserProfile tryProfile; | |
536 | |
537 std::string value; | |
538 | |
539 bool hasValue = false; | |
540 switch (token->GetType()) | |
541 { | |
542 case OrthancPlugins::TokenType_HttpHeader: | |
543 hasValue = headers.GetValue(value, token->GetKey()); | |
544 break; | |
545 | |
546 case OrthancPlugins::TokenType_GetArgument: | |
547 hasValue = getArguments.GetValue(value, token->GetKey()); | |
548 break; | |
549 | |
550 default: | |
551 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
552 } | |
553 | |
554 if (hasValue) | |
555 { | |
556 unsigned int validity; // not used | |
557 if (authorizationService_->GetUserProfile(validity, tryProfile, *token, value)) | |
558 { | |
559 profile = tryProfile; | |
560 return true; | |
561 } | |
562 } | |
563 } | |
564 | |
565 return false; | |
566 } | |
567 | |
568 void AdjustToolsFindQueryLabels(Json::Value& query, const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
569 { | |
570 std::set<std::string> labelsToFind; | |
571 std::string labelsConstraint = "Invalid"; | |
572 | |
573 if (query.isMember("Labels") && query.isMember("LabelsConstraint")) | |
574 { | |
575 Orthanc::SerializationToolbox::ReadSetOfStrings(labelsToFind, query, "Labels"); | |
576 labelsConstraint = Orthanc::SerializationToolbox::ReadString(query, "LabelsConstraint"); | |
577 } | |
578 else if (query.isMember("Labels") || query.isMember("LabelsConstraint")) | |
579 { | |
114 | 580 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 | 581 } |
582 | |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
583 if (!HasAccessToSomeLabels(profile)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
584 { |
114 | 585 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
|
586 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
587 else if (profile.authorizedLabels.size() > 0) |
111 | 588 { |
589 // 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
|
590 if (!HasAccessToAllLabels(profile)) |
111 | 591 { // the user does not have access to all labels -> transform the tools/find body |
592 | |
593 if (labelsToFind.size() == 0) | |
594 { | |
595 if (profile.authorizedLabels.size() > 0) | |
596 { | |
114 | 597 query.removeMember("Labels"); |
111 | 598 Orthanc::SerializationToolbox::WriteSetOfStrings(query, profile.authorizedLabels, "Labels"); |
599 query["LabelsConstraint"] = "Any"; | |
600 } | |
601 } | |
602 else if (labelsConstraint == "All") | |
603 { | |
604 if (profile.authorizedLabels.size() > 0) | |
605 { | |
606 if (!Orthanc::Toolbox::IsSetInSet(labelsToFind, profile.authorizedLabels)) | |
607 { | |
114 | 608 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 | 609 } |
610 } | |
611 } | |
612 else if (labelsConstraint == "Any") | |
613 { | |
614 if (profile.authorizedLabels.size() > 0) | |
615 { | |
616 std::set<std::string> newLabelsToFind; | |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
617 Orthanc::Toolbox::GetIntersection(newLabelsToFind, labelsToFind, profile.authorizedLabels); |
111 | 618 |
619 if (newLabelsToFind.size() == 0) | |
620 { | |
114 | 621 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 | 622 } |
623 | |
624 query.removeMember("Labels"); | |
625 Orthanc::SerializationToolbox::WriteSetOfStrings(query, newLabelsToFind, "Labels"); | |
626 } | |
627 } | |
628 else if (labelsConstraint == "None") | |
629 { | |
630 if (profile.authorizedLabels.size() > 0) | |
631 { | |
114 | 632 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 | 633 } |
634 } | |
635 } | |
636 } | |
637 } | |
638 | |
118 | 639 bool GetStudyInstanceUIDFromQuery(std::string& studyInstanceUID, const Json::Value& body) |
640 { | |
641 | |
642 if (!body.isMember("Query")) | |
643 { | |
644 return false; | |
645 } | |
646 | |
647 if (body["Query"].isMember("StudyInstanceUID")) | |
648 { | |
649 studyInstanceUID = body["Query"]["StudyInstanceUID"].asString(); | |
650 } | |
651 else if (body["Query"].isMember("0020,000d")) | |
652 { | |
653 studyInstanceUID = body["Query"]["0020,000d"].asString(); | |
654 } | |
655 else if (body["Query"].isMember("0020,000D")) | |
656 { | |
657 studyInstanceUID = body["Query"]["0020,000D"].asString(); | |
658 } | |
659 else if (body["Query"].isMember("0020000D")) | |
660 { | |
661 studyInstanceUID = body["Query"]["0020000D"].asString(); | |
662 } | |
663 else | |
664 { | |
665 return false; | |
666 } | |
667 | |
668 return true; | |
669 } | |
670 | |
111 | 671 void ToolsFind(OrthancPluginRestOutput* output, |
672 const char* /*url*/, | |
673 const OrthancPluginHttpRequest* request) | |
674 { | |
675 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
676 | |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
677 try |
111 | 678 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
679 if (request->method != OrthancPluginHttpMethod_Post) |
111 | 680 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
681 OrthancPluginSendMethodNotAllowed(context, output, "POST"); |
111 | 682 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
683 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
684 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
685 // The filtering to this route is performed by this plugin as it is done for any other route before we get here. |
111 | 686 |
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
|
687 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
|
688 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
|
689 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
690 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
|
691 } |
111 | 692 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
693 // 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
|
694 OrthancPlugins::IAuthorizationService::UserProfile profile; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
695 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
|
696 { |
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
|
697 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
|
698 |
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
|
699 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
|
700 { |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
701 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
|
702 } |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
703 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
|
704 { |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
705 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
|
706 } |
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 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
|
708 { |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
709 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
|
710 |
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
|
711 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
|
712 { |
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
|
713 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
|
714 { |
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
|
715 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
|
716 } |
99bdc05012c0
fix wrong forbidden access to dicom-web resources for users with access to all labels
Alain Mazy <am@orthanc.team>
parents:
163
diff
changeset
|
717 |
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
|
718 // since this is a series/instance find, make sure the user has access to the parent study |
162 | 719 Json::Value studyOrthancIds; |
163 | 720 if (!OrthancPlugins::RestApiPost(studyOrthancIds, "/tools/lookup", studyInstanceUID, false)) |
153
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find at Series or Instance level, unable to get the orthanc ID of StudyInstanceUID specified in the query."); |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
723 } |
163 | 724 else if (studyOrthancIds.size() != 1) |
725 { | |
726 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"); | |
727 } | |
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
|
728 |
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 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
|
730 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
|
731 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
|
732 |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
733 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
|
734 { |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
735 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
|
736 } |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
737 |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
738 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
|
739 { |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
740 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
|
741 } |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
742 } |
3683f3d083bd
fix tools/find to allow accessing /dicom-web/studies/../series/../instances/.. on studies that have at least one authorized_labels
Alain Mazy <am@osimis.io>
parents:
150
diff
changeset
|
743 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
744 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
745 else // anonymous user profile or resource token |
111 | 746 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
747 std::string studyInstanceUID; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
748 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
749 // 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
|
750 // -> 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
|
751 // 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
|
752 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
|
753 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
754 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
|
755 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
756 |
162 | 757 Json::Value studyOrthancIds; |
163 | 758 if (!OrthancPlugins::RestApiPost(studyOrthancIds, "/tools/lookup", studyInstanceUID, false)) |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
759 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
760 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: when using tools/find with a resource token, unable to get the orthanc ID of StudyInstanceUID specified in the query."); |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
761 } |
163 | 762 else if (studyOrthancIds.size() != 1) |
763 { | |
764 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"); | |
765 } | |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
766 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
767 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
|
768 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
|
769 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
770 std::set<std::string> labels; |
162 | 771 OrthancPlugins::AccessedResource accessedResource(Orthanc::ResourceType_Study, studyOrthancIds[0]["ID"].asString(), studyInstanceUID, labels); |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
772 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
|
773 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
774 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
|
775 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
776 |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
777 } |
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
778 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
779 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
|
780 |
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
|
781 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
|
782 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
783 OrthancPlugins::AnswerJson(result, output); |
111 | 784 } |
785 | |
786 } | |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
787 |
124
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 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
|
790 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
791 // 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
|
792 if (e.GetErrorCode() == Orthanc::ErrorCode_ForbiddenAccess && !OrthancPlugins::CheckMinimalOrthancVersion(1, 12, 2)) |
111 | 793 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
794 SendForbiddenError(e.GetDetails(), output); |
111 | 795 } |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
796 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
797 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
798 throw e; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
799 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
800 } |
119
66b2b938c43e
fix resource-token when no anonymous profile is available
Alain Mazy <am@osimis.io>
parents:
118
diff
changeset
|
801 |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
802 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
803 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
804 void ToolsLabels(OrthancPluginRestOutput* output, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
805 const char* /*url*/, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
806 const OrthancPluginHttpRequest* request) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
807 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
808 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
809 |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
810 try |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
811 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
812 if (request->method != OrthancPluginHttpMethod_Get) |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
813 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
814 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
815 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
816 else |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
817 { |
124
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
818 // 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
|
819 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
820 // 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
|
821 OrthancPlugins::IAuthorizationService::UserProfile profile; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
822 if (GetUserProfileInternal(profile, request)) |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
823 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
824 if (!HasAccessToSomeLabels(profile)) |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
825 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
826 Json::Value emptyLabels; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
827 OrthancPlugins::AnswerJson(emptyLabels, output); |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
828 return; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
829 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
830 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
831 Json::Value jsonLabels; |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
832 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
|
833 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
834 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
|
835 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
|
836 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
837 if (!HasAccessToAllLabels(profile)) |
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 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
|
840 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
841 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
|
842 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
|
843 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
844 OrthancPlugins::AnswerJson(jsonLabels, output); |
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 |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
847 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
848 else |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
849 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
850 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
|
851 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
852 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
853 } |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
854 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
|
855 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
856 // 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
|
857 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
|
858 { |
d5232d374fd8
Add support for ForbiddenAccess error for Orthanc < 1.12.2
Alain Mazy <am@osimis.io>
parents:
120
diff
changeset
|
859 SendForbiddenError(e.GetDetails(), 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 else |
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 throw e; |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
864 } |
111 | 865 } |
866 } | |
867 | |
868 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
873 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
|
874 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
875 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
|
876 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
877 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
|
878 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
879 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
880 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
881 // 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
|
882 // 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
|
883 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
884 // 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
|
885 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
|
886 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
|
887 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
888 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
|
889 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
890 else |
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 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
|
893 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
894 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
895 // 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
|
896 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
|
897 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
|
898 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
899 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
|
900 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
901 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
902 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
|
903 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
|
904 std::string expirationDateString; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
905 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
|
906 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
907 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
|
908 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
909 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
|
910 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
911 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
912 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
|
913 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
914 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
|
915 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
|
916 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
917 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
|
918 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
919 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
|
920 } |
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 (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
|
923 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
924 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
|
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 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
|
928 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
929 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
|
930 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
931 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
932 resource.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
|
933 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
|
934 } |
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 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
|
937 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
938 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
|
939 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
940 |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
941 if (body.isMember("ValidityDuration")) |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
942 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
943 validityDuration = body["ValidityDuration"].asUInt64(); |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
944 } |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
945 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
946 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
|
947 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
|
948 tokenType, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
949 id, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
950 resources, |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
951 expirationDateString, |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
952 validityDuration)) |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
953 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
954 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
|
955 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
|
956 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
957 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
|
958 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
959 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
|
960 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
961 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
962 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
963 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
|
964 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
965 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
966 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
|
967 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
968 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
969 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
970 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
971 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
972 |
74 | 973 void DecodeToken(OrthancPluginRestOutput* output, |
974 const char* /*url*/, | |
975 const OrthancPluginHttpRequest* request) | |
976 { | |
977 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
978 | |
979 if (request->method != OrthancPluginHttpMethod_Post) | |
980 { | |
981 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
982 } | |
983 else | |
984 { | |
985 // convert from Orthanc flavored API to WebService API | |
986 Json::Value body; | |
987 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize)) | |
988 { | |
989 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); | |
990 } | |
991 | |
992 Json::Value authPayload; | |
993 | |
994 authPayload["token-key"] = body["TokenKey"].asString(); | |
995 authPayload["token-value"] = body["TokenValue"].asString(); | |
996 | |
997 OrthancPlugins::IAuthorizationService::DecodedToken decodedToken; | |
998 if (authorizationService_->DecodeToken(decodedToken, | |
999 body["TokenKey"].asString(), | |
1000 body["TokenValue"].asString())) | |
1001 { | |
1002 Json::Value decodedJsonToken; | |
1003 | |
1004 if (!decodedToken.redirectUrl.empty()) | |
1005 { | |
1006 decodedJsonToken["RedirectUrl"] = decodedToken.redirectUrl; | |
1007 } | |
1008 | |
1009 if (!decodedToken.errorCode.empty()) | |
1010 { | |
1011 decodedJsonToken["ErrorCode"] = decodedToken.errorCode; | |
1012 } | |
1013 | |
1014 if (!decodedToken.tokenType.empty()) | |
1015 { | |
1016 decodedJsonToken["TokenType"] = decodedToken.tokenType; | |
1017 } | |
1018 | |
1019 OrthancPlugins::AnswerJson(decodedJsonToken, output); | |
1020 } | |
1021 } | |
1022 } | |
1023 | |
111 | 1024 |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1025 void GetUserProfile(OrthancPluginRestOutput* output, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1026 const char* /*url*/, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1027 const OrthancPluginHttpRequest* request) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1028 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1029 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1030 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1031 if (request->method != OrthancPluginHttpMethod_Get) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1032 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1033 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1034 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1035 else |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1036 { |
111 | 1037 OrthancPlugins::IAuthorizationService::UserProfile profile; |
1038 if (GetUserProfileInternal(profile, request)) | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1039 { |
111 | 1040 Json::Value jsonProfile; |
1041 jsonProfile["name"] = profile.name; | |
1042 jsonProfile["permissions"] = Json::arrayValue; | |
1043 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
|
1044 { |
111 | 1045 jsonProfile["permissions"].append(*it); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1046 } |
111 | 1047 for (std::set<std::string>::const_iterator it = profile.authorizedLabels.begin(); it != profile.authorizedLabels.end(); ++it) |
1048 { | |
1049 jsonProfile["authorized-labels"].append(*it); | |
1050 } | |
109 | 1051 |
111 | 1052 OrthancPlugins::AnswerJson(jsonProfile, output); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1053 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1054 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1055 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1056 |
71 | 1057 void MergeJson(Json::Value &a, const Json::Value &b) { |
1058 | |
1059 if (!a.isObject() || !b.isObject()) | |
1060 { | |
1061 return; | |
1062 } | |
1063 | |
1064 Json::Value::Members members = b.getMemberNames(); | |
1065 | |
1066 for (size_t i = 0; i < members.size(); i++) | |
1067 { | |
1068 std::string key = members[i]; | |
1069 | |
1070 if (!a[key].isNull() && a[key].type() == Json::objectValue && b[key].type() == Json::objectValue) | |
1071 { | |
1072 MergeJson(a[key], b[key]); | |
1073 } | |
1074 else | |
1075 { | |
1076 a[key] = b[key]; | |
1077 } | |
1078 } | |
1079 } | |
1080 | |
1 | 1081 |
1082 extern "C" | |
1083 { | |
1084 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
1085 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1086 OrthancPlugins::SetGlobalContext(context); |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1087 OrthancPluginLogWarning(context, "Initializing the authorization plugin"); |
1 | 1088 |
1089 /* 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
|
1090 if (OrthancPluginCheckVersion(context) == 0) |
1 | 1091 { |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1092 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
1 | 1093 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
1094 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
1095 return -1; | |
1096 } | |
1097 | |
164 | 1098 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4) |
1099 Orthanc::Logging::InitializePluginContext(context, ORTHANC_PLUGIN_NAME); | |
1100 #elif ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) | |
32 | 1101 Orthanc::Logging::InitializePluginContext(context); |
33
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1102 #else |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1103 Orthanc::Logging::Initialize(context); |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1104 #endif |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
1105 |
156
43b77aa34468
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
153
diff
changeset
|
1106 OrthancPlugins::SetDescription(ORTHANC_PLUGIN_NAME, "Advanced authorization plugin for Orthanc."); |
1 | 1107 |
1108 try | |
1109 { | |
71 | 1110 static const char* PLUGIN_SECTION = "Authorization"; |
1111 | |
1112 OrthancPlugins::OrthancConfiguration orthancFullConfiguration; | |
1113 | |
1114 // read default configuration | |
1115 std::string defaultConfigurationFileContent; | |
1116 Orthanc::EmbeddedResources::GetFileResource(defaultConfigurationFileContent, Orthanc::EmbeddedResources::DEFAULT_CONFIGURATION); | |
1117 Json::Value pluginJsonDefaultConfiguration; | |
1118 OrthancPlugins::ReadJsonWithoutComments(pluginJsonDefaultConfiguration, defaultConfigurationFileContent); | |
1119 Json::Value pluginJsonConfiguration = pluginJsonDefaultConfiguration[PLUGIN_SECTION]; | |
1 | 1120 |
71 | 1121 OrthancPlugins::OrthancConfiguration pluginProvidedConfiguration; |
1122 | |
1123 if (orthancFullConfiguration.IsSection(PLUGIN_SECTION)) | |
1 | 1124 { |
71 | 1125 // get the configuration provided by the user |
1126 orthancFullConfiguration.GetSection(pluginProvidedConfiguration, PLUGIN_SECTION); | |
1127 | |
1128 // merge it with the default configuration. This is a way to apply the all default values in a single step | |
1129 MergeJson(pluginJsonConfiguration, pluginProvidedConfiguration.GetJson()); | |
1130 | |
1131 // recreate a OrthancConfiguration object from the merged configuration | |
1132 OrthancPlugins::OrthancConfiguration pluginConfiguration(pluginJsonConfiguration, PLUGIN_SECTION); | |
1 | 1133 |
1134 // TODO - The size of the caches is set to 10,000 items. Maybe add a configuration option? | |
1135 OrthancPlugins::MemoryCache::Factory factory(10000); | |
1136 | |
71 | 1137 std::string dicomWebRoot = "/dicom-web/"; |
1138 std::string oe2Root = "/ui/"; | |
1 | 1139 |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1140 bool hasBasicAuthEnabled = orthancFullConfiguration.GetBooleanValue("AuthenticationEnabled", "true"); |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1141 |
71 | 1142 if (orthancFullConfiguration.IsSection("DicomWeb")) |
1143 { | |
1144 OrthancPlugins::OrthancConfiguration dicomWeb; | |
1145 dicomWeb.GetSection(orthancFullConfiguration, "DicomWeb"); | |
1146 dicomWebRoot = dicomWeb.GetStringValue("Root", "/dicom-web/"); | |
1147 } | |
1 | 1148 |
71 | 1149 if (orthancFullConfiguration.IsSection("OrthancExplorer2")) |
1150 { | |
1151 OrthancPlugins::OrthancConfiguration oe2; | |
1152 oe2.GetSection(orthancFullConfiguration, "OrthancExplorer2"); | |
1153 oe2Root = oe2.GetStringValue("Root", "/ui/"); | |
1 | 1154 } |
1155 | |
1156 std::list<std::string> tmp; | |
1157 | |
71 | 1158 pluginConfiguration.LookupListOfStrings(tmp, "TokenHttpHeaders", true); |
1 | 1159 for (std::list<std::string>::const_iterator |
1160 it = tmp.begin(); it != tmp.end(); ++it) | |
1161 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1162 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, *it)); |
1 | 1163 } |
1164 | |
71 | 1165 pluginConfiguration.LookupListOfStrings(tmp, "TokenGetArguments", true); |
1 | 1166 |
8
4362026afddf
orthanc 1.2.1 renamed as 1.3.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
1167 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 3, 0) |
1 | 1168 for (std::list<std::string>::const_iterator |
1169 it = tmp.begin(); it != tmp.end(); ++it) | |
1170 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1171 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it)); |
1 | 1172 } |
1173 #else | |
1174 if (!tmp.empty()) | |
1175 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1176 throw Orthanc::OrthancException( |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1177 Orthanc::ErrorCode_Plugin, |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1178 "The option \"TokenGetArguments\" of the authorization plugin " |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
1179 "is only valid if compiled against Orthanc >= 1.3.0" |
1 | 1180 } |
1181 #endif | |
1182 | |
71 | 1183 pluginConfiguration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false); |
1184 pluginConfiguration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false); | |
1 | 1185 |
74 | 1186 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
|
1187 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
|
1188 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
|
1189 std::string urlUserProfile; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1190 std::string urlRoot; |
1 | 1191 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1192 static const char* WEB_SERVICE_ROOT = "WebServiceRootUrl"; |
74 | 1193 static const char* WEB_SERVICE_TOKEN_DECODER = "WebServiceTokenDecoderUrl"; |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1194 static const char* WEB_SERVICE_TOKEN_VALIDATION = "WebServiceTokenValidationUrl"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1195 static const char* WEB_SERVICE_TOKEN_CREATION_BASE = "WebServiceTokenCreationBaseUrl"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1196 static const char* WEB_SERVICE_USER_PROFILE = "WebServiceUserProfileUrl"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1197 static const char* WEB_SERVICE_TOKEN_VALIDATION_LEGACY = "WebService"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1198 if (pluginConfiguration.LookupStringValue(urlRoot, WEB_SERVICE_ROOT)) |
71 | 1199 { |
74 | 1200 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
|
1201 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
|
1202 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
|
1203 urlUserProfile = Orthanc::Toolbox::JoinUri(urlRoot, "/user/get-profile"); |
71 | 1204 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1205 else |
71 | 1206 { |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1207 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION); |
74 | 1208 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
|
1209 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
|
1210 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1211 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
|
1212 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1213 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1214 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
|
1215 pluginConfiguration.LookupStringValue(urlUserProfile, WEB_SERVICE_USER_PROFILE); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1216 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1217 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1218 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
|
1219 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1220 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
|
1221 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1222 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
|
1223 resourceTokensEnabled_ = true; |
71 | 1224 } |
1225 else | |
1226 { | |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1227 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
|
1228 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
|
1229 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1230 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1231 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
|
1232 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1233 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
|
1234 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
|
1235 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1236 static const char* PERMISSIONS = "Permissions"; |
71 | 1237 if (!pluginConfiguration.GetJson().isMember(PERMISSIONS)) |
1238 { | |
1239 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
|
1240 "\" option since you have defined the \"" + std::string(WEB_SERVICE_ROOT) + "\" option"); |
71 | 1241 } |
1242 permissionParser_.reset | |
1243 (new OrthancPlugins::PermissionParser(dicomWebRoot, oe2Root)); | |
1244 | |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1245 permissionParser_->Add(pluginConfiguration.GetJson()[PERMISSIONS], authorizationParser_.get()); |
71 | 1246 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1247 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1248 { |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1249 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
|
1250 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
|
1251 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1252 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1253 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
|
1254 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1255 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
|
1256 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1257 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1258 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1259 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
|
1260 } |
71 | 1261 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1262 if (!resourceTokensEnabled_ && permissionParser_.get() == NULL) |
71 | 1263 { |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1264 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1265 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1266 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
|
1267 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1268 else |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1269 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1270 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
|
1271 } |
1 | 1272 } |
1273 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1274 std::set<std::string> standardConfigurations; |
71 | 1275 if (pluginConfiguration.LookupSetOfStrings(standardConfigurations, "StandardConfigurations", false)) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1276 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1277 if (standardConfigurations.find("osimis-web-viewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1278 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1279 uncheckedFolders_.push_back("/osimis-viewer/app/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1280 uncheckedFolders_.push_back("/osimis-viewer/languages/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1281 uncheckedResources_.insert("/osimis-viewer/config.js"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1282 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1283 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
|
1284 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
|
1285 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1286 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1287 if (standardConfigurations.find("stone-webviewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1288 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1289 uncheckedFolders_.push_back("/stone-webviewer/"); |
65 | 1290 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
|
1291 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1292 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1293 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1294 |
65 | 1295 if (standardConfigurations.find("orthanc-explorer-2") != standardConfigurations.end()) |
1296 { | |
1297 uncheckedFolders_.push_back("/ui/app/"); | |
74 | 1298 uncheckedFolders_.push_back("/ui/landing/"); |
76 | 1299 uncheckedResources_.insert("/"); // for the redirect to /ui/app/ |
66 | 1300 uncheckedResources_.insert("/ui/api/pre-login-configuration"); // for the UI to know, i.e. if Keycloak is enabled or not |
71 | 1301 uncheckedResources_.insert("/ui/api/configuration"); |
120 | 1302 uncheckedResources_.insert("/auth/user/profile"); |
65 | 1303 |
1304 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); // for basic-auth | |
1305 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
|
1306 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in OE2 |
65 | 1307 } |
1308 | |
102 | 1309 if (standardConfigurations.find("ohif") != standardConfigurations.end()) |
1310 { | |
1311 uncheckedFolders_.push_back("/ohif/"); | |
1312 } | |
1313 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1314 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1315 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1316 std::string checkedLevelString; |
71 | 1317 if (pluginConfiguration.LookupStringValue(checkedLevelString, "CheckedLevel")) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1318 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1319 OrthancPlugins::AccessLevel checkedLevel = OrthancPlugins::StringToAccessLevel(checkedLevelString); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1320 if (checkedLevel == OrthancPlugins::AccessLevel_Instance) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1321 { |
113 | 1322 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1323 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1324 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1325 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1326 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1327 else if (checkedLevel == OrthancPlugins::AccessLevel_Series) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1328 { |
113 | 1329 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1330 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1331 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1332 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1333 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1334 else if (checkedLevel == OrthancPlugins::AccessLevel_Study) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1335 { |
113 | 1336 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1337 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1338 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1339 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1340 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1341 else if (checkedLevel == OrthancPlugins::AccessLevel_Patient) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1342 { |
113 | 1343 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1344 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1345 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1346 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1347 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1348 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1349 |
71 | 1350 if (pluginConfiguration.LookupListOfStrings(tmp, "UncheckedLevels", false)) |
1 | 1351 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1352 if (uncheckedLevels_.size() == 0) |
1 | 1353 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1354 for (std::list<std::string>::const_iterator |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1355 it = tmp.begin(); it != tmp.end(); ++it) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1356 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1357 uncheckedLevels_.insert(OrthancPlugins::StringToAccessLevel(*it)); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1358 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1359 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1360 else |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1361 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1362 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
|
1363 return -1; |
1 | 1364 } |
1365 } | |
1366 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1367 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
|
1368 urlTokenCreationBase, |
74 | 1369 urlUserProfile, |
1370 urlTokenDecoder)); | |
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
|
1371 |
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
|
1372 std::string webServiceIdentifier; |
71 | 1373 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
|
1374 { |
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
|
1375 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
|
1376 } |
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
|
1377 |
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
|
1378 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
|
1379 std::string webServicePassword; |
71 | 1380 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
|
1381 { |
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
|
1382 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
|
1383 } |
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
|
1384 |
1 | 1385 authorizationService_.reset |
1386 (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
|
1387 (webService.release(), factory)); |
1 | 1388 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1389 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
|
1390 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1391 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
|
1392 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1393 |
74 | 1394 if (!urlTokenDecoder.empty()) |
1395 { | |
1396 OrthancPlugins::RegisterRestCallback<DecodeToken>("/auth/tokens/decode", true); | |
1397 } | |
1398 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1399 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
|
1400 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1401 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
|
1402 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
|
1403 OrthancPlugins::RegisterRestCallback<ToolsLabels>("/tools/labels", true); |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1404 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1405 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1406 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
|
1407 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1408 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
|
1409 } |
74 | 1410 |
149
423531fb1200
SINGLE_RESOURCE_PATTERNS to facilitate api-key support
Alain Mazy <am@osimis.io>
parents:
138
diff
changeset
|
1411 if (resourceTokensEnabled_ || userTokensEnabled_) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1412 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1413 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1414 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1415 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
|
1416 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1417 |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1418 LOG(WARNING) << "Authorization plugin: Registering Incoming HTTP Request Filter"; |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1419 |
1 | 1420 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1421 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests); |
1 | 1422 #else |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1423 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback); |
1 | 1424 #endif |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1425 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1426 |
1 | 1427 } |
1428 else | |
1429 { | |
71 | 1430 LOG(WARNING) << "No section \"" << PLUGIN_SECTION << "\" in the configuration file, " |
1 | 1431 << "the authorization plugin is disabled"; |
1432 } | |
1433 } | |
1434 catch (Orthanc::OrthancException& e) | |
1435 { | |
1436 LOG(ERROR) << e.What(); | |
1437 return -1; | |
1438 } | |
1439 | |
1440 return 0; | |
1441 } | |
1442 | |
1443 | |
1444 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
1445 { | |
1446 authorizationParser_.reset(NULL); | |
1447 } | |
1448 | |
1449 | |
1450 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
1451 { | |
156
43b77aa34468
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
153
diff
changeset
|
1452 return ORTHANC_PLUGIN_NAME; |
1 | 1453 } |
1454 | |
1455 | |
1456 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
1457 { | |
22
c44013681a51
now using the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
1458 return ORTHANC_PLUGIN_VERSION; |
1 | 1459 } |
1460 } |