如何把SpringSecurity用户登录的form表单传递用户名密码的方式改为用JSON的格式传递
来源:8-1 课程总结
TinyLeon
2018-07-08
老师好:
SpringSecuriy登录用的是form传递的用户名密码,我们这边要求前后端交互都统一为JSON的格式。
请问老师这个有没有什么好的办法呢?
2回答
-
自己写个filter,不用spring原生的。
032019-03-19 -
jiiiiiin
2018-10-15
```java
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
log.debug("身份认证(登录)成功");
final Device currentDevice = HttpUtils.resolveDevice(request);
// 根据渠道返回不同的响应数据
// 还有一种做法是根据客户端程序配置来指定响应数据格式:https://coding.imooc.com/lesson/134.html#mid=6866
if (!currentDevice.isNormal()) {
respJson(response, authentication);
} else {
// 默认是做重定向到登录之前的【期望访问资源】接口
super.onAuthenticationSuccess(request, response, authentication);
}
}```
可以尝试这样在错误和成功处理组件中完成
00
Spring Security技术栈开发企业级认证与授权
2662 学习 · 1561 问题
相似问题