AWS SDK for C++  0.14.3
AWS SDK for C++
PersistentCognitoIdentityProvider.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #pragma once
16 
21 #include <mutex>
22 
23 namespace Aws
24 {
25  namespace Utils
26  {
27  namespace Json
28  {
29  class JsonValue;
30  }
31  }
32  namespace Auth
33  {
35  {
36  LoginAccessTokens() : longTermTokenExpiry(0) {}
40  };
41 
43  {
44  public:
45  virtual bool HasIdentityId() const = 0;
46  virtual bool HasLogins() const = 0;
47  virtual Aws::String GetIdentityId() const = 0;
48  virtual Aws::Map<Aws::String, LoginAccessTokens> GetLogins() = 0;
49  virtual Aws::String GetAccountId() const = 0;
50  virtual Aws::String GetIdentityPoolId() const = 0;
51  virtual void PersistIdentityId(const Aws::String&) = 0;
52  virtual void PersistLogins(const Aws::Map<Aws::String, LoginAccessTokens>&) = 0;
53  inline void ClearLogins() { PersistLogins(Aws::Map<Aws::String, LoginAccessTokens>()); }
54  inline void ClearIdentity() { PersistIdentityId(""); }
55  inline void Logout() { ClearIdentity(); ClearLogins(); }
56 
57  inline void SetLoginsUpdatedCallback(const std::function<void(const PersistentCognitoIdentityProvider&)>& callback)
58  {
59  m_loginsUpdatedCallback = Aws::BuildFunction<void(const PersistentCognitoIdentityProvider&)>(callback);
60  }
61 
62  inline void SetIdentityIdUpdatedCallback(const std::function<void(const PersistentCognitoIdentityProvider&)>& callback)
63  {
64  m_identityIdUpdatedCallback = Aws::BuildFunction<void(const PersistentCognitoIdentityProvider&)>(callback);
65  }
66 
67  protected:
68  std::function<void(const PersistentCognitoIdentityProvider&)> m_loginsUpdatedCallback;
69  std::function<void(const PersistentCognitoIdentityProvider&)> m_identityIdUpdatedCallback;
70  };
71 
73  {
74  public:
75  PersistentCognitoIdentityProvider_JsonFileImpl(const Aws::String& identityPoolId, const Aws::String& accountId, bool disableCaching = false);
76  PersistentCognitoIdentityProvider_JsonFileImpl(const Aws::String& identityPoolId, const Aws::String& accountId, const char* identitiesFilePath, bool disableCaching = false);
77 
78  bool HasIdentityId() const override;
79  bool HasLogins() const override;
80  Aws::String GetIdentityId() const override;
81  Aws::Map<Aws::String, LoginAccessTokens> GetLogins() override;
82  Aws::String GetAccountId() const override { return m_accountId; }
83  Aws::String GetIdentityPoolId() const override { return m_identityPoolId; }
84  void PersistIdentityId(const Aws::String&) override;
85  void PersistLogins(const Aws::Map<Aws::String, LoginAccessTokens>&) override;
86 
87  private:
88  Utils::Json::JsonValue LoadJsonDocFromFile() const;
89  void PersistChangesToFile(const Utils::Json::JsonValue&) const;
90  void LoadAndParseDoc();
91 
93 
94  std::mutex m_docMutex;
95  Aws::String m_identityPoolId;
96  Aws::String m_accountId;
97  Aws::String m_identityId;
99  Aws::String m_identityFilePath;
100  bool m_disableCaching;
101  };
102 
104  }
105 }
PersistentCognitoIdentityProvider_JsonFileImpl DefaultPersistentCognitoIdentityProvider
std::function< void(const PersistentCognitoIdentityProvider &)> m_identityIdUpdatedCallback
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:28
void SetLoginsUpdatedCallback(const std::function< void(const PersistentCognitoIdentityProvider &)> &callback)
std::function< void(const PersistentCognitoIdentityProvider &)> m_loginsUpdatedCallback
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
#define AWS_IDENTITY_MANAGEMENT_API
void SetIdentityIdUpdatedCallback(const std::function< void(const PersistentCognitoIdentityProvider &)> &callback)
JSON (JavaScript Object Notation).