Mercurial > hg > orthanc-authorization
annotate Plugin/CachedAuthorizationService.h @ 108:68ce6fd8b22a
contributing
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 Aug 2023 10:25:40 +0200 |
parents | aa73b10c2db9 |
children | 7381a7674b36 |
rev | line source |
---|---|
1 | 1 /** |
2 * Advanced authorization plugin for Orthanc | |
68 | 3 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
1 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 #pragma once | |
20 | |
71 | 21 #include "BaseAuthorizationService.h" |
1 | 22 #include "ICacheFactory.h" |
23 | |
36
8ada1b669194
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
24 #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
|
25 |
1 | 26 #include <memory> |
27 | |
28 namespace OrthancPlugins | |
29 { | |
30 /** | |
31 * Decorator design pattern to add a cache around an IAuthorizationService | |
32 **/ | |
71 | 33 class CachedAuthorizationService : public BaseAuthorizationService |
1 | 34 { |
35 private: | |
71 | 36 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
|
37 std::unique_ptr<ICache> cache_; |
1 | 38 |
39 std::string ComputeKey(OrthancPluginHttpMethod method, | |
40 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
|
41 const Token* token, |
1 | 42 const std::string& tokenValue) const; |
71 | 43 |
44 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
|
45 const Token* token, |
71 | 46 const std::string& tokenValue) const; |
47 | |
48 virtual bool IsGrantedInternal(unsigned int& validity, | |
49 OrthancPluginHttpMethod method, | |
50 const AccessedResource& access, | |
51 const Token* token, | |
52 const std::string& tokenValue) ORTHANC_OVERRIDE; | |
1 | 53 |
71 | 54 virtual bool GetUserProfileInternal(unsigned int& validity, |
55 Json::Value& profile /* out */, | |
56 const Token* token, | |
57 const std::string& tokenValue) ORTHANC_OVERRIDE; | |
58 | |
59 virtual bool HasUserPermissionInternal(unsigned int& validity, | |
60 const std::string& permission, | |
61 const Token* token, | |
62 const std::string& tokenValue) ORTHANC_OVERRIDE; | |
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 } |