什么是Spring4.0.3中AuthenticationException.getAuthentication()的替代品

时间:2016-09-16 05:22:02

标签: java spring spring-security

我在我的项目中使用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)也已弃用。 这两种方法有其他选择吗?

1 个答案:

答案 0 :(得分:2)

没有替代方法,因为此方法存在安全风险。

3.x版本的latest Javadoc说:

  

@已弃用,以避免潜在的敏感信息泄漏(例如,通过序列化/远程处理)。

任何依赖于此的代码都需要重新考虑。

相关问题