Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant