Mercurial > hg > orthanc-authorization
annotate Plugin/Plugin.cpp @ 115:0eed78c1e177
cache the UserProfile + updated http filter logic
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 08 Sep 2023 09:52:21 +0200 |
parents | 546aea509427 |
children | 89eddd4b2f6a |
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> | |
111 | 30 #include <SerializationToolbox.h> |
71 | 31 #include <EmbeddedResources.h> |
1 | 32 |
33 | |
34 // 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
|
35 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
|
36 static std::unique_ptr<OrthancPlugins::IAuthorizationService> authorizationService_; |
71 | 37 static std::unique_ptr<OrthancPlugins::PermissionParser> permissionParser_; |
1 | 38 static std::set<std::string> uncheckedResources_; |
39 static std::list<std::string> uncheckedFolders_; | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
40 static std::set<OrthancPlugins::Token> tokens_; |
1 | 41 static std::set<OrthancPlugins::AccessLevel> uncheckedLevels_; |
42 | |
43 | |
71 | 44 static std::string JoinStrings(const std::set<std::string>& values) |
45 { | |
46 std::string out; | |
47 std::set<std::string> copy = values; // TODO: remove after upgrading to OrthancFramework 1.11.3+ | |
48 Orthanc::Toolbox::JoinStrings(out, copy, "|"); | |
49 return out; | |
50 } | |
51 | |
86 | 52 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
|
53 { |
86 | 54 private: |
55 OrthancPlugins::Token token_; | |
56 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
|
57 |
86 | 58 public: |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
59 TokenAndValue(const OrthancPlugins::Token& token, const std::string& value) : |
86 | 60 token_(token), |
61 value_(value) | |
62 { | |
63 } | |
64 | |
65 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
|
66 { |
86 | 67 return token_; |
68 } | |
69 | |
70 const std::string& GetValue() const | |
71 { | |
72 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
|
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 |
113 | 76 bool HasAccessToAllLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile) |
77 { | |
78 return (profile.authorizedLabels.find("*") != profile.authorizedLabels.end()); | |
79 } | |
80 | |
81 bool HasAccessToSomeLabels(const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
82 { | |
83 return (profile.authorizedLabels.size() > 0); | |
84 } | |
85 | |
86 | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
87 static bool CheckAuthorizedLabelsForResource(bool& granted, |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
88 const std::string& uri, |
113 | 89 const OrthancPlugins::AssociativeArray& getArguments, |
90 const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
91 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
92 granted = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
93 |
113 | 94 if (HasAccessToAllLabels(profile)) |
95 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
96 granted = true; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
97 return true; // we could check labels |
113 | 98 } |
99 | |
100 if (authorizationParser_.get() != NULL && | |
101 authorizationService_.get() != NULL) | |
102 { | |
103 // Parse the resources that are accessed through this URI | |
104 OrthancPlugins::IAuthorizationParser::AccessedResources accesses; | |
105 | |
106 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) | |
107 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
108 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
|
109 } |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
110 |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
111 if (authorizationParser_->IsListOfResources(uri)) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
112 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
113 granted = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
114 return true; // if a user does not have access to all labels, he can not have access to a list of resources |
113 | 115 } |
116 | |
117 // Loop over all the accessed resources to ensure access is | |
118 // granted to each of them | |
119 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator | |
120 access = accesses.begin(); access != accesses.end(); ++access) | |
121 { | |
122 // Ignored the access levels that are unchecked | |
123 // (cf. "UncheckedLevels" option) | |
124 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end()) | |
125 { | |
126 std::string msg = std::string("Testing whether access to ") + OrthancPlugins::EnumerationToString(access->GetLevel()) + " \"" + access->GetOrthancId() + "\" is allowed wrt Labels for User '" + profile.name + "'"; | |
127 const std::set<std::string>& resourceLabels = access->GetLabels(); | |
128 std::set<std::string> authorizedResourceLabels; | |
129 | |
130 Orthanc::Toolbox::GetIntersection(authorizedResourceLabels, resourceLabels, profile.authorizedLabels); | |
131 | |
132 if (authorizedResourceLabels.size() == 0) | |
133 { | |
134 LOG(INFO) << msg << " -> not granted, no authorized labels"; | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
135 return true; // we could check labels |
113 | 136 } |
137 else | |
138 { | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
139 granted = true; |
113 | 140 LOG(INFO) << msg << " -> granted, at least one authorized labels"; |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
141 return true; // we could check labels |
113 | 142 } |
143 } | |
144 } | |
145 } | |
146 | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
147 // 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
|
148 return false; // we could not check labels |
113 | 149 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
150 |
1 | 151 static int32_t FilterHttpRequests(OrthancPluginHttpMethod method, |
152 const char *uri, | |
153 const char *ip, | |
154 uint32_t headersCount, | |
155 const char *const *headersKeys, | |
156 const char *const *headersValues, | |
157 uint32_t getArgumentsCount, | |
158 const char *const *getArgumentsKeys, | |
159 const char *const *getArgumentsValues) | |
160 { | |
161 try | |
162 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
163 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
|
164 |
109 | 165 // Allow GET accesses to unchecked resources/folders (usually static resources) |
166 //////////////////////////////////////////////////////////////// | |
167 | |
1 | 168 if (method == OrthancPluginHttpMethod_Get) |
169 { | |
170 if (uncheckedResources_.find(uri) != uncheckedResources_.end()) | |
171 { | |
172 return 1; | |
173 } | |
174 | |
175 for (std::list<std::string>::const_iterator | |
176 it = uncheckedFolders_.begin(); it != uncheckedFolders_.end(); ++it) | |
177 { | |
178 if (Orthanc::Toolbox::StartsWith(uri, *it)) | |
179 { | |
180 return 1; | |
181 } | |
182 } | |
183 } | |
184 | |
109 | 185 // Extract auth tokens from headers and url get arguments |
186 //////////////////////////////////////////////////////////////// | |
187 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
188 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
|
189 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
|
190 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
191 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
|
192 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
193 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
|
194 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
195 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
|
196 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
197 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
|
198 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
|
199 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
200 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
|
201 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
|
202 break; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
203 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
204 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
|
205 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
|
206 break; |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
207 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
208 default: |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
209 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
|
210 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
211 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
212 if (hasValue) |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
213 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
214 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
|
215 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
216 } |
71 | 217 |
109 | 218 // Based on the tokens, check if the user has access based on its permissions and the mapping between urls and permissions |
219 //////////////////////////////////////////////////////////////// | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
220 bool hasUserRequiredPermissions = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
221 bool hasAuthorizedLabelsForResource = false; |
109 | 222 |
71 | 223 if (permissionParser_.get() != NULL && |
224 authorizationService_.get() != NULL) | |
225 { | |
226 std::set<std::string> requiredPermissions; | |
227 std::string matchedPattern; | |
228 if (permissionParser_->Parse(requiredPermissions, matchedPattern, method, uri)) | |
229 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
230 if (authTokens.empty()) |
71 | 231 { |
103 | 232 std::string msg = std::string("Testing whether anonymous user has any of the required permissions '") + JoinStrings(requiredPermissions) + "'"; |
113 | 233 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
234 LOG(INFO) << msg; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
235 if (authorizationService_->HasAnonymousUserPermission(validity, requiredPermissions)) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
236 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
237 LOG(INFO) << msg << " -> granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
238 hasUserRequiredPermissions = true; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
239 } |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
240 else |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
241 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
242 LOG(INFO) << msg << " -> not granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
243 hasUserRequiredPermissions = false; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
244 // 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
|
245 } |
71 | 246 } |
247 else | |
248 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
249 for (size_t i = 0; i < authTokens.size(); ++i) |
71 | 250 { |
103 | 251 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 + "'"; |
252 | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
253 // LOG(INFO) << msg; |
113 | 254 OrthancPlugins::IAuthorizationService::UserProfile profile; |
255 unsigned int validityNotUsed; | |
256 authorizationService_->GetUserProfile(validityNotUsed, profile, authTokens[i].GetToken(), authTokens[i].GetValue()); | |
257 | |
258 if (authorizationService_->HasUserPermission(validity, requiredPermissions, profile)) | |
71 | 259 { |
103 | 260 LOG(INFO) << msg << " -> granted"; |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
261 hasUserRequiredPermissions = true; |
113 | 262 |
263 // check labels permissions | |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
264 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
|
265 if (CheckAuthorizedLabelsForResource(hasAuthorizedLabelsForResource, uri, getArguments, profile)) |
113 | 266 { |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
267 if (hasAuthorizedLabelsForResource) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
268 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
269 LOG(INFO) << msg << " -> granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
270 } |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
271 else |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
272 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
273 LOG(INFO) << msg << " -> not granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
274 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
|
275 } |
113 | 276 } |
71 | 277 } |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
278 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
279 { |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
280 LOG(INFO) << msg << " -> not granted"; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
281 hasUserRequiredPermissions = false; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
282 } |
71 | 283 } |
284 } | |
285 } | |
286 } | |
109 | 287 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
288 // 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
|
289 if (hasUserRequiredPermissions) |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
290 { |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
291 return 1; |
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
292 } |
109 | 293 |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
294 // 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
|
295 //////////////////////////////////////////////////////////////// |
109 | 296 |
1 | 297 if (authorizationParser_.get() != NULL && |
298 authorizationService_.get() != NULL) | |
299 { | |
300 // Parse the resources that are accessed through this URI | |
301 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
|
302 |
57
55539d564f4f
added support for /dicom-web/series? & /dicom-web/instances?
Alain Mazy <am@osimis.io>
parents:
56
diff
changeset
|
303 if (!authorizationParser_->Parse(accesses, uri, getArguments.GetMap())) |
1 | 304 { |
305 return 0; // Unable to parse this URI | |
306 } | |
307 | |
308 // Loop over all the accessed resources to ensure access is | |
309 // granted to each of them | |
310 for (OrthancPlugins::IAuthorizationParser::AccessedResources::const_iterator | |
311 access = accesses.begin(); access != accesses.end(); ++access) | |
312 { | |
313 // Ignored the access levels that are unchecked | |
314 // (cf. "UncheckedLevels" option) | |
315 if (uncheckedLevels_.find(access->GetLevel()) == uncheckedLevels_.end()) | |
316 { | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
317 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
|
318 LOG(INFO) << msg; |
1 | 319 |
320 bool granted = false; | |
321 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
322 if (authTokens.empty()) |
1 | 323 { |
71 | 324 granted = authorizationService_->IsGrantedToAnonymousUser(validity, method, *access); |
1 | 325 } |
326 else | |
327 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
328 // 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
|
329 for (size_t i = 0; i < authTokens.size(); ++i) |
1 | 330 { |
86 | 331 if (authorizationService_->IsGranted(validity, method, *access, authTokens[i].GetToken(), authTokens[i].GetValue())) |
1 | 332 { |
333 granted = true; | |
334 break; | |
335 } | |
336 } | |
337 } | |
338 | |
339 if (!granted) | |
340 { | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
341 LOG(INFO) << msg << " -> not granted"; |
1 | 342 return 0; |
343 } | |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
344 else |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
345 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
346 LOG(INFO) << msg << " -> granted"; |
115
0eed78c1e177
cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents:
114
diff
changeset
|
347 return 1; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
348 } |
1 | 349 } |
350 } | |
351 } | |
352 | |
353 // By default, forbid access to all the resources | |
354 return 0; | |
355 } | |
356 catch (std::runtime_error& e) | |
357 { | |
358 LOG(ERROR) << e.what(); | |
359 return OrthancPluginErrorCode_Success; // Ignore error | |
360 } | |
361 catch (Orthanc::OrthancException& e) | |
362 { | |
363 LOG(ERROR) << e.What(); | |
364 return OrthancPluginErrorCode_Success; // Ignore error | |
365 } | |
366 catch (...) | |
367 { | |
368 LOG(ERROR) << "Unhandled internal exception"; | |
369 return OrthancPluginErrorCode_Success; // Ignore error | |
370 } | |
371 } | |
372 | |
373 | |
374 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) | |
375 static int32_t FilterHttpRequestsFallback(OrthancPluginHttpMethod method, | |
376 const char *uri, | |
377 const char *ip, | |
378 uint32_t headersCount, | |
379 const char *const *headersKeys, | |
380 const char *const *headersValues) | |
381 { | |
382 // Fallback wrapper function for Orthanc <= 1.2.0, where the GET | |
383 // arguments were not available in the HTTP filters | |
384 return FilterHttpRequests(method, uri, ip, | |
385 headersCount, headersKeys, headersValues, | |
386 0, NULL, NULL); | |
387 } | |
388 #endif | |
389 | |
390 | |
391 static OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, | |
392 OrthancPluginResourceType resourceType, | |
393 const char* resourceId) | |
394 { | |
395 try | |
396 { | |
397 if (authorizationParser_.get() == NULL) | |
398 { | |
71 | 399 return OrthancPluginErrorCode_Success; |
1 | 400 } |
401 | |
402 if (changeType == OrthancPluginChangeType_Deleted) | |
403 { | |
404 switch (resourceType) | |
405 { | |
406 case OrthancPluginResourceType_Patient: | |
407 authorizationParser_->Invalidate(Orthanc::ResourceType_Patient, resourceId); | |
408 break; | |
409 | |
410 case OrthancPluginResourceType_Study: | |
411 authorizationParser_->Invalidate(Orthanc::ResourceType_Study, resourceId); | |
412 break; | |
413 | |
414 case OrthancPluginResourceType_Series: | |
415 authorizationParser_->Invalidate(Orthanc::ResourceType_Series, resourceId); | |
416 break; | |
417 | |
418 case OrthancPluginResourceType_Instance: | |
419 authorizationParser_->Invalidate(Orthanc::ResourceType_Instance, resourceId); | |
420 break; | |
421 | |
422 default: | |
423 break; | |
424 } | |
425 } | |
426 | |
427 return OrthancPluginErrorCode_Success; | |
428 } | |
429 catch (std::runtime_error& e) | |
430 { | |
431 LOG(ERROR) << e.what(); | |
432 return OrthancPluginErrorCode_Success; // Ignore error | |
433 } | |
434 catch (Orthanc::OrthancException& e) | |
435 { | |
436 LOG(ERROR) << e.What(); | |
437 return OrthancPluginErrorCode_Success; // Ignore error | |
438 } | |
439 catch (...) | |
440 { | |
441 LOG(ERROR) << "Unhandled internal exception"; | |
442 return OrthancPluginErrorCode_Success; // Ignore error | |
443 } | |
444 } | |
445 | |
111 | 446 |
447 bool GetUserProfileInternal(OrthancPlugins::IAuthorizationService::UserProfile& profile, const OrthancPluginHttpRequest* request) | |
448 { | |
449 OrthancPlugins::AssociativeArray headers | |
450 (request->headersCount, request->headersKeys, request->headersValues, false); | |
451 | |
452 OrthancPlugins::AssociativeArray getArguments | |
453 (request->getCount, request->getKeys, request->getValues, true); | |
454 | |
455 // Loop over all the authorization tokens stored in the HTTP | |
456 // headers, until finding one that is granted | |
457 for (std::set<OrthancPlugins::Token>::const_iterator | |
458 token = tokens_.begin(); token != tokens_.end(); ++token) | |
459 { | |
460 OrthancPlugins::IAuthorizationService::UserProfile tryProfile; | |
461 | |
462 std::string value; | |
463 | |
464 bool hasValue = false; | |
465 switch (token->GetType()) | |
466 { | |
467 case OrthancPlugins::TokenType_HttpHeader: | |
468 hasValue = headers.GetValue(value, token->GetKey()); | |
469 break; | |
470 | |
471 case OrthancPlugins::TokenType_GetArgument: | |
472 hasValue = getArguments.GetValue(value, token->GetKey()); | |
473 break; | |
474 | |
475 default: | |
476 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
477 } | |
478 | |
479 if (hasValue) | |
480 { | |
481 unsigned int validity; // not used | |
482 if (authorizationService_->GetUserProfile(validity, tryProfile, *token, value)) | |
483 { | |
484 profile = tryProfile; | |
485 return true; | |
486 } | |
487 } | |
488 } | |
489 | |
490 return false; | |
491 } | |
492 | |
493 void AdjustToolsFindQueryLabels(Json::Value& query, const OrthancPlugins::IAuthorizationService::UserProfile& profile) | |
494 { | |
495 std::set<std::string> labelsToFind; | |
496 std::string labelsConstraint = "Invalid"; | |
497 | |
498 if (query.isMember("Labels") && query.isMember("LabelsConstraint")) | |
499 { | |
500 Orthanc::SerializationToolbox::ReadSetOfStrings(labelsToFind, query, "Labels"); | |
501 labelsConstraint = Orthanc::SerializationToolbox::ReadString(query, "LabelsConstraint"); | |
502 } | |
503 else if (query.isMember("Labels") || query.isMember("LabelsConstraint")) | |
504 { | |
114 | 505 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 | 506 } |
507 | |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
508 if (!HasAccessToSomeLabels(profile)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
509 { |
114 | 510 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
|
511 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
512 else if (profile.authorizedLabels.size() > 0) |
111 | 513 { |
514 // 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
|
515 if (!HasAccessToAllLabels(profile)) |
111 | 516 { // the user does not have access to all labels -> transform the tools/find body |
517 | |
518 if (labelsToFind.size() == 0) | |
519 { | |
520 if (profile.authorizedLabels.size() > 0) | |
521 { | |
114 | 522 query.removeMember("Labels"); |
111 | 523 Orthanc::SerializationToolbox::WriteSetOfStrings(query, profile.authorizedLabels, "Labels"); |
524 query["LabelsConstraint"] = "Any"; | |
525 } | |
526 } | |
527 else if (labelsConstraint == "All") | |
528 { | |
529 if (profile.authorizedLabels.size() > 0) | |
530 { | |
531 if (!Orthanc::Toolbox::IsSetInSet(labelsToFind, profile.authorizedLabels)) | |
532 { | |
114 | 533 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 | 534 } |
535 } | |
536 } | |
537 else if (labelsConstraint == "Any") | |
538 { | |
539 if (profile.authorizedLabels.size() > 0) | |
540 { | |
541 std::set<std::string> newLabelsToFind; | |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
542 Orthanc::Toolbox::GetIntersection(newLabelsToFind, labelsToFind, profile.authorizedLabels); |
111 | 543 |
544 if (newLabelsToFind.size() == 0) | |
545 { | |
114 | 546 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 | 547 } |
548 | |
549 query.removeMember("Labels"); | |
550 Orthanc::SerializationToolbox::WriteSetOfStrings(query, newLabelsToFind, "Labels"); | |
551 } | |
552 } | |
553 else if (labelsConstraint == "None") | |
554 { | |
555 if (profile.authorizedLabels.size() > 0) | |
556 { | |
114 | 557 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 | 558 } |
559 } | |
560 } | |
561 } | |
562 } | |
563 | |
564 void ToolsFind(OrthancPluginRestOutput* output, | |
565 const char* /*url*/, | |
566 const OrthancPluginHttpRequest* request) | |
567 { | |
568 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
569 | |
570 if (request->method != OrthancPluginHttpMethod_Post) | |
571 { | |
572 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
573 } | |
574 else | |
575 { | |
576 // The filtering to this route is performed by this plugin as it is done for any other route before we get here. | |
577 | |
578 Json::Value body; | |
579 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize)) | |
580 { | |
581 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); | |
582 } | |
583 | |
584 // If the logged in user has restrictions on the labels he can access, modify the tools/find payload before reposting it to Orthanc | |
585 OrthancPlugins::IAuthorizationService::UserProfile profile; | |
586 if (GetUserProfileInternal(profile, request)) | |
587 { | |
588 AdjustToolsFindQueryLabels(body, profile); | |
589 | |
590 Json::Value result; | |
591 if (OrthancPlugins::RestApiPost(result, "/tools/find", body, false)) | |
592 { | |
593 OrthancPlugins::AnswerJson(result, output); | |
594 } | |
595 | |
596 } | |
597 else | |
598 { | |
114 | 599 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: no user profile found, access to tools/find is forbidden."); |
111 | 600 } |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
601 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
602 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
603 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
604 void ToolsLabels(OrthancPluginRestOutput* output, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
605 const char* /*url*/, |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
606 const OrthancPluginHttpRequest* request) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
607 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
608 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
609 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
610 if (request->method != OrthancPluginHttpMethod_Get) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
611 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
612 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
613 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
614 else |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
615 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
616 // The filtering to this route is performed by this plugin as it is done for any other route before we get here. |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
617 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
618 // If the logged in user has restrictions on the labels he can access, modify the tools/labels response before answering |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
619 OrthancPlugins::IAuthorizationService::UserProfile profile; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
620 if (GetUserProfileInternal(profile, request)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
621 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
622 if (!HasAccessToSomeLabels(profile)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
623 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
624 Json::Value emptyLabels; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
625 OrthancPlugins::AnswerJson(emptyLabels, output); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
626 return; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
627 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
628 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
629 Json::Value jsonLabels; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
630 if (OrthancPlugins::RestApiGet(jsonLabels, "/tools/labels", false)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
631 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
632 std::set<std::string> allLabels; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
633 Orthanc::SerializationToolbox::ReadSetOfStrings(allLabels, jsonLabels); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
634 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
635 if (!HasAccessToAllLabels(profile)) |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
636 { |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
637 std::set<std::string> authorizedLabels; |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
638 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
639 Orthanc::Toolbox::GetIntersection(authorizedLabels, allLabels, profile.authorizedLabels); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
640 Orthanc::SerializationToolbox::WriteSetOfStrings(jsonLabels, authorizedLabels); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
641 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
642 OrthancPlugins::AnswerJson(jsonLabels, output); |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
643 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
644 |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
645 } |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
646 else |
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
647 { |
114 | 648 throw Orthanc::OrthancException(Orthanc::ErrorCode_ForbiddenAccess, "Auth plugin: no user profile found, access to tools/labels is forbidden."); |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
649 } |
111 | 650 } |
651 } | |
652 | |
653 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
658 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
|
659 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
660 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
|
661 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
662 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
|
663 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
664 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
665 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
666 // 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
|
667 // 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
|
668 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
669 // 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
|
670 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
|
671 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
|
672 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
673 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
|
674 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
675 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
676 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
677 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
|
678 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
679 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
680 // 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
|
681 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
|
682 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
|
683 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
684 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
|
685 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
686 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
687 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
|
688 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
|
689 std::string expirationDateString; |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
690 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
|
691 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
692 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
|
693 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
694 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
|
695 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
696 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
697 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
|
698 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
699 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
|
700 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
|
701 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
702 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
|
703 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
704 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
|
705 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
706 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
707 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
|
708 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
709 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
|
710 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
711 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
712 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
|
713 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
714 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
|
715 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
716 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
717 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
|
718 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
|
719 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
720 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
721 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
|
722 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
723 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
|
724 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
725 |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
726 if (body.isMember("ValidityDuration")) |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
727 { |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
728 validityDuration = body["ValidityDuration"].asUInt64(); |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
729 } |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
730 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
731 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
|
732 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
|
733 tokenType, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
734 id, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
735 resources, |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
736 expirationDateString, |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
737 validityDuration)) |
72
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 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
|
740 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
|
741 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
742 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
|
743 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
744 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
|
745 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
746 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
747 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
748 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
|
749 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
750 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
751 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
|
752 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
753 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
754 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
755 } |
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 |
74 | 758 void DecodeToken(OrthancPluginRestOutput* output, |
759 const char* /*url*/, | |
760 const OrthancPluginHttpRequest* request) | |
761 { | |
762 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
763 | |
764 if (request->method != OrthancPluginHttpMethod_Post) | |
765 { | |
766 OrthancPluginSendMethodNotAllowed(context, output, "POST"); | |
767 } | |
768 else | |
769 { | |
770 // convert from Orthanc flavored API to WebService API | |
771 Json::Value body; | |
772 if (!OrthancPlugins::ReadJson(body, request->body, request->bodySize)) | |
773 { | |
774 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "A JSON payload was expected"); | |
775 } | |
776 | |
777 Json::Value authPayload; | |
778 | |
779 authPayload["token-key"] = body["TokenKey"].asString(); | |
780 authPayload["token-value"] = body["TokenValue"].asString(); | |
781 | |
782 OrthancPlugins::IAuthorizationService::DecodedToken decodedToken; | |
783 if (authorizationService_->DecodeToken(decodedToken, | |
784 body["TokenKey"].asString(), | |
785 body["TokenValue"].asString())) | |
786 { | |
787 Json::Value decodedJsonToken; | |
788 | |
789 if (!decodedToken.redirectUrl.empty()) | |
790 { | |
791 decodedJsonToken["RedirectUrl"] = decodedToken.redirectUrl; | |
792 } | |
793 | |
794 if (!decodedToken.errorCode.empty()) | |
795 { | |
796 decodedJsonToken["ErrorCode"] = decodedToken.errorCode; | |
797 } | |
798 | |
799 if (!decodedToken.tokenType.empty()) | |
800 { | |
801 decodedJsonToken["TokenType"] = decodedToken.tokenType; | |
802 } | |
803 | |
804 OrthancPlugins::AnswerJson(decodedJsonToken, output); | |
805 } | |
806 } | |
807 } | |
808 | |
111 | 809 |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
810 void GetUserProfile(OrthancPluginRestOutput* output, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
811 const char* /*url*/, |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
812 const OrthancPluginHttpRequest* request) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
813 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
814 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
815 |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
816 if (request->method != OrthancPluginHttpMethod_Get) |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
817 { |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
818 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
819 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
820 else |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
821 { |
111 | 822 OrthancPlugins::IAuthorizationService::UserProfile profile; |
823 if (GetUserProfileInternal(profile, request)) | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
824 { |
111 | 825 Json::Value jsonProfile; |
826 jsonProfile["name"] = profile.name; | |
827 jsonProfile["permissions"] = Json::arrayValue; | |
828 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
|
829 { |
111 | 830 jsonProfile["permissions"].append(*it); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
831 } |
111 | 832 for (std::set<std::string>::const_iterator it = profile.authorizedLabels.begin(); it != profile.authorizedLabels.end(); ++it) |
833 { | |
834 jsonProfile["authorized-labels"].append(*it); | |
835 } | |
109 | 836 |
111 | 837 OrthancPlugins::AnswerJson(jsonProfile, output); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
838 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
839 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
840 } |
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
841 |
71 | 842 void MergeJson(Json::Value &a, const Json::Value &b) { |
843 | |
844 if (!a.isObject() || !b.isObject()) | |
845 { | |
846 return; | |
847 } | |
848 | |
849 Json::Value::Members members = b.getMemberNames(); | |
850 | |
851 for (size_t i = 0; i < members.size(); i++) | |
852 { | |
853 std::string key = members[i]; | |
854 | |
855 if (!a[key].isNull() && a[key].type() == Json::objectValue && b[key].type() == Json::objectValue) | |
856 { | |
857 MergeJson(a[key], b[key]); | |
858 } | |
859 else | |
860 { | |
861 a[key] = b[key]; | |
862 } | |
863 } | |
864 } | |
865 | |
1 | 866 |
867 extern "C" | |
868 { | |
869 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
870 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
871 OrthancPlugins::SetGlobalContext(context); |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
872 OrthancPluginLogWarning(context, "Initializing the authorization plugin"); |
1 | 873 |
874 /* 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
|
875 if (OrthancPluginCheckVersion(context) == 0) |
1 | 876 { |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
877 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
1 | 878 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
879 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
880 return -1; | |
881 } | |
882 | |
41 | 883 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
32 | 884 Orthanc::Logging::InitializePluginContext(context); |
33
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
885 #else |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
886 Orthanc::Logging::Initialize(context); |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
887 #endif |
b9c536bf598b
improved Orthanc::Logging::Initialize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
32
diff
changeset
|
888 |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
889 OrthancPluginSetDescription(context, "Advanced authorization plugin for Orthanc."); |
1 | 890 |
891 try | |
892 { | |
71 | 893 static const char* PLUGIN_SECTION = "Authorization"; |
894 | |
895 OrthancPlugins::OrthancConfiguration orthancFullConfiguration; | |
896 | |
897 // read default configuration | |
898 std::string defaultConfigurationFileContent; | |
899 Orthanc::EmbeddedResources::GetFileResource(defaultConfigurationFileContent, Orthanc::EmbeddedResources::DEFAULT_CONFIGURATION); | |
900 Json::Value pluginJsonDefaultConfiguration; | |
901 OrthancPlugins::ReadJsonWithoutComments(pluginJsonDefaultConfiguration, defaultConfigurationFileContent); | |
902 Json::Value pluginJsonConfiguration = pluginJsonDefaultConfiguration[PLUGIN_SECTION]; | |
1 | 903 |
71 | 904 OrthancPlugins::OrthancConfiguration pluginProvidedConfiguration; |
905 | |
906 if (orthancFullConfiguration.IsSection(PLUGIN_SECTION)) | |
1 | 907 { |
71 | 908 // get the configuration provided by the user |
909 orthancFullConfiguration.GetSection(pluginProvidedConfiguration, PLUGIN_SECTION); | |
910 | |
911 // merge it with the default configuration. This is a way to apply the all default values in a single step | |
912 MergeJson(pluginJsonConfiguration, pluginProvidedConfiguration.GetJson()); | |
913 | |
914 // recreate a OrthancConfiguration object from the merged configuration | |
915 OrthancPlugins::OrthancConfiguration pluginConfiguration(pluginJsonConfiguration, PLUGIN_SECTION); | |
1 | 916 |
917 // TODO - The size of the caches is set to 10,000 items. Maybe add a configuration option? | |
918 OrthancPlugins::MemoryCache::Factory factory(10000); | |
919 | |
71 | 920 std::string dicomWebRoot = "/dicom-web/"; |
921 std::string oe2Root = "/ui/"; | |
1 | 922 |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
923 bool hasBasicAuthEnabled = orthancFullConfiguration.GetBooleanValue("AuthenticationEnabled", "true"); |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
924 |
71 | 925 if (orthancFullConfiguration.IsSection("DicomWeb")) |
926 { | |
927 OrthancPlugins::OrthancConfiguration dicomWeb; | |
928 dicomWeb.GetSection(orthancFullConfiguration, "DicomWeb"); | |
929 dicomWebRoot = dicomWeb.GetStringValue("Root", "/dicom-web/"); | |
930 } | |
1 | 931 |
71 | 932 if (orthancFullConfiguration.IsSection("OrthancExplorer2")) |
933 { | |
934 OrthancPlugins::OrthancConfiguration oe2; | |
935 oe2.GetSection(orthancFullConfiguration, "OrthancExplorer2"); | |
936 oe2Root = oe2.GetStringValue("Root", "/ui/"); | |
1 | 937 } |
938 | |
939 std::list<std::string> tmp; | |
940 | |
71 | 941 pluginConfiguration.LookupListOfStrings(tmp, "TokenHttpHeaders", true); |
1 | 942 for (std::list<std::string>::const_iterator |
943 it = tmp.begin(); it != tmp.end(); ++it) | |
944 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
945 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, *it)); |
1 | 946 } |
947 | |
71 | 948 pluginConfiguration.LookupListOfStrings(tmp, "TokenGetArguments", true); |
1 | 949 |
8
4362026afddf
orthanc 1.2.1 renamed as 1.3.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1
diff
changeset
|
950 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 3, 0) |
1 | 951 for (std::list<std::string>::const_iterator |
952 it = tmp.begin(); it != tmp.end(); ++it) | |
953 { | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
954 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it)); |
1 | 955 } |
956 #else | |
957 if (!tmp.empty()) | |
958 { | |
29
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
959 throw Orthanc::OrthancException( |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
960 Orthanc::ErrorCode_Plugin, |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
961 "The option \"TokenGetArguments\" of the authorization plugin " |
bc0431cb6b8f
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
22
diff
changeset
|
962 "is only valid if compiled against Orthanc >= 1.3.0" |
1 | 963 } |
964 #endif | |
965 | |
71 | 966 pluginConfiguration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false); |
967 pluginConfiguration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false); | |
1 | 968 |
74 | 969 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
|
970 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
|
971 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
|
972 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
|
973 std::string urlRoot; |
1 | 974 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
975 static const char* WEB_SERVICE_ROOT = "WebServiceRootUrl"; |
74 | 976 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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 if (pluginConfiguration.LookupStringValue(urlRoot, WEB_SERVICE_ROOT)) |
71 | 982 { |
74 | 983 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
|
984 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
|
985 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
|
986 urlUserProfile = Orthanc::Toolbox::JoinUri(urlRoot, "/user/get-profile"); |
71 | 987 } |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
988 else |
71 | 989 { |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
990 pluginConfiguration.LookupStringValue(urlTokenValidation, WEB_SERVICE_TOKEN_VALIDATION); |
74 | 991 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
|
992 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
|
993 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
994 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
|
995 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
996 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
997 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
|
998 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
|
999 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1000 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1001 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
|
1002 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1003 LOG(WARNING) << "Authorization plugin: url defined for Token Validation: " << urlTokenValidation; |
71 | 1004 authorizationParser_.reset |
1005 (new OrthancPlugins::DefaultAuthorizationParser(factory, dicomWebRoot)); | |
1006 } | |
1007 else | |
1008 { | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1009 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
|
1010 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1011 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1012 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
|
1013 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1014 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
|
1015 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1016 static const char* PERMISSIONS = "Permissions"; |
71 | 1017 if (!pluginConfiguration.GetJson().isMember(PERMISSIONS)) |
1018 { | |
1019 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
|
1020 "\" option since you have defined the \"" + std::string(WEB_SERVICE_ROOT) + "\" option"); |
71 | 1021 } |
1022 permissionParser_.reset | |
1023 (new OrthancPlugins::PermissionParser(dicomWebRoot, oe2Root)); | |
1024 | |
1025 permissionParser_->Add(pluginConfiguration.GetJson()[PERMISSIONS]); | |
1026 } | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1027 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1028 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1029 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
|
1030 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1031 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1032 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
|
1033 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1034 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
|
1035 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1036 else |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1037 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1038 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
|
1039 } |
71 | 1040 |
1041 if (authorizationParser_.get() == NULL && permissionParser_.get() == NULL) | |
1042 { | |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1043 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1044 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1045 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
|
1046 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1047 else |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1048 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1049 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
|
1050 } |
1 | 1051 } |
1052 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1053 std::set<std::string> standardConfigurations; |
71 | 1054 if (pluginConfiguration.LookupSetOfStrings(standardConfigurations, "StandardConfigurations", false)) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1055 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1056 if (standardConfigurations.find("osimis-web-viewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1057 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1058 uncheckedFolders_.push_back("/osimis-viewer/app/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1059 uncheckedFolders_.push_back("/osimis-viewer/languages/"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1060 uncheckedResources_.insert("/osimis-viewer/config.js"); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1061 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1062 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
|
1063 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
|
1064 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1065 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1066 if (standardConfigurations.find("stone-webviewer") != standardConfigurations.end()) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1067 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1068 uncheckedFolders_.push_back("/stone-webviewer/"); |
65 | 1069 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
|
1070 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1071 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1072 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1073 |
65 | 1074 if (standardConfigurations.find("orthanc-explorer-2") != standardConfigurations.end()) |
1075 { | |
1076 uncheckedFolders_.push_back("/ui/app/"); | |
74 | 1077 uncheckedFolders_.push_back("/ui/landing/"); |
76 | 1078 uncheckedResources_.insert("/"); // for the redirect to /ui/app/ |
66 | 1079 uncheckedResources_.insert("/ui/api/pre-login-configuration"); // for the UI to know, i.e. if Keycloak is enabled or not |
71 | 1080 uncheckedResources_.insert("/ui/api/configuration"); |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
1081 uncheckedResources_.insert("/auth/user-profile"); |
65 | 1082 |
1083 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_HttpHeader, "Authorization")); // for basic-auth | |
1084 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
|
1085 tokens_.insert(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, "token")); // for download links in OE2 |
65 | 1086 } |
1087 | |
102 | 1088 if (standardConfigurations.find("ohif") != standardConfigurations.end()) |
1089 { | |
1090 uncheckedFolders_.push_back("/ohif/"); | |
1091 } | |
1092 | |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1093 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1094 |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1095 std::string checkedLevelString; |
71 | 1096 if (pluginConfiguration.LookupStringValue(checkedLevelString, "CheckedLevel")) |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1097 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1098 OrthancPlugins::AccessLevel checkedLevel = OrthancPlugins::StringToAccessLevel(checkedLevelString); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1099 if (checkedLevel == OrthancPlugins::AccessLevel_Instance) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1100 { |
113 | 1101 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1102 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1103 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1104 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1105 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1106 else if (checkedLevel == OrthancPlugins::AccessLevel_Series) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1107 { |
113 | 1108 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1109 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1110 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1111 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1112 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1113 else if (checkedLevel == OrthancPlugins::AccessLevel_Study) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1114 { |
113 | 1115 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1116 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Patient); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1117 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1118 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1119 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1120 else if (checkedLevel == OrthancPlugins::AccessLevel_Patient) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1121 { |
113 | 1122 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_System); |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1123 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Study); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1124 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Series); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1125 uncheckedLevels_.insert(OrthancPlugins::AccessLevel_Instance); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1126 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1127 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1128 |
71 | 1129 if (pluginConfiguration.LookupListOfStrings(tmp, "UncheckedLevels", false)) |
1 | 1130 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1131 if (uncheckedLevels_.size() == 0) |
1 | 1132 { |
58
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1133 for (std::list<std::string>::const_iterator |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1134 it = tmp.begin(); it != tmp.end(); ++it) |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1135 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1136 uncheckedLevels_.insert(OrthancPlugins::StringToAccessLevel(*it)); |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1137 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1138 } |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1139 else |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1140 { |
ad279c70c22d
added a new configuration 'StandardConfigurations'
Alain Mazy <am@osimis.io>
parents:
57
diff
changeset
|
1141 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
|
1142 return -1; |
1 | 1143 } |
1144 } | |
1145 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1146 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
|
1147 urlTokenCreationBase, |
74 | 1148 urlUserProfile, |
1149 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
|
1150 |
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
|
1151 std::string webServiceIdentifier; |
71 | 1152 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
|
1153 { |
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
|
1154 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
|
1155 } |
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
|
1156 |
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
|
1157 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
|
1158 std::string webServicePassword; |
71 | 1159 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
|
1160 { |
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
|
1161 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
|
1162 } |
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
|
1163 |
1 | 1164 authorizationService_.reset |
1165 (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
|
1166 (webService.release(), factory)); |
1 | 1167 |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1168 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
|
1169 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1170 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
|
1171 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1172 |
74 | 1173 if (!urlTokenDecoder.empty()) |
1174 { | |
1175 OrthancPlugins::RegisterRestCallback<DecodeToken>("/auth/tokens/decode", true); | |
1176 } | |
1177 | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1178 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
|
1179 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1180 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
|
1181 } |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1182 |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1183 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
|
1184 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
1185 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
|
1186 } |
74 | 1187 |
111 | 1188 OrthancPlugins::RegisterRestCallback<ToolsFind>("/tools/find", true); |
112
572955904411
added tools/labels + removed forbidden_labels
Alain Mazy <am@osimis.io>
parents:
111
diff
changeset
|
1189 OrthancPlugins::RegisterRestCallback<ToolsLabels>("/tools/labels", true); |
111 | 1190 |
74 | 1191 |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1192 if (authorizationParser_.get() != NULL || permissionParser_.get() != NULL) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1193 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1194 if (hasBasicAuthEnabled) |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1195 { |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1196 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
|
1197 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1198 |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1199 LOG(WARNING) << "Authorization plugin: Registering Incoming HTTP Request Filter"; |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1200 |
1 | 1201 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1202 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests); |
1 | 1203 #else |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1204 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback); |
1 | 1205 #endif |
81
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1206 } |
fac45493d547
more flexibility wrt configuration
Alain Mazy <am@osimis.io>
parents:
77
diff
changeset
|
1207 |
1 | 1208 } |
1209 else | |
1210 { | |
71 | 1211 LOG(WARNING) << "No section \"" << PLUGIN_SECTION << "\" in the configuration file, " |
1 | 1212 << "the authorization plugin is disabled"; |
1213 } | |
1214 } | |
1215 catch (Orthanc::OrthancException& e) | |
1216 { | |
1217 LOG(ERROR) << e.What(); | |
1218 return -1; | |
1219 } | |
1220 | |
1221 return 0; | |
1222 } | |
1223 | |
1224 | |
1225 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
1226 { | |
1227 authorizationParser_.reset(NULL); | |
1228 } | |
1229 | |
1230 | |
1231 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
1232 { | |
1233 return "authorization"; | |
1234 } | |
1235 | |
1236 | |
1237 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
1238 { | |
22
c44013681a51
now using the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
8
diff
changeset
|
1239 return ORTHANC_PLUGIN_VERSION; |
1 | 1240 } |
1241 } |