diff options
author | Spencer Jackson <spencer.jackson@mongodb.com> | 2020-02-28 19:45:13 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-03 00:32:53 +0000 |
commit | a1f6d2eb74268b140929c3f280c37299617d596a (patch) | |
tree | 55df6bd729ca2c663c7c75cd878bfb05d5fd732e /src/mongo/db/auth/user.h | |
parent | b7dfdde9d038433cf34e77618d4b1b114d3f4d91 (diff) | |
download | mongo-a1f6d2eb74268b140929c3f280c37299617d596a.tar.gz |
SERVER-46498 Store connection specified roles in authorization cache key
Diffstat (limited to 'src/mongo/db/auth/user.h')
-rw-r--r-- | src/mongo/db/auth/user.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/mongo/db/auth/user.h b/src/mongo/db/auth/user.h index 97c9994d2e9..59d94699c04 100644 --- a/src/mongo/db/auth/user.h +++ b/src/mongo/db/auth/user.h @@ -254,7 +254,37 @@ private: RestrictionDocuments _restrictions; }; -using UserCache = ReadThroughCache<UserName, User>; +/** + * Represents the properties required to request a UserHandle. + * This type is hashable and may be used as a key describing requests + */ +struct UserRequest { + UserRequest(const UserName& name, boost::optional<std::set<RoleName>> roles) + : name(name), roles(std::move(roles)) {} + + + template <typename H> + friend H AbslHashValue(H h, const UserRequest& key) { + auto state = H::combine(std::move(h), key.name); + if (key.roles) { + for (const auto& role : *key.roles) { + state = H::combine(std::move(state), role); + } + } + return state; + } + + bool operator==(const UserRequest& key) const { + return name == key.name && roles == key.roles; + } + + // The name of the requested user + UserName name; + // Any authorization grants which should override and be used in favor of roles acquisition. + boost::optional<std::set<RoleName>> roles; +}; + +using UserCache = ReadThroughCache<UserRequest, User>; using UserHandle = UserCache::ValueHandle; } // namespace mongo |