summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/auth_decorations.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/auth/auth_decorations.cpp')
-rw-r--r--src/mongo/db/auth/auth_decorations.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/mongo/db/auth/auth_decorations.cpp b/src/mongo/db/auth/auth_decorations.cpp
index c78117b91e6..13b4edbc6b5 100644
--- a/src/mongo/db/auth/auth_decorations.cpp
+++ b/src/mongo/db/auth/auth_decorations.cpp
@@ -53,9 +53,9 @@ const auto getAuthorizationSession =
class AuthzClientObserver final : public ServiceContext::ClientObserver {
public:
void onCreateClient(Client* client) override {
- auto service = client->getServiceContext();
- AuthorizationSession::set(client,
- AuthorizationManager::get(service)->makeAuthorizationSession());
+ if (auto authzManager = AuthorizationManager::get(client->getServiceContext())) {
+ AuthorizationSession::set(client, authzManager->makeAuthorizationSession());
+ }
}
void onDestroyClient(Client* client) override {}
@@ -64,6 +64,11 @@ public:
void onDestroyOperationContext(OperationContext* opCtx) override {}
};
+ServiceContext::ConstructorActionRegisterer authzClientObserverRegisterer{
+ "AuthzClientObserver", [](ServiceContext* service) {
+ service->registerClientObserver(std::make_unique<AuthzClientObserver>());
+ }};
+
} // namespace
void AuthenticationSession::set(Client* client, std::unique_ptr<AuthenticationSession> newSession) {
@@ -86,7 +91,6 @@ AuthorizationManager* AuthorizationManager::get(ServiceContext& service) {
void AuthorizationManager::set(ServiceContext* service,
std::unique_ptr<AuthorizationManager> authzManager) {
getAuthorizationManager(service) = std::move(authzManager);
- service->registerClientObserver(std::make_unique<AuthzClientObserver>());
}
AuthorizationSession* AuthorizationSession::get(Client* client) {