栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Spring Security从登录失败中获取用户名?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Spring Security从登录失败中获取用户名?

好的,据我所知,答案竟然是非常简单的事情,没有经过大量讨论或记录。

这就是我要做的(在创建此类的任何地方都无需配置)…

import org.apache.log4j.Logger;import org.springframework.context.ApplicationListener;import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;import org.springframework.stereotype.Component;@Componentpublic class MyApplicationListener implements ApplicationListener<AuthenticationFailureBadCredentialsEvent> {    private static final Logger LOG = Logger.getLogger(MyApplicationListener.class);    @Override    public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) {        Object userName = event.getAuthentication().getPrincipal();        Object credentials = event.getAuthentication().getCredentials();        LOG.debug("Failed login using USERNAME [" + userName + "]");        LOG.debug("Failed login using PASSWORD [" + credentials + "]");    }}

我与Spring Security专家相距甚远,因此,如果有人读过此书,并且知道某个原因,我们就不应该这样做或知道我想听听它的更好方法。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/466818.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号