gpt4 book ai didi

java - 替换 AuthenticationException.getAuthentication();

转载 作者:行者123 更新时间:2023-11-30 06:56:35 24 4
gpt4 key购买 nike

我们将应用程序从 Spring & 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());
}

有人可以告诉我这个的替代品吗?网上提供的内容不多。

最佳答案

如果在 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);
}

关于java - 替换 AuthenticationException.getAuthentication();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41671347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com