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 UserSessionRepository service.

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

Command icon 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:

Comments

znerol created an issue. See original summary.

znerol’s picture

znerol’s picture

Status: Active » Needs review
dcam’s picture

You forgot to replace the change record URLs in the MR with the actual URL.

Since the idea is to stop the SessionManager from accessing the database, should the connection property and constructor argument be deprecated?

znerol’s picture

Since the idea is to stop the SessionManager from accessing the database, should the connection property and constructor argument be deprecated?

Indeed! And it looks like this is a good opportunity to move the $handler argument to the place matching the parents __constructor().

znerol’s picture

Issue summary: View changes
godotislate’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for IS update. The removal of the write safe check is clear now.

Nice work! lgtm

longwave’s picture

Status: Reviewed & tested by the community » Needs work

I 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...

znerol’s picture

Status: Needs work » Needs review

Right.

godotislate’s picture

The build test failed, so I pushed the button to run the whole pipeline manually so it re-runs (in the fork).

godotislate’s picture

Status: Needs review » Reviewed & tested by the community

Tests finally passed. LGTM, though we need "fast" follow up to remove deprecations for 12.x

longwave’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 29b81b3c8e5 to main and 4bf14a083fc to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 4bf14a08 on 11.x
    refactor: #3570849 Deprecate SessionManager::delete()
    
    By: znerol
    By:...

  • longwave committed 29b81b3c on main
    refactor: #3570849 Deprecate SessionManager::delete()
    
    By: znerol
    By:...

znerol’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.