summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/user.h
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2018-07-31 18:26:07 -0400
committerBen Caimano <ben.caimano@10gen.com>2018-07-31 18:32:19 -0400
commit6711ab3bbc02ca98da1af2fe115f07e37bb076e4 (patch)
treef1859ba3692a982b0afbd06fcb523c830136c25c /src/mongo/db/auth/user.h
parent35757e8ef3134fad1a09cb09a69882929d9ebb76 (diff)
downloadmongo-6711ab3bbc02ca98da1af2fe115f07e37bb076e4.tar.gz
Revert "SERVER-35890 refactor User cache into InvalidatingLRUCache and UserHandle"
This reverts commit 78dec3622268ad27bb855eda4c6a4ed345412fd9.
Diffstat (limited to 'src/mongo/db/auth/user.h')
-rw-r--r--src/mongo/db/auth/user.h37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/mongo/db/auth/user.h b/src/mongo/db/auth/user.h
index a22bdca7231..b974a0a3a7c 100644
--- a/src/mongo/db/auth/user.h
+++ b/src/mongo/db/auth/user.h
@@ -101,6 +101,7 @@ public:
typedef stdx::unordered_map<ResourcePattern, Privilege> ResourcePrivilegeMap;
explicit User(const UserName& name);
+ ~User();
/**
* Returns the user name for this user.
@@ -161,6 +162,12 @@ public:
*/
bool isValid() const;
+ /**
+ * This returns the reference count for this User. The AuthorizationManager should be the
+ * only caller of this.
+ */
+ uint32_t getRefCount() const;
+
// Mutators below. Mutation functions should *only* be called by the AuthorizationManager
/**
@@ -217,15 +224,30 @@ public:
}
void getRestrictions() && = delete;
-protected:
- friend class AuthorizationManagerImpl;
/**
* Marks this instance of the User object as invalid, most likely because information about
* the user has been updated and needs to be reloaded from the AuthorizationManager.
*
* This method should *only* be called by the AuthorizationManager.
*/
- void _invalidate();
+ void invalidate();
+
+ /**
+ * Increments the reference count for this User object, which records how many threads have
+ * a reference to it.
+ *
+ * This method should *only* be called by the AuthorizationManager.
+ */
+ void incrementRefCount();
+
+ /**
+ * Decrements the reference count for this User object, which records how many threads have
+ * a reference to it. Once the reference count goes to zero, the AuthorizationManager is
+ * allowed to destroy this instance.
+ *
+ * This method should *only* be called by the AuthorizationManager.
+ */
+ void decrementRefCount();
private:
UserName _name;
@@ -248,10 +270,11 @@ private:
// Restrictions which must be met by a Client in order to authenticate as this user.
RestrictionDocuments _restrictions;
- // Indicates whether the user has been marked as invalid by the AuthorizationManager.
- AtomicBool _isValid{true};
+ // _refCount and _isInvalidated are modified exclusively by the AuthorizationManager
+ // _isInvalidated can be read by any consumer of User, but _refCount can only be
+ // meaningfully read by the AuthorizationManager, as _refCount is guarded by the AM's _lock
+ uint32_t _refCount;
+ AtomicUInt32 _isValid; // Using as a boolean
};
-using UserHandle = std::shared_ptr<User>;
-
} // namespace mongo