RMS SDK for C++  0.2.1
A client library for using Microsoft RMS from Linux.
TokenCache.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 TOKENCACHE_H
10 #define TOKENCACHE_H
11 
12 #include "types.h"
13 #include "AuthenticationResult.h"
14 #include "ClientKey.h"
15 #include "CallState.h"
16 #include "TokenCacheNotificationArgs.h"
17 #include "TokenCacheKey.h"
18 #include "TokenCacheItem.h"
19 #include "Logger.h"
20 #include "rmsauthExport.h"
21 
22 namespace rmsauth {
23 
24 class RMSAUTH_EXPORT TokenCache
25 {
26  static const String Tag(){static const String tag = "TokenCache"; return tag;}
27 
28  const int SchemaVersion_ = 2;
29  const String LocalSettingsContainerName_ = "ActiveDirectoryAuthenticationLibrary";
30  HashMap<TokenCacheKey, AuthenticationResultPtr> tokenCacheDictionary_;
31  // We do not want to return near expiry tokens, this is why we use this hard coded setting to refresh tokens which are close to expiration.
32  const int64_t expirationMarginInSeconds_ = 300;
33 
34 public:
35  TokenCache(const ByteArray& state);
36  static TokenCache& defaultShared();
37  bool hasStateChanged() const { return hasStateChanged_; }
38  void hasStateChanged(const bool val) { hasStateChanged_ = val; }
39 
40  int count() const;
41  ByteArray serialize();
42  void deserialize(const ByteArray& state);
43  virtual List<TokenCacheItemPtr> readItems();
44  virtual void deleteItem(TokenCacheItemPtr item);
45  virtual void clear();
46 
47  virtual void onAfterAccess(const TokenCacheNotificationArgs&) {}
48  virtual void onBeforeAccess(const TokenCacheNotificationArgs&) {}
49  virtual void onBeforeWrite(const TokenCacheNotificationArgs&) {}
50 
51  AuthenticationResultPtr loadFromCache(const String& authority, const String& resource, const String& clientId, TokenSubjectType subjectType, const String& uniqueId, CallStatePtr callState);
52  void storeToCache(AuthenticationResultPtr result, const String& authority, const String& resource, const String& clientId, TokenSubjectType subjectType, CallStatePtr callState);
53  void updateCachedMrrtRefreshTokens(AuthenticationResultPtr result, const String& authority, const String& clientId, TokenSubjectType subjectType);
54  TokenCacheItemPtr loadSingleItemFromCache(const String& authority, const String& resource, const String& clientId, TokenSubjectType subjectType, const String& uniqueId, CallStatePtr callState);
55  List<TokenCacheItemPtr> queryCache(const String& authority, const String& clientId, TokenSubjectType subjectType, const String& uniqueId);
56  virtual const String getCacheName() const {return TokenCache::Tag();}
57 
58 protected:
59  TokenCache();
60  volatile bool hasStateChanged_ = false;
61 };
62 
63 using TokenCachePtr = ptr<TokenCache>;
64 
65 } // namespace rmsauth {
66 
67 #endif // TOKENCACHE_H
Definition: TokenCache.h:24
Definition: TokenCacheNotificationArgs.h:18
Definition: AcquireTokenForClientHandler.h:14