annotate Plugin/IAuthorizationService.h @ 201:8c79c3b026ce default tip

back to mainline
author Alain Mazy <am@orthanc.team>
date Wed, 03 Jul 2024 09:00:01 +0200
parents 85859ec3aa7e
children
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: 46
diff changeset
3 * Copyright (C) 2017-2023 Osimis S.A., Belgium
150
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
188
c4b908970ae4 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 150
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * 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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #pragma once
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "AccessedResource.h"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "Token.h"
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <orthanc/OrthancCPlugin.h>
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <boost/noncopyable.hpp>
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
28 #include <json/json.h>
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
29 #include <set>
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancPlugins
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 // NOTE: This interface must be thread-safe
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 class IAuthorizationService : public boost::noncopyable
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 public:
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
37 struct OrthancResource
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
38 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
39 std::string dicomUid;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
40 std::string orthancId;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
41 std::string url;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
42 std::string level;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
43 };
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
44
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
45 struct CreatedToken
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
46 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
47 std::string url;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
48 std::string token;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
49 };
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
50
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
51 struct DecodedToken
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
52 {
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
53 std::string redirectUrl;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
54 std::string errorCode;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
55 std::string tokenType;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
56 };
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
57
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
58 struct UserProfile
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
59 {
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
60 std::string name;
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
61 std::set<std::string> permissions;
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
62 std::set<std::string> authorizedLabels;
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
63
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
64 // the source token key/value that identified the user
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
65 TokenType tokenType;
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
66 std::string tokenKey;
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
67 std::string tokenValue;
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
68 };
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
69
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 virtual ~IAuthorizationService()
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 virtual bool IsGranted(unsigned int& validity /* out */,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 OrthancPluginHttpMethod method,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 const AccessedResource& access,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 const Token& token,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 const std::string& tokenValue) = 0;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
80 virtual bool IsGrantedToAnonymousUser(unsigned int& validity /* out */,
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
81 OrthancPluginHttpMethod method,
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
82 const AccessedResource& access) = 0;
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
83
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
84 virtual bool GetUserProfile(unsigned int& validity /* out */,
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
85 UserProfile& profile /* out */,
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
86 const Token& token,
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
87 const std::string& tokenValue) = 0;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
88
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
89 virtual bool GetAnonymousUserProfile(unsigned int& validity /* out */,
109
7381a7674b36 wip: adding labels
Alain Mazy <am@osimis.io>
parents: 74
diff changeset
90 UserProfile& profile /* out */) = 0;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
91
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
92 virtual bool HasUserPermission(unsigned int& validity /* out */,
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
93 const std::set<std::string>& anyOfPermissions,
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 112
diff changeset
94 const UserProfile& profile) = 0;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
95
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
96 virtual bool HasAnonymousUserPermission(unsigned int& validity /* out */,
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
97 const std::set<std::string>& anyOfPermissions) = 0;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
98
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
99 virtual bool CreateToken(CreatedToken& response,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
100 const 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
101 const 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
102 const std::vector<OrthancResource>& resources,
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
103 const std::string& expirationDateString,
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
104 const uint64_t& validityDuration) = 0;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
105
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
106 virtual bool DecodeToken(DecodedToken& response,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
107 const std::string& tokenKey,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
108 const std::string& tokenValue) = 0;
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
109
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
110 virtual bool HasUserProfile() const = 0;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
111 virtual bool HasCreateToken() const = 0;
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
112 virtual bool HasTokenValidation() const = 0;
194
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
113
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
114 virtual bool GetSettingsRoles(Json::Value& roles) = 0;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
115 virtual bool UpdateSettingsRoles(Json::Value& response,
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
116 const Json::Value& roles) = 0;
85859ec3aa7e added support for roles/permissions edition
Alain Mazy <am@orthanc.team>
parents: 188
diff changeset
117
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 };
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }