Problem/Motivation
SessionManager::delete() is the only remaining method which is directly accessing the database. The code should be extracted into a separate service so that modules wishing to swap out the session storage backend do not need to override SessionManager anymore.
Steps to reproduce
Proposed resolution
- Deprecate
SessionManager::delete() - Reassign the responsibility to remove all sessions of a user to a new
UserSessionRepositoryservice.
The SessionManager::delete() method previously was guarded by the WriteSafeSessionHandler. That session handler proxy has the responsibility to prevent writing a session record in unsafe conditions. In core it is used when AccountSwitcher temporarily substitutes the current user with a different one. If something triggers a session write during that time window, write safe session handler prevents the session record from being updated with the id of the temporary user.
On the other hand, UserSessionRepository::deleteAll() (the replacement for SessionManager::delete()) isn't necessarily targeting the current session. In some cases it is even used to delete all sessions of a different user. This is, e.g., the case in Drupal\user\Entity\User::postSave() where all sessions are removed of a user being blocked.
For this reason UserSessionRepository::deleteAll() is neither guarded by the WriteSafeSessionHandler nor by a CLI check.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3570849
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3570849-deprecate-sessionmanagerdelete
changes, plain diff MR !14582
Comments
Comment #3
znerol commentedComment #4
znerol commentedComment #5
dcam commentedYou forgot to replace the change record URLs in the MR with the actual URL.
Since the idea is to stop the
SessionManagerfrom accessing the database, should theconnectionproperty and constructor argument be deprecated?Comment #6
znerol commentedIndeed! And it looks like this is a good opportunity to move the
$handlerargument to the place matching the parents__constructor().Comment #7
znerol commentedComment #8
godotislateThanks for IS update. The removal of the write safe check is clear now.
Nice work! lgtm
Comment #9
znerol commentedOh, I seem to have tried this 10 years ago with a different approach: #2472535: Remove SessionManager::delete in favor of a portable mechanism to invalid sessions of authenticated users
Comment #10
longwaveI think this can be deprecated in 11.4 and removed in 12, if we're quick: I don't really see anyone overriding SessionManager much, there is exactly one example in contrib and it's not affected here.
https://search.tresbien.tech/search?q=%22extends%20SessionManager%22&num...
Comment #11
znerol commentedRight.
Comment #12
godotislateThe build test failed, so I pushed the button to run the whole pipeline manually so it re-runs (in the fork).
Comment #13
godotislateTests finally passed. LGTM, though we need "fast" follow up to remove deprecations for 12.x
Comment #14
longwaveCommitted and pushed 29b81b3c8e5 to main and 4bf14a083fc to 11.x. Thanks!
Comment #19
znerol commentedFollow-up #3577376: Remove recently introduced deprecations from SessionManager