Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

How to expire user sessions properly? #44

Open
AlexeyPotopakhin opened this issue Oct 11, 2018 · 0 comments
Open

How to expire user sessions properly? #44

AlexeyPotopakhin opened this issue Oct 11, 2018 · 0 comments

Comments

@AlexeyPotopakhin
Copy link

Hello, I'm using

  • Spring Boot 2.1.0.M4
  • Spring Session Data Mongodb 2.1.0.BUILD-SNAPSHOT

I'm trying to expire sessions for current user:

@GetMapping("kill_my_sessions")
    public ResponseEntity<?> killMySessions() {
        final var currentUserId = currentUserService.getId().toString();

        // All user sessions
        var sessions = mongoOperationsSessionRepository
                .findByIndexNameAndIndexValue(
                        FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
                        currentUserId);

        // Expiring all user sessions
        sessions.forEach((id, session) -> {
            session.isExpired(); // false
            session.setExpireAt(new Date());
            session.isExpired(); // true
            mongoOperationsSessionRepository.save(session); // ok
        });

        return ResponseEntity.ok().build();
    }

BUT some other thread executes save() method with old not-expired session and overwrites expired session in DB after all sessions were expired.


So, should save() do check for the session expiration in DB before save? Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant