What can be a use case for @Transient annotation from Spring Security Core?

Viewed 43

The official documentation for the @Transient states: (Link here)

A marker for Authentications that should never be stored across requests, for example a bearer token authentication

I understand that @Transient should be used when we do not want to persist any details. One such example that the documentation mentions is for bearer token authentication which makes sense.

What can be a general rule of thumb for situtation(s) where @Transient should be used?

Thank you,

1 Answers

It is pretty much what is written in the Javadocs. The transient authentication tokens indicate to the filter chain, specifically the HttpSessionSecurityContextRepository, whether or not the token ought to be persisted across requests.

Implementations of SecurityContextRepository may choose to not persist tokens that are marked with @Transient in the same way that HttpSessionSecurityContextRepository does.

There are more details in the related issue.

Related