本文介绍了Spring security 3:保存有关数据库中身份验证的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要保存一些关于用户的信息,比如他的IP地址和身份验证日期以及其他内容进入数据库的身份验证。换句话说,我想保持连接历史。
我正在使用自定义身份验证提供程序,UserDetailsS​​ervice的实现,但我不知道在哪里放置保存这些信息的代码。

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.

有任何建议吗?

推荐答案

由于 AbstractAuthenticationProcessingFilter 实现 ApplicationEventPublisherAware 并在成功验证时触发事件 InteractiveAuthenticationSuccessEvent ,您只需要监听该事件并更新数据库。这将使您的数据库代码保持干净并与安全代码分离。

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.

这篇关于Spring security 3:保存有关数据库中身份验证的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:40