summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/user.h
diff options
context:
space:
mode:
authorSpencer Jackson <spencer.jackson@mongodb.com>2020-02-28 19:45:13 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-03 00:32:53 +0000
commita1f6d2eb74268b140929c3f280c37299617d596a (patch)
tree55df6bd729ca2c663c7c75cd878bfb05d5fd732e /src/mongo/db/auth/user.h
parentb7dfdde9d038433cf34e77618d4b1b114d3f4d91 (diff)
downloadmongo-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.h32
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