AuthenticationException.getAuthentication()的替换;

时间:2017-01-16 07:24:34

标签: java spring hibernate

我们将应用程序从Spring& amp; Hibernate 3.x到4.x.问题是现在已弃用AuthenticationException.getAuthentication()。任何人都可以建议任何替代方案。 以下是我们使用的代码:

public ModelAndView init(HttpServletRequest request, HttpServletResponse response){
    AuthenticationException exception = (AuthenticationException)request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

    Authentication loginAuthentication = exception.getAuthentication();

    //Set the user name for the change password screen
    return new ModelAndView("common/changePassword", "userName", loginAuthentication.getPrincipal());   
}

有人能指出我替换它。网上没有多少。

1 个答案:

答案 0 :(得分:0)

如果在AuthenticationException的情况下执行以下代码,则表示您从登录表单提交的用户名和密码仍可在HttpServletRequest中使用。所以我认为你可以从那里获得用户名。

public ModelAndView init(HttpServletRequest request, HttpServletResponse response){
    AuthenticationException exception = (AuthenticationException)request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

    String username = request.getParameter("<Name of your username parameter>");

    //Set the user name for the change password screen
    return new ModelAndView("common/changePassword", "userName", username);   
}