I have a J2EE REST-based web application that uses Spring Security 4.0.1.RELEASE. I am configuring Spring Security with a Java-based configuration and have set the session creation policy to STATELESS like so:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(secureEnabled=true, prePostEnabled=true, jsr250Enabled=true, order=1)
public class DefaultSecurityBeansConfig extends WebSecurityConfigurerAdapter {
// ...
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()...; // additional config omitted for brevity
// ...
}
// ...
}
After reading this article about Spring Security session management, I believe that the SessionManagementFilter
filter should not be running in Spring Security's filter chain. But it definitely is. I can set a breakpoint in that class's doFilter
method, and it is run on every request to the server.
What is going on here? The fact that this filter is running is causing other unexpected behavior in my app that I thought had been configured away.
Thanks.
SessionManagementFilter
with aNullSecurityContextRepository
which won't store it. So basically it will always run but depending on the configuration it will do something or not. – UriiadoFilter
method calls anonAuthentication
method, which has registered as its only delegate strategy theChangeSessionIdAuthenticationStrategy
. This would seem to conflict with mySTATELESS
session creation policy. I don't have a session fixation strategy explicitly set, which if I'm not mistaken will default tomigrateSession
, but this behavior implies I'm somehow usingchangeSessionId
. I may end up posting a new question with these findings. – Fructification((HttpServletRequest) request).getSession()
). And thisChangeSessionIdAuthenticationStrategy
that is running keeps changing my JSESSIONID. According to Spring docs, the NEVER value ofSessionCreationPolicy
is supposed to make use of theHttpSession
if it exists, while the STATELESS value "will never create an HttpSession and will never use it to obtain theSecurityContext
". To me, that sounds like it shouldn't be messing with my JSESSIONID. I'm just really confused why it's interfering. – FructificationsessionFixation().none()
. However this will make your application less secure and vulnerable to session fixation attacks. I fail to see why changing the sessionid would break things, what is breaking be fixed instead of making your app less secure. – Uriia