【问题标题】:How to migrate old code from Spring Security 2.0 to 3.0 when it's based on ConcurrentSessionControllerImpl?基于 ConcurrentSessionControllerImpl 的旧代码如何从 Spring Security 2.0 迁移到 3.0?
【发布时间】:2018-08-03 12:09:46
【问题描述】:

我正在使用 Spring Security 2.0 的旧 Java 代码,该代码必须迁移到 Spring Security 3.0 及更高版本。

我现在的问题是有一个扩展 ConcurrentSessionControllerImpl 的类,它已通过 Spring Security 3.0 中的重构被删除。关键是我在 Spring Security 2.0 文档中找不到有关此重构的任何文档,也找不到有关 ConcurrentSessionControllerImpl 类的任何文档。

该类覆盖以下方法:

public void checkAuthenticationAllowed(final Authentication auth) throws AuthenticationException;

public void registerSuccessfulAuthentication(final Authentication authentication);

有没有办法迁移,还是我必须重写整个应用程序安全层?

【问题讨论】:

标签: java spring spring-security migration


【解决方案1】:

由于 Spring Security 的重构,ConcurrentSessionControllerImpl 已大部分重构为 org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy

registerSuccessfulAuthentication 最佳映射到哪里

onAuthentication(Authentication authentication, HttpServletRequest request, HttpServletResponse response)

虽然checkAuthenticationAllowed 现在是ConcurrentSessionControlStrategy 中的私有方法,但可以通过以下方式进行部分自定义:

protected void allowableSessionsExceeded(List<SessionInformation> sessions, int allowableSessions, SessionRegistry registry);

protected int getMaximumSessionsForThisUser(Authentication authentication);

还有一些设置器需要配置:

public void setExceptionIfMaximumExceeded(boolean exceptionIfMaximumExceeded);
public void setMaximumSessions(int maximumSessions);

有关ConcurrentSessionControlStrategy 的更多信息,请查看JavaDocs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    相关资源
    最近更新 更多