annotate Plugin/Plugin.cpp @ 116:89eddd4b2f6a

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