java - 并发会话管理不起作用。我已按照文档进行操作,但我认为我遗漏了一些小东西
问题描述
这是我的安全配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/assets/**", "/register/**", "/","/login**")
.permitAll().antMatchers("/profile/**").hasAuthority("ROLE_1").anyRequest().authenticated()
.antMatchers("/actuator/**").hasAuthority("ROLE_2").anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true).expiredUrl("/login?expired")
.and().and().logout().deleteCookies("JSESSIONID").invalidateHttpSession(true)
.and().csrf().disable();
// .failureUrl("/fail");
}
这是将 HttpSessionEventPublisher 添加到应用程序上下文中
@Bean
public HttpSessionEventPublisher httpSessionEventPublisher() {
return new HttpSessionEventPublisher();
}
请让我知道我错过了什么。我仍然可以使用相同的凭据从两个浏览器登录。
解决方案
我找到了解决方案。它是覆盖我的 User 类的 equals 和 hashCode 方法,该类基于以下解决方案实现 UserDetails。已验证主体的 UserDetails 对象的比较是控制/测量会话并发的方式
http://forum.spring.io/forum/spring-projects/security/99166-maximum-sessions-1-does-not-work
推荐阅读
- data-visualization - 有人知道如何共享 google colab 文档,以便人们可以运行笔记本但看不到实际代码吗?
- java - 不了解 Android Mediaplayer 同步
- r - 对数据集中的几对使用 cpquery 函数
- sql - How to retrieve a particular number from the string XXXX-XXXX-XXX-XXXX through SQL
- python - 无法使用 python 检索所有 XML 数据
- search - Fuse.js:完全匹配的名称
- aws-amplify - snsdev-dev 已存在于堆栈中
- c# - 拆分由任何非数字字符串分隔的数字
- python - 格式化分类报告以显示不同的指标
- python - 我想在python中组合一个元组列表