Skip to content

Commit

Permalink
JS auth policy lookup map (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton authored Jan 21, 2021
1 parent ecbe8d8 commit a05c0a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
## [0.17.1]

### Changed

Expand Down Expand Up @@ -641,6 +641,7 @@ Some discrepancies with the TR remain, and are being tracked under https://githu

Initial pre-release

[0.17.1]: https://github.com/microsoft/CCF/releases/tag/ccf-0.17.1
[0.17.0]: https://github.com/microsoft/CCF/releases/tag/ccf-0.17.0
[0.16.3]: https://github.com/microsoft/CCF/releases/tag/ccf-0.16.3
[0.16.2]: https://github.com/microsoft/CCF/releases/tag/ccf-0.16.2
Expand Down
61 changes: 38 additions & 23 deletions src/apps/js_generic/named_auth_policies.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,49 @@

namespace ccfapp
{
static std::shared_ptr<ccf::AuthnPolicy> get_policy_by_name(
const std::string& name)
using NamedAuthPolicies =
std::unordered_map<std::string, std::shared_ptr<ccf::AuthnPolicy>>;

static NamedAuthPolicies& auth_policies_by_name()
{
if (name == ccf::UserCertAuthnPolicy::SECURITY_SCHEME_NAME)
{
return ccf::user_cert_auth_policy;
}
if (name == ccf::UserSignatureAuthnPolicy::SECURITY_SCHEME_NAME)
{
return ccf::user_signature_auth_policy;
}
if (name == ccf::MemberCertAuthnPolicy::SECURITY_SCHEME_NAME)
{
return ccf::member_cert_auth_policy;
}
if (name == ccf::MemberSignatureAuthnPolicy::SECURITY_SCHEME_NAME)
{
return ccf::member_signature_auth_policy;
}
if (name == ccf::JwtAuthnPolicy::SECURITY_SCHEME_NAME)
static NamedAuthPolicies policies;
if (policies.empty())
{
return ccf::jwt_auth_policy;
policies.emplace(
ccf::UserCertAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::user_cert_auth_policy);
policies.emplace(
ccf::UserSignatureAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::user_signature_auth_policy);

policies.emplace(
ccf::MemberCertAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::member_cert_auth_policy);
policies.emplace(
ccf::MemberSignatureAuthnPolicy::SECURITY_SCHEME_NAME,
ccf::member_signature_auth_policy);

policies.emplace(
ccf::JwtAuthnPolicy::SECURITY_SCHEME_NAME, ccf::jwt_auth_policy);

policies.emplace(
ccf::EmptyAuthnPolicy::SECURITY_SCHEME_NAME, ccf::empty_auth_policy);
}
if (name == ccf::EmptyAuthnPolicy::SECURITY_SCHEME_NAME)

return policies;
}

static std::shared_ptr<ccf::AuthnPolicy> get_policy_by_name(
const std::string& name)
{
auto& policies = auth_policies_by_name();
auto it = policies.find(name);
if (it == policies.end())
{
return ccf::empty_auth_policy;
return nullptr;
}
return nullptr;

return it->second;
}

template <typename T>
Expand Down

0 comments on commit a05c0a3

Please sign in to comment.