Spring Security Stateless Session

有些Scenario我們會需要使用Stateless的Session, 例如每次的web service call/API call,

會需要client每次都重新驗證一次。

以下說明如何使用Stateless session in Spring Security (Java configuration)。

version:

<spring.version>5.0.0.M4</spring.version>
<spring.security.version>4.2.1.RELEASE</spring.security.version>


@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

....

@Override
protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests().anyRequest().authenticated().and().httpBasic()
...
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

}

...

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s