我正在尝试使用spring安全性为spring boot 2设置会话管理,并且我有使用实现UserDetails接口的custoom类,因为我从文档中知道我需要ovveride方法:equals和hashcode
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimpleUser that = (SimpleUser) o;
return email.equals(that.email) &&
getPassword().equals(that.getPassword());
}
public int hashCode() {
return Objects.hash(email, getPassword());
}
安全设定:
http.anyRequest().authenticated()
.and()
.addFilterAt(authenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.formLogin()
.loginPage("/login")
.and()
.logout().invalidateHttpSession(true)
.logoutUrl("/logout").permitAll()
.logoutSuccessHandler(logoutSuccessHandler())
.and().csrf().disable().sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true);
这是我做的和会话管理无法正常工作,我能够从两个不同的浏览器在一台计算机上登录,我不知道我做错了什么,请帮助我!
可能有很多原因,为什么一切都没有按预期工作。
也许你可以通过以下方式进一步深入研究:
pom.xml
或你的手动版本管理Spring Boot和-Security版本冲突spring-boot-starter-security
equals
和hashCode
方法。