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