| 1 | /* |
| 2 | * Copyright 2010-2017 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 | #include <aws/core/utils/logging/LogMacros.h> |
| 17 | #include <aws/core/auth/AWSAuthSignerProvider.h> |
| 18 | #include <aws/core/auth/AWSAuthSigner.h> |
| 19 | #include <aws/core/auth/AWSCredentialsProvider.h> |
| 20 | #include <aws/core/utils/memory/stl/AWSAllocator.h> |
| 21 | |
| 22 | const char CLASS_TAG[] = "AuthSignerProvider" ; |
| 23 | |
| 24 | using namespace Aws::Auth; |
| 25 | |
| 26 | DefaultAuthSignerProvider::DefaultAuthSignerProvider(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider, |
| 27 | const Aws::String& serviceName, const Aws::String& region) |
| 28 | { |
| 29 | m_signers.emplace_back(Aws::MakeShared<Aws::Client::AWSAuthV4Signer>(CLASS_TAG, credentialsProvider, serviceName.c_str(), region)); |
| 30 | m_signers.emplace_back(Aws::MakeShared<Aws::Client::AWSAuthEventStreamV4Signer>(CLASS_TAG, credentialsProvider, serviceName.c_str(), region)); |
| 31 | m_signers.emplace_back(Aws::MakeShared<Aws::Client::AWSNullSigner>(CLASS_TAG)); |
| 32 | } |
| 33 | |
| 34 | DefaultAuthSignerProvider::DefaultAuthSignerProvider(const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer) |
| 35 | { |
| 36 | m_signers.emplace_back(Aws::MakeShared<Aws::Client::AWSNullSigner>(CLASS_TAG)); |
| 37 | if(signer) |
| 38 | { |
| 39 | m_signers.emplace_back(signer); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | std::shared_ptr<Aws::Client::AWSAuthSigner> DefaultAuthSignerProvider::GetSigner(const Aws::String& signerName) const |
| 44 | { |
| 45 | for(const auto& signer : m_signers) |
| 46 | { |
| 47 | if(signer->GetName() == signerName) |
| 48 | { |
| 49 | return signer; |
| 50 | } |
| 51 | } |
| 52 | AWS_LOGSTREAM_ERROR(CLASS_TAG, "Request's signer: '" << signerName << "' is not found in the signer's map." ); |
| 53 | assert(false); |
| 54 | return nullptr; |
| 55 | } |
| 56 | |
| 57 | void DefaultAuthSignerProvider::AddSigner(std::shared_ptr<Aws::Client::AWSAuthSigner>& signer) |
| 58 | { |
| 59 | assert(signer); |
| 60 | m_signers.emplace_back(signer); |
| 61 | } |
| 62 | |