Sameer Malhotra
Sameer Malhotra

Reputation: 464

Spring boot jdbc session only for logged-in users

I am using Spring Session JDBC in my spring boot application and it's working fine. But it's resulting into lot of calls to database. I want to only invoke the jdbc session management for authenticated users and the anonymous users can keep using the default spring session management. Is there a way to do this?

Upvotes: 2

Views: 314

Answers (3)

Matthias M
Matthias M

Reputation: 14830

If possible you should avoid creating sessions for unauthenticated users. If no session is created, no database queries will be done.

The default session creation policy IF_REQUIRED already supports this behaviour.

Upvotes: 0

Lineo
Lineo

Reputation: 1

It's not so neglectable on ddos/penetration testing even you bruteforce the main domain of the app, with a postgres database behind has the side effect to fill the pg_wal and crash the database.

Upvotes: 0

Yennefer
Yennefer

Reputation: 6234

As stated by doc, Spring Session is a replacement of the regular HTTP session, therefore you cannot have both of them.

Usually, the performance overhead in the case you report should be minimal, or handled by database caches in a way to be neglectable.

Upvotes: 0

Related Questions