annotate Plugin/AuthorizationWebService.h @ 188:c4b908970ae4

updated copyright, as Orthanc Team now replaces Osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 21:59:01 +0200
parents 9be1ee2b8fe1
children de232f9b3a60 85859ec3aa7e
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: 54
diff changeset
3 * Copyright (C) 2017-2023 Osimis S.A., Belgium
150
Alain Mazy <am@osimis.io>
parents: 115
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
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
23 #include "BaseAuthorizationService.h"
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
24 #include <Compatibility.h>
1
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 namespace OrthancPlugins
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
28 class AuthorizationWebService : public BaseAuthorizationService
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 private:
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 std::string username_;
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 std::string password_;
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: 46
diff changeset
33 std::string identifier_;
69
af44dce56328 new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents: 68
diff changeset
34 std::string userProfileUrl_;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
35 std::string tokenValidationUrl_;
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
36 std::string tokenDecoderUrl_;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
37 std::string tokenCreationBaseUrl_;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
39 protected:
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
40 virtual bool IsGrantedInternal(unsigned int& validity,
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 OrthancPluginHttpMethod method,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 const AccessedResource& access,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 const Token* token,
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
44 const std::string& tokenValue) ORTHANC_OVERRIDE;
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
46 virtual bool GetUserProfileInternal(unsigned int& validity,
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
47 UserProfile& profile /* out */,
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
48 const Token* token,
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
49 const std::string& tokenValue) ORTHANC_OVERRIDE;
71
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 virtual bool HasUserPermissionInternal(unsigned int& validity,
113
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
52 const std::string& permission,
43154740ea2e wip: checking labels
Alain Mazy <am@osimis.io>
parents: 109
diff changeset
53 const UserProfile& profile) ORTHANC_OVERRIDE;
71
30fb3ce960d9 configurable user permissions
Alain Mazy <am@osimis.io>
parents: 69
diff changeset
54
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 public:
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
56 AuthorizationWebService(const std::string& tokenValidationUrl,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
57 const std::string& tokenCreationBaseUrl,
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
58 const std::string& userProfileUrl,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
59 const std::string& tokenDecoderUrl) :
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
60 userProfileUrl_(userProfileUrl),
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
61 tokenValidationUrl_(tokenValidationUrl),
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
62 tokenDecoderUrl_(tokenDecoderUrl),
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
63 tokenCreationBaseUrl_(tokenCreationBaseUrl)
29
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
64 {
bc0431cb6b8f fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
65 }
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 void SetCredentials(const std::string& username,
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const std::string& password);
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
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: 46
diff changeset
70 void SetIdentifier(const std::string& 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: 46
diff changeset
71
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
72 virtual bool HasUserProfile() const
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 return !userProfileUrl_.empty();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
75 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
76
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
77 virtual bool HasCreateToken() const
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
78 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
79 return !tokenCreationBaseUrl_.empty();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
80 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
81
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
82 virtual bool HasTokenValidation() const
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
83 {
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
84 return !tokenValidationUrl_.empty();
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
85 }
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
86
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
87 virtual bool CreateToken(IAuthorizationService::CreatedToken& response,
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
88 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
89 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
90 const std::vector<IAuthorizationService::OrthancResource>& resources,
73
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
91 const std::string& expirationDateString,
512247750f0a new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents: 72
diff changeset
92 const uint64_t& validityDuration) ORTHANC_OVERRIDE;
72
e381ba725669 new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents: 71
diff changeset
93
74
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
94 virtual bool DecodeToken(DecodedToken& response,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
95 const std::string& tokenKey,
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
96 const std::string& tokenValue);
aa73b10c2db9 new API route to decode tokens
Alain Mazy <am@osimis.io>
parents: 73
diff changeset
97
115
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
98 static void ToJson(Json::Value& output, const UserProfile& profile);
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
99
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
100 static void FromJson(UserProfile& profile, const Json::Value& input);
0eed78c1e177 cache the UserProfile + updated http filter logic
Alain Mazy <am@osimis.io>
parents: 113
diff changeset
101
1
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 };
d5d3cb00556a initial release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }