-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Summary
When using session creation policy = STATELESS and form login, when authentication fails, the default failure handler creates a session but that is unexpected.
Actual Behavior
SimpleUrlAuthenticationFailureHandler is the default failure handler based on the below configuration. It has allowSessionCreation = true
. That causes it to create a session even when session creation policy is stateless: as evidenced by seeing a JSESSIONID in the response from authentication failure.
Expected Behavior
SimpleUrlAuthenticationFailureHandler should obey session creation policy.
There is a workaround because that handler has setter setAllowSessionCreation, so you can manually configure it. But, would it be desirable for it to follow session creation policy instead?
If you implement the workaround, then you no longer see a JSESSIONID in the response from authentication failure.
Configuration
protected void configure(HttpSecurity httpSecurity) throws Exception
{
httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
httpSecurity.formLogin()
.authenticationDetailsSource(createMyAuthenticationDetailsSource())
.successHandler(createMyStatelessAuthenticationSuccessHandler());
}
Version
Spring Security 4.1.3 (Spring Boot 1.4.2)
Sample
Example workaround if you wire SimpleUrlAuthenticationFailureHandler and setAllowSessionCreation(false):
@Bean(autowire = Autowire.BY_TYPE)
public SimpleUrlAuthenticationFailureHandler createFailureHandler()
{
SimpleUrlAuthenticationFailureHandler failureHandler = new SimpleUrlAuthenticationFailureHandler();
failureHandler.setAllowSessionCreation(false);
return failureHandler;
}
protected void configure(HttpSecurity httpSecurity) throws Exception
{
httpSecurity.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
httpSecurity.formLogin()
.authenticationDetailsSource(createMyAuthenticationDetailsSource())
.successHandler(createMyStatelessAuthenticationSuccessHandler())
.failureHandler(createFailureHandler());
}