@Autowired
private FindByIndexNameSessionRepository<ExpiringSession> sessionRepository;
@Bean
SpringSessionBackedSessionRegistry sessionRegistry() {
return new SpringSessionBackedSessionRegistry<ExpiringSession>(
this.sessionRepository);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
//@formatter:off
http.formLogin().and()
.logout().and()
.csrf().disable()
.sessionManagement()
.maximumSessions(2)
.sessionRegistry(sessionRegistry())
// set to true to prevent logins after reaching max sessions:
.maxSessionsPreventsLogin(false)
.and()
.and()
.authorizeRequests()
.antMatchers("/").authenticated();
//@formatter:on
}