Skip to content

Commit 1bccfb9

Browse files
sbalujasbiscigl
andauthored
Multi auth request level resolution (#3632)
* Multi auth request level resolution * Fix inline variables error * Add noAuthIdentityResolver instead of nullptr, fix include headers * remove unused var * Bearer token to follow single definition rule for linker issues (logging tag definitions) * Fix request includes from NoAuthScheme.h to NoAuthSchemeOption.h * Revert "remove unused var" This reverts commit d7aeff8. --------- Co-authored-by: sbiscigl <sbiscigl@amazon.com>
1 parent 70c3d5c commit 1bccfb9

38 files changed

+545
-65
lines changed

src/aws-cpp-sdk-core/include/aws/core/AmazonWebServiceRequest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <aws/core/utils/memory/stl/AWSString.h>
2020
#include <aws/core/utils/stream/ResponseStream.h>
2121
#include <aws/core/endpoint/internal/AWSEndpointAttribute.h>
22+
#include <smithy/identity/auth/AuthSchemeOption.h>
2223

2324
namespace Aws
2425
{
@@ -231,6 +232,8 @@ namespace Aws
231232
RetryContext GetRetryContext() const { return m_retryContext; }
232233

233234
void SetRetryContext(const RetryContext& context) const { m_retryContext = context; }
235+
236+
virtual Aws::Vector<smithy::AuthSchemeOption> GetRequestSpecificSupportedAuth() const { return {}; }
234237
protected:
235238
/**
236239
* Default does nothing. Override this to convert what would otherwise be the payload of the

src/aws-cpp-sdk-core/include/aws/core/auth/AWSAuthSigner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
#include <aws/core/auth/signer/AWSAuthV4Signer.h>
1212
#include <aws/core/auth/signer/AWSAuthEventStreamV4Signer.h>
1313
#include <aws/core/auth/signer/AWSNullSigner.h>
14-
1514
// This is a header that represents old legacy all-in-one header to maintain backward compatibility

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace client
188188
}
189189
}
190190

191-
Aws::Vector<AuthSchemeOption> authSchemeOptions = m_authSchemeResolver->resolveAuthScheme(identityParams);
191+
Aws::Vector<AuthSchemeOption> authSchemeOptions = ctx.m_authResolver == nullptr ? m_authSchemeResolver->resolveAuthScheme(identityParams) : ctx.m_authResolver->resolveAuthScheme(identityParams);
192192

193193
auto authSchemeOptionIt = std::find_if(authSchemeOptions.begin(), authSchemeOptions.end(),
194194
[this](const AuthSchemeOption& opt)

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClientAsyncRequestContext.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <smithy/Smithy_EXPORTS.h>
1313
#include <smithy/identity/auth/AuthSchemeOption.h>
1414
#include <smithy/interceptor/InterceptorContext.h>
15+
#include <smithy/identity/auth/AuthSchemeResolverBase.h>
1516

1617
namespace smithy
1718
{
@@ -71,18 +72,21 @@ namespace smithy
7172
std::shared_ptr<Aws::Utils::Threading::Executor> m_pExecutor;
7273
std::shared_ptr<interceptor::InterceptorContext> m_interceptorContext;
7374
std::shared_ptr<smithy::AwsIdentity> m_awsIdentity;
75+
std::shared_ptr<smithy::AuthSchemeResolverBase<>> m_authResolver;
7476

7577
AwsSmithyClientAsyncRequestContext() = default;
7678

7779
AwsSmithyClientAsyncRequestContext(
7880
Aws::AmazonWebServiceRequest const * const request,
7981
const char* requestName,
80-
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor):
82+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
83+
std::shared_ptr<smithy::AuthSchemeResolverBase<>> authResolver):
8184
m_invocationId{Aws::Utils::UUID::PseudoRandomUUID()},
8285
m_pRequest{request},
8386
m_requestName{requestName ? requestName : m_pRequest ? m_pRequest->GetServiceRequestName() : ""},
8487
m_retryCount{0},
85-
m_pExecutor{pExecutor}
88+
m_pExecutor{pExecutor},
89+
m_authResolver{authResolver}
8690
{
8791

8892
}

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
*/
55
#pragma once
66

7+
#include <smithy/Smithy_EXPORTS.h>
78
#include <smithy/identity/auth/AuthSchemeOption.h>
9+
810
namespace smithy
911
{
10-
struct BearerTokenAuthSchemeOption
11-
{
12-
static AuthSchemeOption bearerTokenAuthSchemeOption;
13-
};
14-
15-
AuthSchemeOption BearerTokenAuthSchemeOption::bearerTokenAuthSchemeOption =
16-
AuthSchemeOption("smithy.api#HTTPBearerAuth");
12+
struct BearerTokenAuthSchemeOption
13+
{
14+
static SMITHY_API AuthSchemeOption bearerTokenAuthSchemeOption;
15+
};
1716
} // namespace smithy
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/auth/AuthScheme.h>
8+
#include <smithy/identity/auth/built-in/NoAuthSchemeOption.h>
9+
10+
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
11+
#include <smithy/identity/signer/built-in/NoAuthSigner.h>
12+
#include <smithy/identity/resolver/built-in/NoAuthIdentityResolver.h>
13+
14+
namespace smithy {
15+
constexpr char NOAUTH[] = "smithy.api#noAuth";
16+
17+
class NoAuthScheme : public AuthScheme<AwsCredentialIdentityBase>
18+
{
19+
public:
20+
using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>;
21+
using AwsCredentialSignerT = AwsSignerBase<IdentityT>;
22+
23+
explicit NoAuthScheme()
24+
: AuthScheme(NOAUTH),
25+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
26+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
27+
{
28+
assert(m_signer);
29+
assert(m_identityResolver);
30+
}
31+
32+
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
33+
const Aws::String& serviceName,
34+
const Aws::String& region)
35+
: AuthScheme(NOAUTH),
36+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
37+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
38+
{
39+
AWS_UNREFERENCED_PARAM(identityResolver);
40+
AWS_UNREFERENCED_PARAM(serviceName);
41+
AWS_UNREFERENCED_PARAM(region);
42+
assert(m_signer);
43+
assert(m_identityResolver);
44+
}
45+
46+
explicit NoAuthScheme(const Aws::String& serviceName,
47+
const Aws::String& region)
48+
: NoAuthScheme(nullptr, serviceName, region)
49+
{
50+
assert(m_signer);
51+
assert(m_identityResolver);
52+
}
53+
54+
//legacy constructors
55+
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver, const Aws::String& serviceName, const Aws::String& region, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy policy, bool urlEscape)
56+
: AuthScheme(NOAUTH),
57+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
58+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
59+
{
60+
AWS_UNREFERENCED_PARAM(identityResolver);
61+
AWS_UNREFERENCED_PARAM(serviceName);
62+
AWS_UNREFERENCED_PARAM(region);
63+
AWS_UNREFERENCED_PARAM(policy);
64+
AWS_UNREFERENCED_PARAM(urlEscape);
65+
assert(m_signer);
66+
assert(m_identityResolver);
67+
}
68+
69+
virtual ~NoAuthScheme() = default;
70+
71+
std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver() override
72+
{
73+
return m_identityResolver;
74+
}
75+
76+
std::shared_ptr<AwsCredentialSignerT> signer() override
77+
{
78+
return m_signer;
79+
}
80+
81+
protected:
82+
std::shared_ptr<AwsCredentialSignerT> m_signer;
83+
std::shared_ptr<AwsCredentialIdentityResolverT> m_identityResolver;
84+
};
85+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/Smithy_EXPORTS.h>
8+
#include <smithy/identity/auth/AuthSchemeOption.h>
9+
10+
namespace smithy {
11+
struct NoAuthSchemeOption
12+
{
13+
static SMITHY_API AuthSchemeOption noAuthSchemeOption;
14+
};
15+
}

src/aws-cpp-sdk-core/include/smithy/identity/identity/impl/AwsBearerTokenIdentityImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
99

1010
namespace smithy {
11-
const Aws::String &AwsBearerTokenIdentity::token() const { return m_token; }
11+
inline const Aws::String &AwsBearerTokenIdentity::token() const { return m_token; }
1212

13-
Aws::Crt::Optional<AwsIdentity::DateTime>
13+
inline Aws::Crt::Optional<AwsIdentity::DateTime>
1414
AwsBearerTokenIdentity::expiration() const
1515
{
1616
return m_expiration;

src/aws-cpp-sdk-core/include/smithy/identity/resolver/AwsBearerTokenIdentityResolver.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class AwsBearerTokenIdentityResolver
1717
: public IdentityResolverBase<AwsBearerTokenIdentityBase>
1818
{
1919
public:
20-
static const char BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG[];
21-
2220
using IdentityT = AwsBearerTokenIdentity;
2321
virtual ~AwsBearerTokenIdentityResolver() = default;
2422

@@ -57,7 +55,7 @@ class AwsBearerTokenIdentityResolver
5755
if (!bearerTokenProvider)
5856
{
5957
AWS_LOGSTREAM_FATAL(
60-
BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG,
58+
"BearerTokenProvider",
6159
"Unexpected nullptr in "
6260
"DefaultBearerTokenProviderChain::m_providerChain");
6361
return Aws::Client::AWSError<Aws::Client::CoreErrors>(
@@ -70,7 +68,7 @@ class AwsBearerTokenIdentityResolver
7068
if (!bearerToken.IsExpiredOrEmpty())
7169
{
7270
auto outcomePtr = Aws::MakeUnique<AwsBearerTokenIdentity>(
73-
BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG);
71+
"BearerTokenProvider");
7472
outcomePtr->token() = bearerToken.GetToken();
7573
outcomePtr->expiration() = bearerToken.GetExpiration();
7674
return ResolveIdentityFutureOutcome(std::move(outcomePtr));
@@ -104,8 +102,5 @@ class DefaultAwsBearerTokenIdentityResolver
104102
: AwsBearerTokenIdentityResolver(Aws::Vector<std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase>>{
105103
Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider")}){};
106104
};
107-
const char
108-
AwsBearerTokenIdentityResolver::BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG[] =
109-
"BearerTokenProvider";
110105

111106
} // namespace smithy
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/resolver/AwsCredentialIdentityResolver.h>
8+
9+
#include <aws/core/auth/AWSCredentials.h>
10+
11+
namespace smithy {
12+
/**
13+
* A no-auth identity resolver that returns empty credentials for unauthenticated requests
14+
*/
15+
class NoAuthIdentityResolver : public AwsCredentialIdentityResolver {
16+
public:
17+
NoAuthIdentityResolver() = default;
18+
virtual ~NoAuthIdentityResolver() = default;
19+
20+
ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) override
21+
{
22+
AWS_UNREFERENCED_PARAM(identityProperties);
23+
AWS_UNREFERENCED_PARAM(additionalParameters);
24+
25+
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("NoAuthIdentityResolver");
26+
// Return empty identity for no-auth scenarios
27+
return {std::move(smithyCreds)};
28+
}
29+
};
30+
}

0 commit comments

Comments
 (0)