spring - Spring Security Failurehandler 中的自定义登录表单 Bean
问题描述
版本:Spring Security 4.2.3
我需要一些附加值,例如登录 Jsp 页面中的“表单操作”。是否可以在自定义 SuccessHandler 或 FailureHandler 中获取表单 bean“logonForm”。我尝试了 Autowired,但这没有帮助。有什么建议么?
自定义登录 JSP
<form:form action="userLogon" commandName="logonForm" >
<input type="hidden" name="action" id="action"/>
故障处理程序
public class MyAppAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Autowired(required=false)
@Qualifier("logonForm")
private LogonForm logonForm;
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
setUseForward(true); // ensure it is a server forward than client redirect
if (authException != null) {
String userId = logonForm.getUserId();
解决方案
结果更简单,登录字段值可从 API 获得:
String userId = request.getParameter("userId");
String action= request.getParameter("action");
推荐阅读
- docker - docker build --no-cache 会构建不同的层吗?
- stl - 使用 LLVM 在 Windows 上使用 QtCreator 设置 Cocos2dx 项目
- c# - Azure Functions - Host.json 不适用于 Azure 应用程序设置
- android - 在多行 TextView 的末尾放置一个视图
- typo3 - TYPO3 使用 Querybuilder 更改表
- oracle - 在 Obiee12c 中创建一个新用户
- jasper-reports - 是否可以在主报告中包含子报告作为二进制文件的一部分?
- vb.net - VB.NET 2010 - 用于 FTPS 的 WinSCP 包
- jquery - 如何使用内联 jquery 迭代组合框中的响应值?-姜戈
- java - Apache Camel 自定义服务和关闭