【问题标题】:How to get inputs from an authentication failed on spring春季如何从身份验证中获取输入失败
【发布时间】:2022-01-11 14:09:09
【问题描述】:

当我的项目从 SPRING 3 迁移到 SPRING 5 时,我必须使用 AuthenticationException getAuthentication.getPrincipal() 获取用户凭据的方法已被弃用,现在当用户身份验证失败时我无法获取信息。 我尝试使用 request.getParameter(WebAttributes.AUTHENTICATION_EXCEPTION) 从 HttpServletRequest 获取信息;但是由于我的身份验证对象已经为空,所以我得到了空; 我也试过 request.getSession().getAttribute(name);但代码无法识别“name”变量。

【问题讨论】:

标签: authentication spring-security


【解决方案1】:

我可以通过 request.getparameter("name of your variable"); 获得所需的信息。这是一个例子;

public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException exception) throws IOException {
   
   request.getparameter("name");
   request.getparameter("lastname");
   request.getparameter("id");
}

【讨论】:

    猜你喜欢
    • 2022-07-22
    • 2020-04-08
    • 1970-01-01
    • 2015-12-16
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    相关资源
    最近更新 更多