Skip to content

Commit f837d21

Browse files
committed
add session Registy
1 parent ff7b3ad commit f837d21

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

springboot-springSecurity2/src/main/java/com/us/example/config/WebSecurityConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
2626

2727
@Autowired
2828
private CustomUserService customUserService;
29+
@Autowired
30+
SessionRegistry sessionRegistry;
2931

3032
@Autowired
3133
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@@ -48,10 +50,16 @@ protected void configure(HttpSecurity http) throws Exception {
4850
.antMatchers("/**")
4951
.permitAll()
5052
.and()
51-
.sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true);
53+
.sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true).sessionRegistry(sessionRegistry);
5254
http.httpBasic();
5355
}
5456

57+
@Bean
58+
public SessionRegistry getSessionRegistry(){
59+
SessionRegistry sessionRegistry=new SessionRegistryImpl();
60+
return sessionRegistry;
61+
}
62+
5563
@Bean
5664
public ServletListenerRegistrationBean httpSessionEventPublisher() {
5765
return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());

0 commit comments

Comments
 (0)