Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Spring Security without sessions?

I am building a web application with Spring Security that will live on Amazon EC2 and use Amazon's Elastic Load Balancers. Unfortunately, ELB does not support sticky sessions, so I need to ensure my application works properly without sessions.

So far, I have setup RememberMeServices to assign a token via a cookie, and this works fine, but I want the cookie to expire with the browser session (e.g. when the browser closes).

I have to imagine I'm not the first one to want to use Spring Security without sessions... any suggestions?

like image 857
Jarrod Carlson Avatar asked Mar 24 '10 00:03

Jarrod Carlson


People also ask

Does Spring Security use session?

By default, Spring Security will create a session when it needs one — this is “ifRequired“. For a more stateless application, the “never” option will ensure that Spring Security itself won't create any session. But if the application creates one, Spring Security will make use of it.

How do I turn off spring session?

You can disable Spring Session by setting the store-type to none . For setting the timeout of the session you can use the spring. session. timeout property.


1 Answers

In Spring Security 3 with Java Config, you can use HttpSecurity.sessionManagement():

@Override protected void configure(final HttpSecurity http) throws Exception {     http         .sessionManagement()             .sessionCreationPolicy(SessionCreationPolicy.STATELESS); } 
like image 165
Ben Hutchison Avatar answered Oct 03 '22 10:10

Ben Hutchison