AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AuthorizationManager.h
Go to the documentation of this file.
1 /*
2  * Copyright 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 
16 #ifndef ACSDKAUTHORIZATION_AUTHORIZATIONMANAGER_H_
17 #define ACSDKAUTHORIZATION_AUTHORIZATIONMANAGER_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include <string>
24 
34 
35 namespace alexaClientSDK {
36 namespace acsdkAuthorization {
37 
99  , public std::enable_shared_from_this<AuthorizationManager> {
100 public:
109  static std::shared_ptr<acsdkAuthorization::AuthorizationManager> create(
110  const std::shared_ptr<avsCommon::sdkInterfaces::storage::MiscStorageInterface>& storage,
111  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager);
112 
115  void reportStateChange(
117  const std::string& authId,
118  const std::string& userId) override;
119  void add(const std::shared_ptr<acsdkAuthorizationInterfaces::AuthorizationAdapterInterface>& adapter) override;
121 
124  void logout() override;
128 
131  void addAuthObserver(std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface> observer) override;
132  void removeAuthObserver(std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface> observer) override;
133  std::string getAuthToken() override;
134  void onAuthFailure(const std::string& token) override;
136 
139  void clearData() override;
141 
148  const std::shared_ptr<registrationManager::RegistrationManagerInterface> registrationManager);
149 
150  // @name RequiresShutdown Functions
152  void doShutdown() override;
154 
155 private:
163  const std::shared_ptr<AuthorizationManagerStorage>& storage,
164  const std::shared_ptr<registrationManager::CustomerDataManagerInterface>& customerDataManager);
165 
171  bool init();
172 
180  void handleTransition(
182  const std::string& authId,
183  const std::string& userId);
184 
188  void clearDataLocked();
189 
197  void logoutHelper(std::unique_lock<std::mutex>& lock);
198 
204  void setStateLocked(const avsCommon::sdkInterfaces::AuthObserverInterface::FullState& newState);
205 
212  void setActiveLocked(const std::string& adapterId, const std::string& userId);
213 
220  void persist(const std::string& adapterId, const std::string& userId);
221 
223  std::mutex m_mutex;
224 
230  std::mutex m_observersMutex;
231 
233  std::unordered_map<std::string, std::shared_ptr<acsdkAuthorizationInterfaces::AuthorizationAdapterInterface>>
234  m_adapters;
235 
237  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::AuthObserverInterface>> m_observers;
238 
240  std::shared_ptr<acsdkAuthorizationInterfaces::AuthorizationAdapterInterface> m_activeAdapter;
241 
243  std::string m_activeAdapterId;
244 
246  std::string m_activeUserId;
247 
250 
252  std::shared_ptr<AuthorizationManagerStorage> m_storage;
253 
255  std::shared_ptr<registrationManager::RegistrationManagerInterface> m_registrationManager;
256 
259 };
260 
261 } // namespace acsdkAuthorization
262 } // namespace alexaClientSDK
263 
264 #endif // ACSDKAUTHORIZATION_AUTHORIZATIONMANAGER_H_
void removeAuthObserver(std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
static std::shared_ptr< acsdkAuthorization::AuthorizationManager > create(const std::shared_ptr< avsCommon::sdkInterfaces::storage::MiscStorageInterface > &storage, const std::shared_ptr< registrationManager::CustomerDataManagerInterface > &customerDataManager)
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
State
The enum State describes the state of authorization.
Definition: AuthObserverInterface.h:34
void reportStateChange(const avsCommon::sdkInterfaces::AuthObserverInterface::FullState &state, const std::string &authId, const std::string &userId) override
void addAuthObserver(std::shared_ptr< avsCommon::sdkInterfaces::AuthObserverInterface > observer) override
An aggregated structure to simplify working with State and Error.
Definition: AuthObserverInterface.h:80
void onAuthFailure(const std::string &token) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
avsCommon::sdkInterfaces::AuthObserverInterface::State getState() override
void add(const std::shared_ptr< acsdkAuthorizationInterfaces::AuthorizationAdapterInterface > &adapter) override
void setRegistrationManager(const std::shared_ptr< registrationManager::RegistrationManagerInterface > registrationManager)

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0