Mercurial > hg > orthanc-authorization
annotate Plugin/CachedAuthorizationService.h @ 190:de232f9b3a60
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 15:08:41 +0200 |
parents | c4b908970ae4 |
children | 2f1e872e8eaa |
rev | line source |
---|---|
1 | 1 /** |
2 * Advanced authorization plugin for Orthanc | |
68 | 3 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
150 | 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 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #pragma once | |
22 | |
71 | 23 #include "BaseAuthorizationService.h" |
1 | 24 #include "ICacheFactory.h" |
25 | |
36
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
26 #include <Compatibility.h> // For std::unique_ptr<> |
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
27 |
1 | 28 #include <memory> |
29 | |
30 namespace OrthancPlugins | |
31 { | |
32 /** | |
33 * Decorator design pattern to add a cache around an IAuthorizationService | |
34 **/ | |
71 | 35 class CachedAuthorizationService : public BaseAuthorizationService |
1 | 36 { |
37 private: | |
71 | 38 std::unique_ptr<BaseAuthorizationService> decorated_; |
36
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
39 std::unique_ptr<ICache> cache_; |
1 | 40 |
41 std::string ComputeKey(OrthancPluginHttpMethod method, | |
42 const AccessedResource& access, | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
43 const Token* token, |
1 | 44 const std::string& tokenValue) const; |
71 | 45 |
46 std::string ComputeKey(const std::string& permission, | |
72
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
47 const Token* token, |
71 | 48 const std::string& tokenValue) const; |
49 | |
50 virtual bool IsGrantedInternal(unsigned int& validity, | |
51 OrthancPluginHttpMethod method, | |
52 const AccessedResource& access, | |
53 const Token* token, | |
54 const std::string& tokenValue) ORTHANC_OVERRIDE; | |
1 | 55 |
71 | 56 virtual bool GetUserProfileInternal(unsigned int& validity, |
109 | 57 UserProfile& profile /* out */, |
71 | 58 const Token* token, |
59 const std::string& tokenValue) ORTHANC_OVERRIDE; | |
60 | |
61 virtual bool HasUserPermissionInternal(unsigned int& validity, | |
62 const std::string& permission, | |
113 | 63 const UserProfile& profile) ORTHANC_OVERRIDE; |
71 | 64 |
65 | |
1 | 66 public: |
71 | 67 CachedAuthorizationService(BaseAuthorizationService* decorated /* takes ownership */, |
1 | 68 ICacheFactory& factory); |
69 | |
190 | 70 virtual bool HasUserProfile() const 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
|
71 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
72 return decorated_->HasUserProfile(); |
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 |
190 | 75 virtual bool HasCreateToken() const 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
|
76 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
77 return decorated_->HasCreateToken(); |
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 |
190 | 80 virtual bool HasTokenValidation() const 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
|
81 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
82 return decorated_->HasTokenValidation(); |
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 |
74 | 85 virtual bool CreateToken(IAuthorizationService::CreatedToken& response, |
86 const std::string& tokenType, | |
87 const std::string& id, | |
88 const std::vector<IAuthorizationService::OrthancResource>& resources, | |
89 const std::string& expirationDateString, | |
190 | 90 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
|
91 { |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
92 return decorated_->CreateToken(response, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
93 tokenType, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
94 id, |
e381ba725669
new PUT auth/tokens/{token-type} API route + updated interface with WebService
Alain Mazy <am@osimis.io>
parents:
71
diff
changeset
|
95 resources, |
73
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
96 expirationDateString, |
512247750f0a
new ValidityDuration arg in create token API
Alain Mazy <am@osimis.io>
parents:
72
diff
changeset
|
97 validityDuration); |
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 |
74 | 100 virtual bool DecodeToken(DecodedToken& response, |
101 const std::string& tokenKey, | |
190 | 102 const std::string& tokenValue) ORTHANC_OVERRIDE |
74 | 103 { |
104 return decorated_->DecodeToken(response, | |
105 tokenKey, | |
106 tokenValue); | |
107 } | |
108 | |
69
af44dce56328
new 'auth/user-profile' Rest API route
Alain Mazy <am@osimis.io>
parents:
68
diff
changeset
|
109 }; |
1 | 110 } |