BnW
BnW

Reputation: 25

Spring security 3 : Save informations about authentification in database

I need to save some informations about user when he is authentificated like his IP Adress and authentification date and other stuff into the database. In other words i want to keep connections history. I am using a custom authentification provider, an implementation of UserDetailsService but i dont know where to put code of saving these informations.

Any suggestions?

Upvotes: 2

Views: 2877

Answers (2)

Ritesh
Ritesh

Reputation: 7522

Since the AbstractAuthenticationProcessingFilter implements ApplicationEventPublisherAware and fires the event InteractiveAuthenticationSuccessEvent on successful authentication, you just need to listen to that event and update database. This will keep your database code clean and decoupled from the security code.

Upvotes: 2

Boris Kirzner
Boris Kirzner

Reputation: 895

You need to implement your custom AuthenticationSuccessHandler.

Upvotes: 1

Related Questions