【发布时间】:2017-01-24 06:01:56
【问题描述】:
我在我的项目中使用 Spring 3,现在升级到 Spring 4.0.3.RELEASE。
现在在使用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());
}
同样不推荐使用setAuthentication(authentication) 方法。
这两种方法有什么替代方法吗?
【问题讨论】:
-
正如NealeU所说,依赖逻辑需要重新思考,但是baeldung.com/get-user-in-spring-security有'''SecurityContextHolder.getContext().getAuthentication();'''
标签: java spring spring-security