【问题标题】:What is the replacement of AuthenticationException.getAuthentication() in Spring4.0.3Spring4.0.3中AuthenticationException.getAuthentication()的替换是什么
【发布时间】: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) 方法。 这两种方法有什么替代方法吗?

【问题讨论】:

标签: java spring spring-security


【解决方案1】:

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

3.x 版本的latest Javadoc 说:

@deprecated 以避免潜在的敏感信息泄露(例如通过序列化/远程处理)。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2016-01-15
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    相关资源
    最近更新 更多