Mercurial > hg > orthanc-authorization
annotate Plugin/Plugin.cpp @ 109:7381a7674b36
wip: adding labels
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 18 Aug 2023 12:08:49 +0200 |
parents | fcc4542a0c38 |
children | 2b1a95c7d263 |
rev | line source |
---|---|
1 | 1 /** |
2 * Advanced authorization plugin for Orthanc | |
68 | 3 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
1 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 #include "AssociativeArray.h" | |
20 #include "DefaultAuthorizationParser.h" | |
21 #include "CachedAuthorizationService.h" | |
22 #include "AuthorizationWebService.h" | |
71 | 23 #include "PermissionParser.h" |
1 | 24 #include "MemoryCache.h" |
34 | 25 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
26 | |
36
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
27 #include <Compatibility.h> // For std::unique_ptr<> |
32 | 28 #include <Logging.h> |
29 #include <Toolbox.h> | |
71 | 30 #include <EmbeddedResources.h> |
1 | 31 |
32 | |
33 // Configuration of the authorization plugin | |
36
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
35
diff
changeset
|
34 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
|
35 static std::unique_ptr<OrthancPlugins::IAuthorizationService> authorizationService_; |
71 | 36 static std::unique_ptr<OrthancPlugins::PermissionParser> permissionParser_; |
1 | 37 static std::set<std::string> uncheckedResources_; |
38 static std::list<std::string> uncheckedFolders_; | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
39 static std::set<OrthancPlugins::Token> tokens_; |
1 | 40 static std::set<OrthancPlugins::AccessLevel> uncheckedLevels_; |
41 | |
42 | |
71 | 43 static std::string JoinStrings(const std::set<std::string>& values) |
44 { | |
45 std::string out; | |
46 std::set<std::string> copy = values; // TODO: remove after upgrading to OrthancFramework 1.11.3+ | |
47 Orthanc::Toolbox::JoinStrings(out, copy, "|"); | |
48 return out; | |
49 } | |
50 | |
86 | 51 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
|
52 { |
86 | 53 private: |
54 OrthancPlugins::Token token_; | |
55 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
|
56 |
86 | 57 public: |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
58 TokenAndValue(const OrthancPlugins::Token& token, const std::string& value) : |
86 | 59 token_(token), |
60 value_(value) | |
61 { | |
62 } | |
63 | |
64 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
|
65 { |
86 | 66 return token_; |
67 } | |
68 | |
69 const std::string& GetValue() const | |
70 { | |
71 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
|
72 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
73 }; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
74 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
75 |
1 | 76 static int32_t FilterHttpRequests(OrthancPluginHttpMethod method, |
77 const char *uri, | |
78 const char *ip, | |
79 uint32_t headersCount, | |
80 const char *const *headersKeys, | |
81 const char *const *headersValues, | |
82 uint32_t getArgumentsCount, | |
83 const char *const *getArgumentsKeys, | |
84 const char *const *getArgumentsValues) | |
85 { | |
86 try | |
87 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
88 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
|
89 |
109 | 90 // Allow GET accesses to unchecked resources/folders (usually static resources) |
91 //////////////////////////////////////////////////////////////// | |
92 | |
1 | 93 if (method == OrthancPluginHttpMethod_Get) |
94 { | |
95 if (uncheckedResources_.find(uri) != uncheckedResources_.end()) | |
96 { | |
97 return 1; | |
98 } | |
99 | |
100 for (std::list<std::string>::const_iterator | |
101 it = uncheckedFolders_.begin(); it != uncheckedFolders_.end(); ++it) | |
102 { | |
103 if (Orthanc::Toolbox::StartsWith(uri, *it)) | |
104 { | |
105 return 1; | |
106 } | |
107 } | |
108 } | |
109 | |
109 | 110 // Extract auth tokens from headers and url get arguments |
111 //////////////////////////////////////////////////////////////// | |
112 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
113 OrthancPlugins::AssociativeArray headers(headersCount, headersKeys, headersValues, false); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
114 OrthancPlugins::AssociativeArray getArguments(getArgumentsCount, getArgumentsKeys, getArgumentsValues, true); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
115 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
116 std::vector<TokenAndValue> authTokens; // the tokens that are set in this request |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
117 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
118 for (std::set<OrthancPlugins::Token>::const_iterator token = tokens_.begin(); token != tokens_.end(); ++token) |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
119 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
120 std::string value; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
121 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
122 bool hasValue = false; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
123 switch (token->GetType()) |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
124 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
125 case OrthancPlugins::TokenType_HttpHeader: |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
126 hasValue = headers.GetValue(value, token->GetKey()); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
127 break; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
128 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
129 case OrthancPlugins::TokenType_GetArgument: |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
130 hasValue = getArguments.GetValue(value, token->GetKey()); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
131 break; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
132 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
133 default: |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
135 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
136 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
137 if (hasValue) |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
138 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
139 authTokens.push_back(TokenAndValue(*token, value)); |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
140 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
141 } |
71 | 142 |
109 | 143 // Based on the tokens, check if the user has access based on its permissions and the mapping between urls and permissions |
144 //////////////////////////////////////////////////////////////// | |
145 | |
71 | 146 if (permissionParser_.get() != NULL && |
147 authorizationService_.get() != NULL) | |
148 { | |
149 std::set<std::string> requiredPermissions; | |
150 std::string matchedPattern; | |
151 if (permissionParser_->Parse(requiredPermissions, matchedPattern, method, uri)) | |
152 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
153 if (authTokens.empty()) |
71 | 154 { |
103 | 155 std::string msg = std::string("Testing whether anonymous user has any of the required permissions '") + JoinStrings(requiredPermissions) + "'"; |
156 LOG(INFO) << msg; | |
71 | 157 if (authorizationService_->HasAnonymousUserPermission(validity, requiredPermissions)) |
158 { | |
103 | 159 LOG(INFO) << msg << " -> granted"; |
71 | 160 return 1; |
161 } | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
162 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
163 { |
103 | 164 LOG(INFO) << msg << " -> not granted"; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
165 } |
71 | 166 } |
167 else | |
168 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
169 for (size_t i = 0; i < authTokens.size(); ++i) |
71 | 170 { |
103 | 171 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 + "'"; |
172 | |
173 LOG(INFO) << msg; | |
86 | 174 if (authorizationService_->HasUserPermission(validity, requiredPermissions, authTokens[i].GetToken(), authTokens[i].GetValue())) |
71 | 175 { |
109 | 176 // TODO: check labels permissions |
103 | 177 LOG(INFO) << msg << " -> granted"; |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
178 return 1; |
71 | 179 } |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
180 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
181 { |
103 | 182 LOG(INFO) << msg << " -> not granted"; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
183 } |
71 | 184 } |
185 } | |
186 } | |
187 } | |
109 | 188 |
189 | |
190 // | |
191 | |
1 | 192 if (authorizationParser_.get() != NULL && |
193 authorizationService_.get() != NULL) | |
194 { | |
195 // Parse the resources that are accessed through this URI | |
196 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
|
197 |
57
55539d564f4f
added support for /dicom-web/series? & /dicom-web/instances?
Alain Mazy <am@osimis.io>
parents:
56
diff
changeset
|
198 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) |
1 | 199 { |
200 return 0; // Unable to parse this URI | |
201 } | |
202 | |
203 // Loop over all the accessed resources to ensure access is | |
204 // granted to each of them | |
205 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator | |
206 access = accesses.begin(); access != accesses.end(); ++access) | |
207 { | |
208 // Ignored the access levels that are unchecked | |
209 // (cf. "UncheckedLevels" option) | |
210 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end()) | |
211 { | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
212 std::string msg = std::string("Testing whether access to ") + OrthancPlugins::EnumerationToString(access->GetLevel()) + " \"" + access->GetOrthancId() + "\" is allowed with a resource token"; |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
213 LOG(INFO) << msg; |
1 | 214 |
215 bool granted = false; | |
216 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
217 if (authTokens.empty()) |
1 | 218 { |
71 | 219 granted = authorizationService_->IsGrantedToAnonymousUser(validity, method, *access); |
1 | 220 } |
221 else | |
222 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
223 // Loop over all the authorization tokens in the request until finding one that is granted |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
224 for (size_t i = 0; i < authTokens.size(); ++i) |
1 | 225 { |
86 | 226 if (authorizationService_->IsGranted(validity, method, *access, authTokens[i].GetToken(), authTokens[i].GetValue())) |
1 | 227 { |
228 granted = true; | |
229 break; | |
230 } | |
231 } | |
232 } | |
233 | |
234 if (!granted) | |
235 { | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
236 LOG(INFO) << msg << " -> not granted"; |
1 | 237 return 0; |
238 } | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
239 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
240 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
241 LOG(INFO) << msg << " -> granted"; |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
242 } |
1 | 243 } |
244 } | |
245 | |
246 // Access is granted to all the resources | |
247 return 1; | |
248 } | |
249 | |
250 // By default, forbid access to all the resources | |
251 return 0; | |
252 } | |
253 catch (std::runtime_error& e) | |
254 { | |
255 LOG(ERROR) << e.what(); | |
256 return OrthancPluginErrorCode_Success; // Ignore error | |
257 } | |
258 catch (Orthanc::OrthancException& e) | |
259 { | |
260 LOG(ERROR) << e.What(); | |
261 return OrthancPluginErrorCode_Success; // Ignore error | |
262 } | |
263 catch (...) | |
264 { | |
265 LOG(ERROR) << "Unhandled internal exception"; | |
266 return OrthancPluginErrorCode_Success; // Ignore error | |
267 } | |
268 } | |
269 | |
270 | |
271 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) | |
272 static int32_t FilterHttpRequestsFallback(OrthancPluginHttpMethod method, | |
273 const char *uri, | |
274 const char *ip, | |
275 uint32_t headersCount, | |
276 const char *const *headersKeys, | |
277 const char *const *headersValues) | |
278 { | |
279 // Fallback wrapper function for Orthanc <= 1.2.0, where the GET | |
280 // arguments were not available in the HTTP filters | |
281 return FilterHttpRequests(method, uri, ip, | |
282 headersCount, headersKeys, headersValues, | |
283 0, NULL, NULL); | |
284 } | |
285 #endif | |
286 | |
287 | |
288 static OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
289 OrthancPluginResourceType resourceType, | |
290 const char* resourceId) | |
291 { | |
292 try | |
293 { | |
294 if (authorizationParser_.get() == NULL) | |
295 { | |
71 | 296 return OrthancPluginErrorCode_Success; |
1 | 297 } |
298 | |
299 if (changeType == OrthancPluginChangeType_Deleted) | |
300 { | |
301 switch (resourceType) | |
302 { | |
303 case OrthancPluginResourceType_Patient: | |
304 authorizationParser_->Invalidate(Orthanc::ResourceType_Patient, resourceId); | |
305 break; | |
306 | |
307 case OrthancPluginResourceType_Study: | |
308 authorizationParser_->Invalidate(Orthanc::ResourceType_Study, resourceId); | |
309 break; | |
310 | |
311 case OrthancPluginResourceType_Series: | |
312 authorizationParser_->Invalidate(Orthanc::ResourceType_Series, resourceId); | |
313 break; | |
314 | |
315 case OrthancPluginResourceType_Instance: | |
316 authorizationParser_->Invalidate(Orthanc::ResourceType_Instance, resourceId); | |
317 break; | |
318 | |
319 default: | |
320 break; | |
321 } | |
322 } | |
323 | |
324 return OrthancPluginErrorCode_Success; | |
325 } | |
326 catch (std::runtime_error& e) | |
327 { | |
328 LOG(ERROR) << e.what(); | |
329 return OrthancPluginErrorCode_Success; // Ignore error | |
330 } | |
331 catch (Orthanc::OrthancException& e) | |
332 { | |
333 LOG(ERROR) << e.What(); | |
334 return OrthancPluginErrorCode_Success; // Ignore error | |
335 } | |
336 catch (...) | |
337 { | |
338 LOG(ERROR) << "Unhandled internal exception"; | |
339 return OrthancPluginErrorCode_Success; // Ignore error | |
340 } | |
341 } | |
342 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
347 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
|
348 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
349 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
|
350 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
351 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
|
352 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
353 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
354 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
355 // 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
|
356 // 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
|
357 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
358 // 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
|
359 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
|
360 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
|
361 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
362 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
|
363 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
364 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
365 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
366 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
|
367 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
368 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
369 // 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
|
370 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
|
371 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
|
372 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
373 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
|
374 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
375 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
376 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
|
377 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
|
378 std::string expirationDateString; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
379 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
|
380 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
381 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
|
382 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
383 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
|
384 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
385 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
386 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
|
387 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
388 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
|
389 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
|
390 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
391 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
|
392 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
393 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
|
394 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
395 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
396 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
|
397 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
398 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
|
399 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
400 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
401 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
|
402 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
403 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
|
404 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
405 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
406 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
|
407 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
|
408 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
409 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
410 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
|
411 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
412 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
|
413 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
414 |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
415 if (body.isMember("ValidityDuration")) |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
416 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
417 validityDuration = body["ValidityDuration"].asUInt64(); |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
418 } |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
419 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
420 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
|
421 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
|
422 tokenType, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
423 id, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
424 resources, |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
425 expirationDateString, |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
426 validityDuration)) |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
427 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
428 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
|
429 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
|
430 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
431 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
|
432 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
433 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
|
434 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
435 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
436 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
437 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
|
438 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
439 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
440 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
|
441 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
442 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
443 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
444 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
445 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
446 |
74 | 447 void DecodeToken(OrthancPluginRestOutput* output, |
448 const char* /*url*/, | |
449 const OrthancPluginHttpRequest* request) | |
450 { | |
451 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
452 | |
453 if (request->method != OrthancPluginHttpMethod_Post) | |
454 { | |
455 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
456 } | |
457 else | |
458 { | |
459 // convert from Orthanc flavored API to WebService API | |
460 Json::Value body; | |
461 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize)) | |
462 { | |
463 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); | |
464 } | |
465 | |
466 Json::Value authPayload; | |
467 | |
468 authPayload["token-key"] = body["TokenKey"].asString(); | |
469 authPayload["token-value"] = body["TokenValue"].asString(); | |
470 | |
471 OrthancPlugins::IAuthorizationService::DecodedToken decodedToken; | |
472 if (authorizationService_->DecodeToken(decodedToken, | |
473 body["TokenKey"].asString(), | |
474 body["TokenValue"].asString())) | |
475 { | |
476 Json::Value decodedJsonToken; | |
477 | |
478 if (!decodedToken.redirectUrl.empty()) | |
479 { | |
480 decodedJsonToken["RedirectUrl"] = decodedToken.redirectUrl; | |
481 } | |
482 | |
483 if (!decodedToken.errorCode.empty()) | |
484 { | |
485 decodedJsonToken["ErrorCode"] = decodedToken.errorCode; | |
486 } | |
487 | |
488 if (!decodedToken.tokenType.empty()) | |
489 { | |
490 decodedJsonToken["TokenType"] = decodedToken.tokenType; | |
491 } | |
492 | |
493 OrthancPlugins::AnswerJson(decodedJsonToken, output); | |
494 } | |
495 } | |
496 } | |
497 | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
498 void GetUserProfile(OrthancPluginRestOutput* output, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
499 const char* /*url*/, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
500 const OrthancPluginHttpRequest* request) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
501 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
502 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
503 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
504 if (request->method != OrthancPluginHttpMethod_Get) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
505 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
506 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
507 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
508 else |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
509 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
510 OrthancPlugins::AssociativeArray headers |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
511 (request->headersCount, request->headersKeys, request->headersValues, false); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
512 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
513 OrthancPlugins::AssociativeArray getArguments |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
514 (request->getCount, request->getKeys, request->getValues, true); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
515 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
516 // Loop over all the authorization tokens stored in the HTTP |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
517 // headers, until finding one that is granted |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
518 for (std::set<OrthancPlugins::Token>::const_iterator |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
519 token = tokens_.begin(); token != tokens_.end(); ++token) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
520 { |
109 | 521 OrthancPlugins::IAuthorizationService::UserProfile profile; |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
522 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
523 std::string value; |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
524 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
525 bool hasValue = false; |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
526 switch (token->GetType()) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
527 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
528 case OrthancPlugins::TokenType_HttpHeader: |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
529 hasValue = headers.GetValue(value, token->GetKey()); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
530 break; |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
531 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
532 case OrthancPlugins::TokenType_GetArgument: |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
533 hasValue = getArguments.GetValue(value, token->GetKey()); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
534 break; |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
535 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
536 default: |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
537 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
538 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
539 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
540 if (hasValue) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
541 { |
71 | 542 unsigned int validity; // not used |
82 | 543 if (authorizationService_->GetUserProfile(validity, profile, *token, value)) |
544 { | |
109 | 545 Json::Value jsonProfile; |
546 jsonProfile["name"] = profile.name; | |
547 jsonProfile["permissions"] = Json::arrayValue; | |
548 for (std::set<std::string>::const_iterator it = profile.permissions.begin(); it != profile.permissions.end(); ++it) | |
549 { | |
550 jsonProfile["permissions"].append(*it); | |
551 } | |
552 for (std::set<std::string>::const_iterator it = profile.authorizedLabels.begin(); it != profile.authorizedLabels.end(); ++it) | |
553 { | |
554 jsonProfile["authorized-labels"].append(*it); | |
555 } | |
556 for (std::set<std::string>::const_iterator it = profile.forbiddenLabels.begin(); it != profile.forbiddenLabels.end(); ++it) | |
557 { | |
558 jsonProfile["forbidden-labels"].append(*it); | |
559 } | |
560 | |
561 OrthancPlugins::AnswerJson(jsonProfile, output); | |
82 | 562 return; |
563 } | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
564 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
565 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
566 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
567 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
568 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
569 |
71 | 570 void MergeJson(Json::Value &a, const Json::Value &b) { |
571 | |
572 if (!a.isObject() || !b.isObject()) | |
573 { | |
574 return; | |
575 } | |
576 | |
577 Json::Value::Members members = b.getMemberNames(); | |
578 | |
579 for (size_t i = 0; i < members.size(); i++) | |
580 { | |
581 std::string key = members[i]; | |
582 | |
583 if (!a[key].isNull() && a[key].type() == Json::objectValue && b[key].type() == Json::objectValue) | |
584 { | |
585 MergeJson(a[key], b[key]); | |
586 } | |
587 else | |
588 { | |
589 a[key] = b[key]; | |
590 } | |
591 } | |
592 } | |
593 | |
1 | 594 |
595 extern "C" | |
596 { | |
597 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
598 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
599 OrthancPlugins::SetGlobalContext(context); |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
600 OrthancPluginLogWarning(context, "Initializing the authorization plugin"); |
1 | 601 |
602 /* 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
|
603 if (OrthancPluginCheckVersion(context) == 0) |
1 | 604 { |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
605 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
1 | 606 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
607 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
608 return -1; | |
609 } | |
610 | |
41 | 611 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
32 | 612 Orthanc::Logging::InitializePluginContext(context); |
33
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
613 #else |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
614 Orthanc::Logging::Initialize(context); |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
615 #endif |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
616 |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
617 OrthancPluginSetDescription(context, "Advanced authorization plugin for Orthanc."); |
1 | 618 |
619 try | |
620 { | |
71 | 621 static const char* PLUGIN_SECTION = "Authorization"; |
622 | |
623 OrthancPlugins::OrthancConfiguration orthancFullConfiguration; | |
624 | |
625 // read default configuration | |
626 std::string defaultConfigurationFileContent; | |
627 Orthanc::EmbeddedResources::GetFileResource(defaultConfigurationFileContent, Orthanc::EmbeddedResources::DEFAULT_CONFIGURATION); | |
628 Json::Value pluginJsonDefaultConfiguration; | |
629 OrthancPlugins::ReadJsonWithoutComments(pluginJsonDefaultConfiguration, defaultConfigurationFileContent); | |
630 Json::Value pluginJsonConfiguration = pluginJsonDefaultConfiguration[PLUGIN_SECTION]; | |
1 | 631 |
71 | 632 OrthancPlugins::OrthancConfiguration pluginProvidedConfiguration; |
633 | |
634 if (orthancFullConfiguration.IsSection(PLUGIN_SECTION)) | |
1 | 635 { |
71 | 636 // get the configuration provided by the user |
637 orthancFullConfiguration.GetSection(pluginProvidedConfiguration, PLUGIN_SECTION); | |
638 | |
639 // merge it with the default configuration. This is a way to apply the all default values in a single step | |
640 MergeJson(pluginJsonConfiguration, pluginProvidedConfiguration.GetJson()); | |
641 | |
642 // recreate a OrthancConfiguration object from the merged configuration | |
643 OrthancPlugins::OrthancConfiguration pluginConfiguration(pluginJsonConfiguration, PLUGIN_SECTION); | |
1 | 644 |
645 // TODO - The size of the caches is set to 10,000 items. Maybe add a configuration option? | |
646 OrthancPlugins::MemoryCache::Factory factory(10000); | |
647 | |
71 | 648 std::string dicomWebRoot = "/dicom-web/"; |
649 std::string oe2Root = "/ui/"; | |
1 | 650 |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
651 bool hasBasicAuthEnabled = orthancFullConfiguration.GetBooleanValue("AuthenticationEnabled", "true"); |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
652 |
71 | 653 if (orthancFullConfiguration.IsSection("DicomWeb")) |
654 { | |
655 OrthancPlugins::OrthancConfiguration dicomWeb; | |
656 dicomWeb.GetSection(orthancFullConfiguration, "DicomWeb"); | |
657 dicomWebRoot = dicomWeb.GetStringValue("Root", "/dicom-web/"); | |
658 } | |
1 | 659 |
71 | 660 if (orthancFullConfiguration.IsSection("OrthancExplorer2")) |
661 { | |
662 OrthancPlugins::OrthancConfiguration oe2; | |
663 oe2.GetSection(orthancFullConfiguration, "OrthancExplorer2"); | |
664 oe2Root = oe2.GetStringValue("Root", "/ui/"); | |
1 | 665 } |
666 | |
667 std::list<std::string> tmp; | |
668 | |
71 | 669 pluginConfiguration.LookupListOfStrings(tmp, "TokenHttpHeaders", true); |
1 | 670 for (std::list<std::string>::const_iterator |
671 it = tmp.begin(); it != tmp.end(); ++it) | |
672 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
673 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, *it)); |
1 | 674 } |
675 | |
71 | 676 pluginConfiguration.LookupListOfStrings(tmp, "TokenGetArguments", true); |
1 | 677 |
8
4362026afddf
orthanc 1.2.1 renamed as 1.3.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
678 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 3, 0) |
1 | 679 for (std::list<std::string>::const_iterator |
680 it = tmp.begin(); it != tmp.end(); ++it) | |
681 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
682 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it)); |
1 | 683 } |
684 #else | |
685 if (!tmp.empty()) | |
686 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
687 throw Orthanc::OrthancException( |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
688 Orthanc::ErrorCode_Plugin, |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
689 "The option \"TokenGetArguments\" of the authorization plugin " |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
690 "is only valid if compiled against Orthanc >= 1.3.0" |
1 | 691 } |
692 #endif | |
693 | |
71 | 694 pluginConfiguration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false); |
695 pluginConfiguration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false); | |
1 | 696 |
74 | 697 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
|
698 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
|
699 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
|
700 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
|
701 std::string urlRoot; |
1 | 702 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
703 static const char* WEB_SERVICE_ROOT = "WebServiceRootUrl"; |
74 | 704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 if (pluginConfiguration.LookupStringValue(urlRoot, WEB_SERVICE_ROOT)) |
71 | 710 { |
74 | 711 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
|
712 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
|
713 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
|
714 urlUserProfile = Orthanc::Toolbox::JoinUri(urlRoot, "/user/get-profile"); |
71 | 715 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
716 else |
71 | 717 { |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
718 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION); |
74 | 719 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
|
720 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
|
721 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
722 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
|
723 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
724 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
725 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
|
726 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
|
727 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
728 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
729 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
|
730 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
731 LOG(WARNING) << "Authorization plugin: url defined for Token Validation: " << urlTokenValidation; |
71 | 732 authorizationParser_.reset |
733 (new OrthancPlugins::DefaultAuthorizationParser(factory, dicomWebRoot)); | |
734 } | |
735 else | |
736 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
737 LOG(WARNING) << "Authorization plugin: no url defined for Token Validation"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
738 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
739 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
740 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
|
741 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
742 LOG(WARNING) << "Authorization plugin: url defined for User Profile: " << urlUserProfile; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
743 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
744 static const char* PERMISSIONS = "Permissions"; |
71 | 745 if (!pluginConfiguration.GetJson().isMember(PERMISSIONS)) |
746 { | |
747 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
|
748 "\" option since you have defined the \"" + std::string(WEB_SERVICE_ROOT) + "\" option"); |
71 | 749 } |
750 permissionParser_.reset | |
751 (new OrthancPlugins::PermissionParser(dicomWebRoot, oe2Root)); | |
752 | |
753 permissionParser_->Add(pluginConfiguration.GetJson()[PERMISSIONS]); | |
754 } | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
755 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
756 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
757 LOG(WARNING) << "Authorization plugin: no url defined for User Profile"; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
758 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
759 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
760 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
|
761 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
762 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
|
763 // TODO Token Creation |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
764 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
765 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
766 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
767 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
|
768 } |
71 | 769 |
770 if (authorizationParser_.get() == NULL && permissionParser_.get() == NULL) | |
771 { | |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
772 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
773 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
774 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
|
775 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
776 else |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
777 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
778 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
|
779 } |
1 | 780 } |
781 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
782 std::set<std::string> standardConfigurations; |
71 | 783 if (pluginConfiguration.LookupSetOfStrings(standardConfigurations, "StandardConfigurations", false)) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
784 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
785 if (standardConfigurations.find("osimis-web-viewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
786 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
787 uncheckedFolders_.push_back("/osimis-viewer/app/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
788 uncheckedFolders_.push_back("/osimis-viewer/languages/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
789 uncheckedResources_.insert("/osimis-viewer/config.js"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
790 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
791 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
|
792 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
|
793 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
794 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
795 if (standardConfigurations.find("stone-webviewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
796 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
797 uncheckedFolders_.push_back("/stone-webviewer/"); |
65 | 798 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
|
799 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
800 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
801 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
802 |
65 | 803 if (standardConfigurations.find("orthanc-explorer-2") != standardConfigurations.end()) |
804 { | |
805 uncheckedFolders_.push_back("/ui/app/"); | |
74 | 806 uncheckedFolders_.push_back("/ui/landing/"); |
76 | 807 uncheckedResources_.insert("/"); // for the redirect to /ui/app/ |
66 | 808 uncheckedResources_.insert("/ui/api/pre-login-configuration"); // for the UI to know, i.e. if Keycloak is enabled or not |
71 | 809 uncheckedResources_.insert("/ui/api/configuration"); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
810 uncheckedResources_.insert("/auth/user-profile"); |
65 | 811 |
812 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); // for basic-auth | |
813 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
|
814 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in OE2 |
65 | 815 } |
816 | |
102 | 817 if (standardConfigurations.find("ohif") != standardConfigurations.end()) |
818 { | |
819 uncheckedFolders_.push_back("/ohif/"); | |
820 } | |
821 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
822 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
823 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
824 std::string checkedLevelString; |
71 | 825 if (pluginConfiguration.LookupStringValue(checkedLevelString, "CheckedLevel")) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
826 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
827 OrthancPlugins::AccessLevel checkedLevel = OrthancPlugins::StringToAccessLevel(checkedLevelString); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
828 if (checkedLevel == OrthancPlugins::AccessLevel_Instance) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
829 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
830 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
831 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
832 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
833 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
834 else if (checkedLevel == OrthancPlugins::AccessLevel_Series) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
835 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
836 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
837 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
838 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
839 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
840 else if (checkedLevel == OrthancPlugins::AccessLevel_Study) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
841 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
842 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
843 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
844 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
845 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
846 else if (checkedLevel == OrthancPlugins::AccessLevel_Patient) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
847 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
848 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
849 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
850 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
851 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
852 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
853 |
71 | 854 if (pluginConfiguration.LookupListOfStrings(tmp, "UncheckedLevels", false)) |
1 | 855 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
856 if (uncheckedLevels_.size() == 0) |
1 | 857 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
858 for (std::list<std::string>::const_iterator |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
859 it = tmp.begin(); it != tmp.end(); ++it) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
860 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
861 uncheckedLevels_.insert(OrthancPlugins::StringToAccessLevel(*it)); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
862 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
863 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
864 else |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
865 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
866 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
|
867 return -1; |
1 | 868 } |
869 } | |
870 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
871 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
|
872 urlTokenCreationBase, |
74 | 873 urlUserProfile, |
874 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
|
875 |
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
|
876 std::string webServiceIdentifier; |
71 | 877 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
|
878 { |
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
|
879 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
|
880 } |
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
|
881 |
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
|
882 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
|
883 std::string webServicePassword; |
71 | 884 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
|
885 { |
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
|
886 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
|
887 } |
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
|
888 |
1 | 889 authorizationService_.reset |
890 (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
|
891 (webService.release(), factory)); |
1 | 892 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
893 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
|
894 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
895 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
|
896 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
897 |
74 | 898 if (!urlTokenDecoder.empty()) |
899 { | |
900 OrthancPlugins::RegisterRestCallback<DecodeToken>("/auth/tokens/decode", true); | |
901 } | |
902 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
903 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
|
904 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
905 OrthancPlugins::RegisterRestCallback<GetUserProfile>("/auth/user/profile", true); |
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 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
908 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
|
909 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
910 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
|
911 } |
74 | 912 |
913 | |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
914 if (authorizationParser_.get() != NULL || permissionParser_.get() != NULL) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
915 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
916 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
917 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
918 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
|
919 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
920 |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
921 LOG(WARNING) << "Authorization plugin: Registering Incoming HTTP Request Filter"; |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
922 |
1 | 923 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
924 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests); |
1 | 925 #else |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
926 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback); |
1 | 927 #endif |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
928 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
929 |
1 | 930 } |
931 else | |
932 { | |
71 | 933 LOG(WARNING) << "No section \"" << PLUGIN_SECTION << "\" in the configuration file, " |
1 | 934 << "the authorization plugin is disabled"; |
935 } | |
936 } | |
937 catch (Orthanc::OrthancException& e) | |
938 { | |
939 LOG(ERROR) << e.What(); | |
940 return -1; | |
941 } | |
942 | |
943 return 0; | |
944 } | |
945 | |
946 | |
947 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
948 { | |
949 authorizationParser_.reset(NULL); | |
950 } | |
951 | |
952 | |
953 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
954 { | |
955 return "authorization"; | |
956 } | |
957 | |
958 | |
959 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
960 { | |
22
c44013681a51
now using the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
961 return ORTHANC_PLUGIN_VERSION; |
1 | 962 } |
963 } |