SpringSecurity自定义认证成功处理器
自定义认证成功处理器
代码实现
1.实现AuthenticationSuccessHandler接口
第一步:实现 AuthenticationSuccessHandler
@Component("customAuthenticationSuccessHandler")
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {@Overridepublic void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication){//以返回JSON数据为例Result result = Result.ok("认证成功");response.setContentType("application/json;charset=UTF-8");response.getWriter().write(result.toJsonString());}
}
2.配置SpringScurry
第二步:配置SpringScurry
@Autowired
private AuthenticationSuccessHandler customAuthenticationSuccessHandler;
@Override
//前后代码省略
protected void configure(HttpSecurity http) throws Exception {http//前后代码省略.successHandler(customAuthenticationSuccessHandler)
}
跳转到上次访问页面
当我们要实现页面跳转时,我们只需要继承AuthenticationSuccessHandler
的实现类SavedRequestAwareAuthenticationSuccessHandler
然后调用父类的方法
@Component("customAuthenticationSuccessHandler")
public class CustomAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {@Overridepublic void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {//super.onAuthenticationSuccess(request,response,authentication);}}
}
SpringSecurity自定义认证成功处理器相关推荐
- spring security:自定义认证成功处理器
使用spring认证登录,登录之后,一般还需要进行其他处理,例如:保存登录时间.登录ip到数据库,缓存用户信息到redis数据库等等,这些操作可以通过自定义一个登录成功处理器来处理. 自定义认证成功处 ...
- Security自定义认证规则
一.自动配置分析 boot对security自动配置源于SpringBootWebSecurityConfiguration类 @Configuration(proxyBeanMethods = fa ...
- 5. SpringSecurity用户认证源码 与 实现短信验证码(自定义SpringSecurity组件)
前言 源码讲解 源码分析 AbstractAuthenticationProcessingFilter.java UsernamePasswordAuthenticationFilter.java P ...
- (二)Spring Security自定义登录成功或失败处理器
目录 一:创建登录成功处理器 二:创建登录失败处理器 三:添加处理器 三. 项目地址 我们接着上一章 Spring Security最简单的搭建,进行开发 LoginSuccessHandler 和L ...
- SpringSecurity使用自定义认证页面
SpringSecurity使用自定义认证页面 在SpringSecurity主配置文件中指定认证页面配置信息 修改认证页面的请求地址 再次启动项目后就可以看到自定义的酷炫认证页面了!
- springsecurity自定义短信验证码认证登录流程
文章目录 前言 验证码存储我们采用redis作为缓存 (注意,这里为了测试方便改为手动设置验证码) 经过上面接口,验证码已经存入到redis中,下面开始认证流程 自定义SmsCodeAuthentic ...
- SpringSecurity实战:基于mysql自定义SpringSecurity权限认证规则
上文<Spring Security 源码分析:Spring Security 授权过程>已经详细分析了Spring Security 授权过程,接下来通过上文的授权过程我们可以自定义授权 ...
- 3. SpringSecurity 自定义手机号登录
距离上一次更新,不知不觉已经过去了半个月了,人真的是不能放松,一放松就肆意妄为了.希望这个月内可以把 SpringSecurity 系列更新完毕吧,加油!. OK,言归正传上一章我们利用 Spring ...
- spring security 自定义认证登录
spring security 自定义认证登录 1.概要 1.1.简介 spring security是一种基于 Spring AOP 和 Servlet 过滤器的安全框架,以此来管理权限认证等. 1 ...
最新文章
- 转 深入理解Midlet类
- 京东智能情感客服挽救一名学生生命,“可信赖的AI”用温暖前行
- php mysql study_phpStudy 升级 MySQL5.7
- 科技|全球首款飞行汽车开始量产!下月开始预售,2023年后或可实现一键打“飞车”...
- numpy比较运算符和其对应的通用函数
- java break在switch_java中switch case语句需要加入break的原因解析
- Flickr30k图像标注数据集下载及使用方法(转载的,备忘)
- osg图元绑定方式总结
- NDK 开发实战 - 封装 java 层 sdk 模型
- Java ObjectOutputStream writeFields()方法与示例
- Little Alchemy 游戏 - 扒答案。。 Java
- 基于mysql搭建框架环境搭建_Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
- 计算机专业能评电子工程师吗,计算机工程师职称 评定条件
- java如何声明一个数组用来存储随机生成的字母并且保证不重复
- Visual studio 2013 连接MySQL数据库的设置。
- R语言colorRampPalette函数-创建颜色梯度(渐变色)
- Office 2007简体中文版售价抢先看
- 半导体、芯片、集成电路、无尘车间具体释义及区别
- proteus不能打开一直在开启界面转圈
- 虚拟机安装ubuntu怎么全屏_ubuntu虚拟机怎么设置全屏显示?