【发布时间】:2021-05-04 12:49:25
【问题描述】:
您好团队我正在尝试设置每个用户的并发会话限制。我正在尝试使用会话管理来限制它,但它没有按预期工作。我尝试将最大会话数设置为 1,但我可以拥有超过 1 个活动会话。 请找配置
http.csrf().disable()
// take all the default security headers
.headers()
.contentTypeOptions().and()
.xssProtection().and()
.cacheControl().disable().addHeaderWriter(new StaticAndDynamicCacheControlHeaderWriter(cacheTimeDays))
.httpStrictTransportSecurity().and()
// add X-Frame-Options: SAMEORIGIN
.frameOptions().sameOrigin().and()
// Un-authenticated calls
.authorizeRequests()
.antMatchers("/api")
.permitAll()
.antMatchers("/api")
.access("authenticated or hasIpAddress('localhost')").and()
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).accessDeniedHandler(accessDeniedHandler).and()
// Login configuration - the default action here is POST.
.formLogin().permitAll().loginProcessingUrl(LOGIN_LOGOUT_URI).successHandler(authLoginSuccessHandler).failureHandler(authLoginFailureHandler)
.and()
// Logout configuration
.logout().permitAll().logoutRequestMatcher(new AntPathRequestMatcher(LOGIN_LOGOUT_URI, "DELETE")).logoutSuccessHandler(authLogoutSuccessHandler)
.and()
.addFilter(getJsonUsernamePasswordAuthenticationFilter())
.authorizeRequests().antMatchers("/api/**").authenticated().and()
.authorizeRequests().anyRequest().permitAll().and()
.sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(true).sessionRegistry(sessionRegistry());
【问题讨论】:
标签: java spring spring-security spring-session