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