Несколько сессий создаются для одного и того же пользователя - PullRequest
0 голосов
/ 25 марта 2019

Прежде всего, извините за мой плохой английский, у меня проблема с управлением сеансом, у меня есть ApplicationListener, который выполняет некоторый код для событий HttpSessionDestroyed.

Я также добавил журнал для каждого HttpSessionCreatedEvent.

Иногда и случайным образом у меня возникает несколько HttpSessionCreatedEvent, когда я тестирую свое приложение в локальном режиме, и Spring Security отключает пользователя и повторно подключает его без фронтальных взаимодействий (идентификатор сеанса был изменен, и его невозможно увидеть безжурналы).Я думаю, что это как-то связано с тайм-аутом сеанса, потому что я могу легко воспроизвести его, сократив продолжительность сеанса.

Я пробовал разные решения, но не понимаю причину проблемы.

Я хочу решить эту проблему, потому что я думаю, что это причина других проблем, с которыми я сталкиваюсь с моим приложением.

Вот мой ApplicationListener

@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
    if (applicationEvent instanceof HttpSessionCreatedEvent) { //If event is a session created event
        LOGGER.info("Session created {}", ((HttpSessionCreatedEvent) applicationEvent).getSession().getId());

    } else if (applicationEvent instanceof HttpSessionDestroyedEvent) { //If event is a session destroy event
        HttpSession session = ((HttpSessionDestroyedEvent) applicationEvent).getSession();
        LOGGER.info("Session destroyed {}", session.getId());
        CLUserInfos clUserInfos = (CLUserInfos) session.getAttribute("userInfos");
        FolderEngagementSessionBean folderEngagementSessionBean =  (FolderEngagementSessionBean)session.getAttribute("scopedTarget.folderEngagementSessionBean");

        if (folderEngagementSessionBean != null && folderEngagementSessionBean.getFolderId() != null) {
            this.dossierDeblocageProcessor.gererSortieDossier(folderEngagementSessionBean.getFolderId(), clUserInfos, session.getId());
        }
    }
}

А вот моя SecurityConfiguration

    http
            .csrf().ignoringAntMatchers(
            "/fileupload/**",
            "/js/lib/ckeditor/ckeditor_4.5.6/filemanager/upload/simpleuploader/**",
            "/js/lib/ckeditor/ckeditor_4.5.6/filemanager/browser/default/connectors/jsp/connector/**",
            "/securecert/RequestSimplifiedConnect*",
            "/RequestAutoLogonSG*",
            "/SAMLConnectSG*",
            "/securecert/RequestToken*",
            "/authentification*"
    )
            .and()
            .headers().frameOptions().disable().and()
            .addFilterBefore(new BrowserFilter(), UsernamePasswordAuthenticationFilter.class)
            .addFilterBefore(new CLTokenAuthenticationFilter(authenticationManager(), clAuthenticationSuccessHandler), UsernamePasswordAuthenticationFilter.class)
            .authorizeRequests()
            .antMatchers("/css/**", "/fo/**", "/images/**", "/js/**", "/bo/images/**", "/errors/**").permitAll()
            .antMatchers("/navigateurNonGere").permitAll()
            .antMatchers("/supervision*").permitAll()
            .antMatchers("/expire*").permitAll()
            .antMatchers("/securecert/RequestToken*").permitAll()
            .antMatchers("/securecert/RequestSimplifiedConnect*").permitAll()
            .antMatchers("/SAMLConnectSG*").permitAll()
            .antMatchers("/RequestAutoLogonSG*").permitAll()
            .antMatchers("/authentification*").anonymous() // Allowing request parameters
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/authentification")
            .failureHandler(new CLAuthenticationFailureHandler())
            .successHandler(clAuthenticationSuccessHandler)
            .passwordParameter("motDePasse")
            .permitAll()
            .authenticationDetailsSource(new CLAuthenticationDetailsSource())
            .and()
            .logout()
            .logoutUrl("/authentification/logout")
            .logoutSuccessHandler(cLLogoutSuccessHandler)
            .invalidateHttpSession(true);

    http.exceptionHandling().accessDeniedHandler(clAccessDeniedHandler);
    http.sessionManagement()
            .maximumSessions(1)
            .maxSessionsPreventsLogin(true)
            .expiredUrl("/expire")
            .and()
            .invalidSessionUrl("/expire");
}

Вот мои журналы, которые я не понимаю, потому что я просто тестирую свое приложение с одним пользователем.

[INFO] [fr.cl.extranet.web.listeners.session.LogoutListener: 31] [25/03] [16:27:18] Сессия создана CA8E429A831823738124B761AC21E235 [INFO] [fr.cl.extranet.web.listeners.session.LogoutListener: 31] [25/03] [16:27: 18] Сеанс создан.web.listeners.session.LogoutListener: 31] [25/03] [16:27:18] Сессия создана 6B16F535EC4758CD94536DD31F2590FC

Можете ли вы помочь мне разобраться в проблеме, пожалуйста?

...