SpringBoot2.x+SpringSecurity+Oauth2 password模式登录成功后回调函数的终极解决方案

18 篇文章 0 订阅
11 篇文章 0 订阅

今天在搭建项目的时候碰到Security并没有提供登录成功回调的相关API,研究了一下源码,今天写个笔记,记录下。先说说解决方案,通过跟踪源码我们会发现验证成功后他会publisher一个Authentication进去。

package com.xz.process.config;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

/**
 * 认证成功回调的方法
 * @author yuxuan
 *
 */
@Component
public class ApplicationListenerAuthencationSuccess implements ApplicationListener<AuthenticationSuccessEvent> {

	@Override
	public void onApplicationEvent(AuthenticationSuccessEvent event) {
		//在这里做登录日志
//		System.out.println(event.getSource()+"++++++++++++++");	
	}
}

那我们只需要监听AuthenticationSuccessEvent就可以了。

有问题可以在下面评论,技术问题可以私聊我。

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值