We had the exact same problem and I think I have solved it. At least I was able to get the HC session id to be sent to session registry's removeSession when user logs out.
The problem was that HttpSessionDestroyedEvents don't get fired for HC-wrapped session objects, but instead for "native" sessions. This is because the native session gets invalidated and thus the servlet container's session destroyed notification fired only after the HC WebFilter has done it's own cleanup. Therefore the HttpSessionEventPublisher that is responsible for publishing those events to Spring's listeners only sees the native session, not the HC-wrapped one.
In our system the problem only surfaced in logout, when session information in (HC-distributed) concurrent session registry didn't get properly updated.
My solution was to create my own LogoutHandler that fires HttpSessionDestroyedEvent to Spring's ApplicationEventListeners immediately before continuing to invalidate the session. This way, the session object for which the event is generated is the correct HC-wrapped session and session registry (and other listeners) sees HC's session ID instead of the native (servlet container generated) id.
The downside for this is that you cannot configure the logout mechanism using spring's <security:logout> -directive, instead you must manually configure the LogoutFilter and provide it with correct handlers and pass it as a custom filter to spring security.
Code examples below
LogoutHandler:
public class EventFiringSecurityContextLogoutHandler extends SecurityContextLogoutHandler implements ApplicationContextAware {
ApplicationContext applicationContext;
@Override
public void logout(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) {
if (isInvalidateHttpSession()) {
applicationContext.publishEvent(new HttpSessionDestroyedEvent(request.getSession()));
}
super.logout(request, response, authentication);
}
@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
And LogoutFilter configuration:
<bean id="customLogoutHandler" class="EventFiringSecurityContextLogoutHandler">
</bean>
<bean id="customLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<constructor-arg index="0" ref="customLogoutSuccessHandler"></constructor-arg>
<constructor-arg index="1">
<list>
<ref bean="customLogoutHandler"/>
</list>
</constructor-arg>
<property name="filterProcessesUrl" value="/logoutProcess"/>
</bean>
<security:http ...>
...
<security:custom-filter ref="customLogoutFilter" position="LOGOUT_FILTER"/>
</security:http>
Need still more testing but at a first glance this seems to solve the problem for us.