Fisrt, I need to say that I'm using session scoped bean. So before session is closed the preDestroy()
method is invoked
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "session")
public class MySessionBean {
@PreDestroy
public void preDestroy() {
//Do Smth with using Security principal
}
}
When I logout by using Spring Security utils everything goes fine, the preDestroy()
method is called.
The main problems come when I use
server.session-timeout = 60
or = 1
in application.properties
preDestroy()
is called approximately in 2.5 minutes after session has opened.- And much more interesting is that
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
isnull
.
BUT I've successfully loged out.
Also I've tried a
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
return (ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) ->
configurableEmbeddedServletContainer.setSessionTimeout(1, TimeUnit.MINUTES);
}
I have the same result.
Also the problem exists while using Provided Tomcat
UPDATE:
The weird thing is that if I manually after 1 minute check the session existence the method
preDestroy()
is called immediately. ButSecurity Principal
is alreadynull
Thanks in Advance!