I'm trying to expire the sessions of my users when I update / delete them. This is my configuration:
@Bean
public SessionRegistry sessionRegistry () {
return new SessionRegistryImpl();
}
@Bean
public ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() { //(5)
return new ServletListenerRegistrationBean<HttpSessionEventPublisher>(new HttpSessionEventPublisher());
}
@Override
protected void configure (HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("*.jsp").authenticated()
.and()
.formLogin().loginPage("/login.html")
.defaultSuccessUrl("/")
.failureUrl("/login.html?failed=1")
.usernameParameter("email").passwordParameter("password")
.and()
.logout().logoutUrl("/logout.html")
.and()
.logout().logoutSuccessUrl("/");
http.sessionManagement()
.maximumSessions(100)
.maxSessionsPreventsLogin(false)
.expiredUrl("/ejercicios-programacion/")
.sessionRegistry(sessionRegistry());
}
But when I do:
@Autowired
private SessionRegistry sessionRegistry;
private boolean isEmpty () {
return sessionRegistry.getAllPrincipals().isEmpty();
}
(Obviously my class is a @Component so it is initialized by Spring)
It returns true, even though I'm logged in with 3 different users in different browser windows. Why is this happening?