Fix: login-as crash 'Database Manager is not initialized' (backport #8661 to 2.0)#8677
Open
addow wants to merge 1 commit into
Open
Fix: login-as crash 'Database Manager is not initialized' (backport #8661 to 2.0)#8677addow wants to merge 1 commit into
addow wants to merge 1 commit into
Conversation
Backport of upstream/master commit 8432203. Replaces legacy api_is_global_platform_admin() with User::isSuperAdmin() to avoid a fatal crash when the Symfony firewall fires the switch_user event at priority 8, before LegacyListener initialises the legacy Container at priority 7. Also replaces the legacy SessionManager/UserManager DRH path with a clean Doctrine-based UserRepository::isUserFollowedByDrh() lookup, removing all remaining legacy Container dependencies from this service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a platform admin uses the switch-user feature (
/?_switch_user=...), a fatal error occurs:Root cause
The Symfony firewall fires the
switch_userevent at priority 8, beforeLegacyListenerinitialises the legacy Container at priority 7. The call chain:SwitchUserListener→SwitchUserSubscriber→LoginAsAuthorizationChecker::isGlobalPlatformAdmin()→api_is_global_platform_admin()→Database::getManager()→ fatalFix
Backport of upstream/master commit
8432203a14("Internal: Fix 'login as' admin/hrm - refs #8661"):LoginAsAuthorizationChecker::isGlobalPlatformAdmin()— replaceapi_is_global_platform_admin()withUser::isSuperAdmin(), which reads directly from the already-loaded Doctrine entity and needs no legacy Container.LoginAsAuthorizationChecker::canDrhLoginAs()— replace theSessionManager/UserManagerlegacy helpers with a clean DoctrineUserRepository::isUserFollowedByDrh()call, eliminating the remaining legacy Container dependency from this service.UserRepository::isUserFollowedByDrh()— new Doctrine method, native replacement forUserManager::is_user_followed_by_drh().LoginAsAuthorizationCheckerTest— unit test for all impersonation policy paths (also from the original commit).The fix on upstream/master was not backported to the
2.0branch; this PR does exactly that.