RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
PolicyDescriptor.h
1 /*
2  * ======================================================================
3  * Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
4  * Licensed under the MIT License.
5  * See LICENSE.md in the project root for license information.
6  * ======================================================================
7  */
8 
9 #ifndef _RMS_LIB_POLICYDESCRIPTOR_H_
10 #define _RMS_LIB_POLICYDESCRIPTOR_H_
11 
12 #include <chrono>
13 #include <unordered_map>
14 #include <memory>
15 #include <string>
16 
17 #include "ModernAPIExport.h"
18 
19 #include "UserRoles.h"
20 #include "UserRights.h"
21 
22 namespace rmscore {
23 namespace core {
24 class ProtectionPolicy;
25 }
26 
27 namespace modernapi {
28 
30 namespace detail {
31 struct HashConstString
32 {
33  long operator()(const std::string& str) const {
34  return static_cast<long>(std::hash<std::string>()(str));
35  }
36 };
37 
38 template<typename T>
39 using HashMapString = std::unordered_map<std::string, T, HashConstString>;
40 }
42 
43 using AppDataHashMap = detail::HashMapString<std::string>;
44 
45 
49 class DLL_PUBLIC_RMS PolicyDescriptor {
50 public:
51 
56  PolicyDescriptor(const std::vector<UserRights>& userRightsList);
57 
62  PolicyDescriptor(const std::vector<UserRoles>& userRolesList);
63 
67  const std::string& Name()
68  {
69  return this->name_;
70  }
71 
76  void Name(const std::string& value)
77  {
78  this->name_ = value;
79  }
80 
84  const std::string& Description()
85  {
86  return this->description_;
87  }
88 
93  void Description(const std::string& value)
94  {
95  this->description_ = value;
96  }
97 
107  const std::vector<UserRights>& UserRightsList() const
108  {
109  return this->userRightsList_;
110  }
111 
115  const std::vector<UserRoles>& UserRolesList()
116  {
117  return this->userRolesList_;
118  }
119 
123  const std::chrono::time_point<std::chrono::system_clock>& ContentValidUntil()
124  {
125  return this->contentValidUntil_;
126  }
127 
133  const std::chrono::time_point<std::chrono::system_clock>& value)
134  {
135  this->contentValidUntil_ = value;
136  }
137 
142  {
143  return this->bAllowOfflineAccess_;
144  }
145 
150  void AllowOfflineAccess(bool value)
151  {
152  this->bAllowOfflineAccess_ = value;
153  }
154 
158  std::shared_ptr<std::string>Referrer() const
159  {
160  return this->referrer_;
161  }
162 
167  void Referrer(std::shared_ptr<std::string>uri)
168  {
169  this->referrer_ = uri;
170  }
171 
175  const AppDataHashMap& EncryptedAppData()
176  {
177  return this->encryptedAppData_;
178  }
179 
184  void EncryptedAppData(const AppDataHashMap& value)
185  {
186  this->encryptedAppData_ = value;
187  }
188 
192  const AppDataHashMap& SignedAppData()
193  {
194  return this->signedAppData_;
195  }
196 
201  void SignedAppData(const AppDataHashMap& value)
202  {
203  this->signedAppData_ = value;
204  }
205 
206 public:
207 
208  PolicyDescriptor(std::shared_ptr<core::ProtectionPolicy>policy);
209 
210 private:
211 
212  std::string name_;
213  std::string description_;
214 
215  std::vector<UserRights> userRightsList_;
216  std::vector<UserRoles> userRolesList_;
217 
218  std::chrono::time_point<std::chrono::system_clock> contentValidUntil_;
219  bool bAllowOfflineAccess_;
220 
221  std::shared_ptr<std::string> referrer_;
222  AppDataHashMap encryptedAppData_;
223  AppDataHashMap signedAppData_;
224 
225 private:
226 
227  static void ValidateUserRightsList(
228  const std::vector<UserRights>& userRightsList);
229  static void ValidateUserRolesList(
230  const std::vector<UserRoles>& userRolesList);
231 };
232 
236 enum OfflineCacheLifetimeConstants {
237 
241  NoCache = 0,
242 
246  CacheNeverExpires = -1
247 };
248 } // m_namespace modernapi
249 } // m_namespace rmscore
250 
251 #endif // _RMS_LIB_POLICYDESCRIPTOR_H_
bool AllowOfflineAccess()
Gets the setting of the offline access allowance control; True or False.
Definition: PolicyDescriptor.h:141
void Name(const std::string &value)
Sets the name of the PolicyDescriptor.
Definition: PolicyDescriptor.h:76
const std::chrono::time_point< std::chrono::system_clock > & ContentValidUntil()
Gets the date that the content is valid until.
Definition: PolicyDescriptor.h:123
void Referrer(std::shared_ptr< std::string >uri)
Sets the referral URI of the PolicyDescriptor.
Definition: PolicyDescriptor.h:167
Definition: AuthenticationCallbackImpl.h:16
void Description(const std::string &value)
Sets the description of the PolicyDescriptor.
Definition: PolicyDescriptor.h:93
void EncryptedAppData(const AppDataHashMap &value)
Sets the encrypted app data.
Definition: PolicyDescriptor.h:184
Specifies users and rights assigned for a file. This is information used for custom protection...
Definition: PolicyDescriptor.h:49
const std::vector< UserRights > & UserRightsList() const
Gets the user's rights list.
Definition: PolicyDescriptor.h:107
void AllowOfflineAccess(bool value)
Sets the True or False setting of the offline access allowance control.
Definition: PolicyDescriptor.h:150
const std::vector< UserRoles > & UserRolesList()
Gets the user's roles list.
Definition: PolicyDescriptor.h:115
const std::string & Name()
Gets the name of the PolicyDescriptor.
Definition: PolicyDescriptor.h:67
void ContentValidUntil(const std::chrono::time_point< std::chrono::system_clock > &value)
Sets the date that the content is valid until.
Definition: PolicyDescriptor.h:132
std::shared_ptr< std::string > Referrer() const
Gets the referral URI of the PolicyDescriptor.
Definition: PolicyDescriptor.h:158
void SignedAppData(const AppDataHashMap &value)
Sets the signed app data.
Definition: PolicyDescriptor.h:201
const AppDataHashMap & EncryptedAppData()
Gets the encrypted app data.
Definition: PolicyDescriptor.h:175
const std::string & Description()
Gets the description of the PolicyDescriptor.
Definition: PolicyDescriptor.h:84
const AppDataHashMap & SignedAppData()
Gets the signed app data.
Definition: PolicyDescriptor.h:192