提问人:M. Da 提问时间:8/30/2023 更新时间:8/30/2023 访问量:85
Spring-Boot 2.7 -> 3 升级后不再触发 SessionCreatedEvent
SessionCreatedEvent no longer fires after Spring-Boot 2.7 -> 3 upgrade
问:
在 Spring-Boot 2.7.x 中,我收到了 SessionCreatedEvent 和 SessionDestroyedEvent 事件。升级到 Spring Boot 3.0.x 后,这些事件不再传递到我的应用程序。不过,我仍然收到 SessionFixationProtectionEvent 事件。我正在使用 Redis 进行会话管理。我尝试使用Spring Boot 3.1.x,但没有帮助。
我在我的班上。@EnableRedisHttpSession(flushMode = FlushMode.IMMEDIATE, saveMode = SaveMode.ALWAYS, maxInactiveIntervalInSeconds = 600)
@Configuration
我已将SecurityFilterChain配置为:
return http
.securityContext((securityContext) -> securityContext
.requireExplicitSave(false)
)
.authorizeHttpRequests()
.requestMatchers(EndpointRequest.toAnyEndpoint()).anonymous()
.requestMatchers("/error", "/favicon.ico").permitAll()
.requestMatchers(HttpMethod.GET, "/login", "/assets/**").permitAll()
.anyRequest().authenticated()
.and()
.headers()
.frameOptions().sameOrigin()
.xssProtection().and()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.sessionManagement()
.invalidSessionStrategy(new RestfulApiInvalidSessionStrategy(new AntPathRequestMatcher("/api/**")))
.invalidSessionUrl("/login")
.sessionCreationPolicy(IF_REQUIRED)
.sessionFixation().changeSessionId()
.maximumSessions(2).maxSessionsPreventsLogin(false)
.expiredSessionStrategy(new RestfulApiInvalidSessionStrategy(new AntPathRequestMatcher("/api/**")))
.expiredUrl("/login?expired")
.and()
.and()
.formLogin()
.loginPage("/login").permitAll()
.successHandler(this.authenticationSuccessHandler)
.failureHandler(this.authenticationFailureHandler)
.and()
.httpBasic()
.and()
.csrf().disable()
.build()
因此,我的事件侦听器是:
@EventListener
public void onSessionCreated(SessionCreatedEvent event) {
log.info("session created");
}
@EventListener
public void onSessionDestroyed(SessionDestroyedEvent event) {
log.info("session destroyed");
}
@Order(Ordered.HIGHEST_PRECEDENCE)
@EventListener(SessionFixationProtectionEvent.class)
public void onSessionFixationProtectionEvent(SessionFixationProtectionEvent event) {
log.info("session migrated");
}
我已经注册了 HttpSessionEventPublisher:
@Bean
public ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() {
return new ServletListenerRegistrationBean<>(new HttpSessionEventPublisher());
}
我不确定我还需要做什么。它在 2.7 中有效,但在 3.0 中无效。我尝试注册并侦听 HttpSessionEvents,但这些似乎也没有被解雇。@WebListener
答: 暂无答案
评论