spring-session icon indicating copy to clipboard operation
spring-session copied to clipboard

SpringSessionBackedSessionInformation.EXPIRED not used in expired session clean up

Open bayang opened this issue 1 year ago • 0 comments

Describe the bug

I use Jdbc session, I want to mark some sessions as expired. So I call

//private val sessionRegistry: SessionRegistry,

sessionRegistry.getAllSessions("login", false).forEach {
               it.expireNow()
    }

getAllSessions returns SpringSessionBackedSessionInformation objects. Calling expireNow on them calls super.expireNow and adds the SpringSessionBackedSessionInformation.EXPIRED attribute. The times of the session are not touched in DB.

So far so good.

When the clean up job launches in JdbcIndexedSessionRepository it only checks the expiry date, so expired sessions are kept in db.

Example data from DB :

"PRIMARY_ID","SESSION_ID","CREATION_TIME","LAST_ACCESS_TIME","MAX_INACTIVE_INTERVAL","EXPIRY_TIME","PRINCIPAL_NAME"
a296354c-d86a-49ac-9ff5-c9593eec64f4,ba25a393-db6f-4e40-a467-33361df132a5,1729712977529,1729753828691,604800,1730358628691,toto

corresponding attribute :

"SESSION_PRIMARY_ID","ATTRIBUTE_NAME","ATTRIBUTE_BYTES"
"a296354c-d86a-49ac-9ff5-c9593eec64f4",org.springframework.session.security.SpringSessionBackedSessionInformation.EXPIRED,"true"

Expected behavior

clean up cron should delete sessions based on expiry time but also based on the presence of the SpringSessionBackedSessionInformation.EXPIRED attribute.

bayang avatar Oct 24 '24 07:10 bayang