summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-11-07 15:22:08 +0000
committerevergreen <evergreen@mongodb.com>2019-11-07 15:22:08 +0000
commitb2493375543cb89b020f224a1759c1f4d40aa638 (patch)
tree971629049003126366f31846208ce6bf65fdbd20 /src/mongo/db/auth
parenta811bbe9d2489c428886288651c2dbddec0d123d (diff)
downloadmongo-b2493375543cb89b020f224a1759c1f4d40aa638.tar.gz
SERVER-44372 WeakFunction: a simplification of SHIM_ macros
Diffstat (limited to 'src/mongo/db/auth')
-rw-r--r--src/mongo/db/auth/authorization_manager.cpp7
-rw-r--r--src/mongo/db/auth/authorization_manager.h3
-rw-r--r--src/mongo/db/auth/authorization_manager_global.cpp4
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp10
-rw-r--r--src/mongo/db/auth/authorization_session.cpp8
-rw-r--r--src/mongo/db/auth/authorization_session.h3
-rw-r--r--src/mongo/db/auth/authorization_session_impl.cpp11
-rw-r--r--src/mongo/db/auth/authz_manager_external_state.cpp6
-rw-r--r--src/mongo/db/auth/authz_manager_external_state.h3
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_d.cpp11
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_mock.cpp10
-rw-r--r--src/mongo/db/auth/authz_manager_external_state_s.cpp17
-rw-r--r--src/mongo/db/auth/authz_session_external_state.cpp7
-rw-r--r--src/mongo/db/auth/authz_session_external_state.h3
-rw-r--r--src/mongo/db/auth/authz_session_external_state_d.cpp13
-rw-r--r--src/mongo/db/auth/authz_session_external_state_mock.cpp12
-rw-r--r--src/mongo/db/auth/authz_session_external_state_s.cpp12
17 files changed, 105 insertions, 35 deletions
diff --git a/src/mongo/db/auth/authorization_manager.cpp b/src/mongo/db/auth/authorization_manager.cpp
index cfdcf367452..b6c30368b2f 100644
--- a/src/mongo/db/auth/authorization_manager.cpp
+++ b/src/mongo/db/auth/authorization_manager.cpp
@@ -38,6 +38,7 @@
#include <vector>
#include "mongo/base/init.h"
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/bson/mutable/element.h"
@@ -100,6 +101,10 @@ const int AuthorizationManager::schemaVersion26Upgrade;
const int AuthorizationManager::schemaVersion26Final;
const int AuthorizationManager::schemaVersion28SCRAM;
-MONGO_DEFINE_SHIM(AuthorizationManager::create);
+
+std::unique_ptr<AuthorizationManager> AuthorizationManager::create() {
+ static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthorizationManager::create);
+ return w();
+}
} // namespace mongo
diff --git a/src/mongo/db/auth/authorization_manager.h b/src/mongo/db/auth/authorization_manager.h
index 21380460468..7f11e10739c 100644
--- a/src/mongo/db/auth/authorization_manager.h
+++ b/src/mongo/db/auth/authorization_manager.h
@@ -36,7 +36,6 @@
#include <boost/optional.hpp>
#include "mongo/base/secure_allocator.h"
-#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/bson/mutable/element.h"
#include "mongo/bson/oid.h"
@@ -96,7 +95,7 @@ public:
AuthorizationManager() = default;
- static MONGO_DECLARE_SHIM(()->std::unique_ptr<AuthorizationManager>) create;
+ static std::unique_ptr<AuthorizationManager> create();
static constexpr StringData USERID_FIELD_NAME = "userId"_sd;
static constexpr StringData USER_NAME_FIELD_NAME = "user"_sd;
diff --git a/src/mongo/db/auth/authorization_manager_global.cpp b/src/mongo/db/auth/authorization_manager_global.cpp
index ba1015947fb..e549de2f404 100644
--- a/src/mongo/db/auth/authorization_manager_global.cpp
+++ b/src/mongo/db/auth/authorization_manager_global.cpp
@@ -60,9 +60,7 @@ Status AuthzVersionParameter::setFromString(const std::string& newValueString) {
ServiceContext::ConstructorActionRegisterer createAuthorizationManager(
"CreateAuthorizationManager",
- {"OIDGeneration",
- "EndStartupOptionStorage",
- MONGO_SHIM_DEPENDENCY(AuthorizationManager::create)},
+ {"OIDGeneration", "EndStartupOptionStorage"},
[](ServiceContext* service) {
auto authzManager = AuthorizationManager::create();
authzManager->setAuthEnabled(serverGlobalParams.authState ==
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index 8c94db89c40..54bae468e32 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -38,6 +38,7 @@
#include <vector>
#include "mongo/base/init.h"
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/bson/mutable/element.h"
@@ -222,10 +223,17 @@ Status AuthorizationManagerPinnedUsersServerParameter::setFromString(const std::
return authorizationManagerPinnedUsers.setFromString(str);
}
-MONGO_REGISTER_SHIM(AuthorizationManager::create)()->std::unique_ptr<AuthorizationManager> {
+namespace {
+
+std::unique_ptr<AuthorizationManager> authorizationManagerCreateImpl() {
return std::make_unique<AuthorizationManagerImpl>();
}
+auto authorizationManagerCreateRegistration =
+ MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationManager::create, authorizationManagerCreateImpl);
+
+} // namespace
+
/**
* Guard object for synchronizing accesses to data cached in AuthorizationManager instances.
* This guard allows one thread to access the cache at a time, and provides an exception-safe
diff --git a/src/mongo/db/auth/authorization_session.cpp b/src/mongo/db/auth/authorization_session.cpp
index 065049da621..19172661b6a 100644
--- a/src/mongo/db/auth/authorization_session.cpp
+++ b/src/mongo/db/auth/authorization_session.cpp
@@ -36,6 +36,7 @@
#include <string>
#include <vector>
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
@@ -66,5 +67,10 @@ void AuthorizationSession::ScopedImpersonate::swap() {
swap(*std::get<1>(impersonations), _roles);
}
-MONGO_DEFINE_SHIM(AuthorizationSession::create);
+std::unique_ptr<AuthorizationSession> AuthorizationSession::create(
+ AuthorizationManager* authzManager) {
+ static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthorizationSession::create);
+ return w(authzManager);
+}
+
} // namespace mongo
diff --git a/src/mongo/db/auth/authorization_session.h b/src/mongo/db/auth/authorization_session.h
index 61fc801dfac..1546aab99ad 100644
--- a/src/mongo/db/auth/authorization_session.h
+++ b/src/mongo/db/auth/authorization_session.h
@@ -72,8 +72,7 @@ class AuthorizationSession {
AuthorizationSession& operator=(const AuthorizationSession&) = delete;
public:
- static MONGO_DECLARE_SHIM(
- (AuthorizationManager * authzManager)->std::unique_ptr<AuthorizationSession>) create;
+ static std::unique_ptr<AuthorizationSession> create(AuthorizationManager*);
AuthorizationSession() = default;
diff --git a/src/mongo/db/auth/authorization_session_impl.cpp b/src/mongo/db/auth/authorization_session_impl.cpp
index 07ef4bf6a25..73c2feb31b2 100644
--- a/src/mongo/db/auth/authorization_session_impl.cpp
+++ b/src/mongo/db/auth/authorization_session_impl.cpp
@@ -36,6 +36,7 @@
#include <string>
#include <vector>
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/auth/action_set.h"
#include "mongo/db/auth/action_type.h"
@@ -61,14 +62,18 @@ namespace mongo {
namespace dps = ::mongo::dotted_path_support;
using std::vector;
-MONGO_REGISTER_SHIM(AuthorizationSession::create)
-(AuthorizationManager* authzManager)->std::unique_ptr<AuthorizationSession> {
+namespace {
+
+std::unique_ptr<AuthorizationSession> authorizationSessionCreateImpl(
+ AuthorizationManager* authzManager) {
return std::make_unique<AuthorizationSessionImpl>(
AuthzSessionExternalState::create(authzManager),
AuthorizationSessionImpl::InstallMockForTestingOrAuthImpl{});
}
-namespace {
+auto authorizationSessionCreateRegistration =
+ MONGO_WEAK_FUNCTION_REGISTRATION(AuthorizationSession::create, authorizationSessionCreateImpl);
+
constexpr StringData ADMIN_DBNAME = "admin"_sd;
// Checks if this connection has the privileges necessary to create or modify the view 'viewNs'
diff --git a/src/mongo/db/auth/authz_manager_external_state.cpp b/src/mongo/db/auth/authz_manager_external_state.cpp
index 8093e0fb8b3..bc129430819 100644
--- a/src/mongo/db/auth/authz_manager_external_state.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state.cpp
@@ -29,6 +29,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/base/shim.h"
#include "mongo/config.h"
#include "mongo/db/auth/authorization_manager_global_parameters_gen.h"
#include "mongo/db/auth/authz_manager_external_state.h"
@@ -38,7 +39,10 @@
namespace mongo {
-MONGO_DEFINE_SHIM(AuthzManagerExternalState::create);
+std::unique_ptr<AuthzManagerExternalState> AuthzManagerExternalState::create() {
+ static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthzManagerExternalState::create);
+ return w();
+}
AuthzManagerExternalState::AuthzManagerExternalState() = default;
AuthzManagerExternalState::~AuthzManagerExternalState() = default;
diff --git a/src/mongo/db/auth/authz_manager_external_state.h b/src/mongo/db/auth/authz_manager_external_state.h
index e18963fefb3..3a98677cedd 100644
--- a/src/mongo/db/auth/authz_manager_external_state.h
+++ b/src/mongo/db/auth/authz_manager_external_state.h
@@ -34,7 +34,6 @@
#include <string>
#include <vector>
-#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/authorization_manager_impl.h"
@@ -59,7 +58,7 @@ class AuthzManagerExternalState {
AuthzManagerExternalState& operator=(const AuthzManagerExternalState&) = delete;
public:
- static MONGO_DECLARE_SHIM(()->std::unique_ptr<AuthzManagerExternalState>) create;
+ static std::unique_ptr<AuthzManagerExternalState> create();
virtual ~AuthzManagerExternalState();
diff --git a/src/mongo/db/auth/authz_manager_external_state_d.cpp b/src/mongo/db/auth/authz_manager_external_state_d.cpp
index adfbfb083ca..99dab1244ac 100644
--- a/src/mongo/db/auth/authz_manager_external_state_d.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_d.cpp
@@ -35,6 +35,7 @@
#include <memory>
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/auth/authz_session_external_state_d.h"
#include "mongo/db/auth/user_name.h"
@@ -90,9 +91,15 @@ Status AuthzManagerExternalStateMongod::findOne(OperationContext* opCtx,
<< query);
}
-MONGO_REGISTER_SHIM(AuthzManagerExternalState::create)
-()->std::unique_ptr<AuthzManagerExternalState> {
+namespace {
+
+std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() {
return std::make_unique<AuthzManagerExternalStateMongod>();
}
+auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl);
+
+} // namespace
+
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp
index 19a7977e605..575985de12c 100644
--- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp
@@ -34,6 +34,7 @@
#include <memory>
#include <string>
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/bson/mutable/algorithm.h"
#include "mongo/bson/mutable/document.h"
@@ -50,12 +51,15 @@
namespace mongo {
-MONGO_REGISTER_SHIM(AuthzManagerExternalState::create)
-()->std::unique_ptr<AuthzManagerExternalState> {
+namespace {
+
+std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() {
return std::make_unique<AuthzManagerExternalStateMock>();
}
-namespace {
+auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl);
+
void addRoleNameToObjectElement(mutablebson::Element object, const RoleName& role) {
fassert(17175, object.appendString(AuthorizationManager::ROLE_NAME_FIELD_NAME, role.getRole()));
fassert(17176, object.appendString(AuthorizationManager::ROLE_DB_FIELD_NAME, role.getDB()));
diff --git a/src/mongo/db/auth/authz_manager_external_state_s.cpp b/src/mongo/db/auth/authz_manager_external_state_s.cpp
index ec1a695ba53..d8835c5a15a 100644
--- a/src/mongo/db/auth/authz_manager_external_state_s.cpp
+++ b/src/mongo/db/auth/authz_manager_external_state_s.cpp
@@ -36,6 +36,7 @@
#include <string>
#include <vector>
+#include "mongo/base/shim.h"
#include "mongo/db/auth/authz_session_external_state_s.h"
#include "mongo/db/auth/user_document_parser.h"
#include "mongo/db/auth/user_management_commands_parser.h"
@@ -49,11 +50,6 @@
namespace mongo {
-MONGO_REGISTER_SHIM(AuthzManagerExternalState::create)
-()->std::unique_ptr<AuthzManagerExternalState> {
- return std::make_unique<AuthzManagerExternalStateMongos>();
-}
-
namespace {
/**
@@ -325,4 +321,15 @@ bool AuthzManagerExternalStateMongos::hasAnyPrivilegeDocuments(OperationContext*
return foundRoles.size() > 0;
}
+namespace {
+
+std::unique_ptr<AuthzManagerExternalState> authzManagerExternalStateCreateImpl() {
+ return std::make_unique<AuthzManagerExternalStateMongos>();
+}
+
+auto authzManagerExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzManagerExternalState::create, authzManagerExternalStateCreateImpl);
+
+} // namespace
+
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_session_external_state.cpp b/src/mongo/db/auth/authz_session_external_state.cpp
index 78cc3d0be28..73a3db66a5e 100644
--- a/src/mongo/db/auth/authz_session_external_state.cpp
+++ b/src/mongo/db/auth/authz_session_external_state.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/auth/authz_session_external_state.h"
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/namespace_string.h"
@@ -44,6 +45,10 @@ AuthorizationManager& AuthzSessionExternalState::getAuthorizationManager() {
return *_authzManager;
}
-MONGO_DEFINE_SHIM(AuthzSessionExternalState::create);
+std::unique_ptr<AuthzSessionExternalState> AuthzSessionExternalState::create(
+ AuthorizationManager* authzManager) {
+ static auto w = MONGO_WEAK_FUNCTION_DEFINITION(AuthzSessionExternalState::create);
+ return w(authzManager);
+}
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_session_external_state.h b/src/mongo/db/auth/authz_session_external_state.h
index 7647a9c9df9..d6af2dbfc4e 100644
--- a/src/mongo/db/auth/authz_session_external_state.h
+++ b/src/mongo/db/auth/authz_session_external_state.h
@@ -50,8 +50,7 @@ class AuthzSessionExternalState {
AuthzSessionExternalState& operator=(const AuthzSessionExternalState&) = delete;
public:
- static MONGO_DECLARE_SHIM(
- (AuthorizationManager * authzManager)->std::unique_ptr<AuthzSessionExternalState>) create;
+ static std::unique_ptr<AuthzSessionExternalState> create(AuthorizationManager* authzManager);
virtual ~AuthzSessionExternalState();
diff --git a/src/mongo/db/auth/authz_session_external_state_d.cpp b/src/mongo/db/auth/authz_session_external_state_d.cpp
index 3d56df4058f..37246f91054 100644
--- a/src/mongo/db/auth/authz_session_external_state_d.cpp
+++ b/src/mongo/db/auth/authz_session_external_state_d.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/auth/authz_session_external_state_d.h"
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/client.h"
#include "mongo/db/jsobj.h"
@@ -66,9 +67,17 @@ bool AuthzSessionExternalStateMongod::serverIsArbiter() const {
repl::ReplicationCoordinator::get(getGlobalServiceContext())->getMemberState().arbiter());
}
-MONGO_REGISTER_SHIM(AuthzSessionExternalState::create)
-(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> {
+namespace {
+
+std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateImpl(
+ AuthorizationManager* authzManager) {
return std::make_unique<AuthzSessionExternalStateMongod>(authzManager);
}
+auto authzSessionExternalStateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzSessionExternalState::create, authzSessionExternalStateImpl);
+
+} // namespace
+
+
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_session_external_state_mock.cpp b/src/mongo/db/auth/authz_session_external_state_mock.cpp
index aec268a8763..fa9c141d230 100644
--- a/src/mongo/db/auth/authz_session_external_state_mock.cpp
+++ b/src/mongo/db/auth/authz_session_external_state_mock.cpp
@@ -28,10 +28,18 @@
*/
#include "mongo/db/auth/authz_session_external_state_mock.h"
+#include "mongo/base/shim.h"
namespace mongo {
-MONGO_REGISTER_SHIM(AuthzSessionExternalState::create)
-(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> {
+namespace {
+
+std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateCreateImpl(
+ AuthorizationManager* authzManager) {
return std::make_unique<AuthzSessionExternalStateMock>(authzManager);
}
+
+auto authzSessionExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzSessionExternalState::create, authzSessionExternalStateCreateImpl);
+
+} // namespace
} // namespace mongo
diff --git a/src/mongo/db/auth/authz_session_external_state_s.cpp b/src/mongo/db/auth/authz_session_external_state_s.cpp
index 4b7a4a791b4..2313564224c 100644
--- a/src/mongo/db/auth/authz_session_external_state_s.cpp
+++ b/src/mongo/db/auth/authz_session_external_state_s.cpp
@@ -33,6 +33,7 @@
#include <string>
+#include "mongo/base/shim.h"
#include "mongo/base/status.h"
#include "mongo/db/jsobj.h"
@@ -46,9 +47,16 @@ void AuthzSessionExternalStateMongos::startRequest(OperationContext* opCtx) {
_checkShouldAllowLocalhost(opCtx);
}
-MONGO_REGISTER_SHIM(AuthzSessionExternalState::create)
-(AuthorizationManager* const authzManager)->std::unique_ptr<AuthzSessionExternalState> {
+namespace {
+
+std::unique_ptr<AuthzSessionExternalState> authzSessionExternalStateCreateImpl(
+ AuthorizationManager* authzManager) {
return std::make_unique<AuthzSessionExternalStateMongos>(authzManager);
}
+auto authzSessionExternalStateCreateRegistration = MONGO_WEAK_FUNCTION_REGISTRATION(
+ AuthzSessionExternalState::create, authzSessionExternalStateCreateImpl);
+
+} // namespace
+
} // namespace mongo