Перенаправление недействительной сессии HTTP не работает - PullRequest
0 голосов
/ 06 сентября 2018

Я пытаюсь перенаправить на URL выхода из системы или отправить запрещенный код в случае истечения времени сеанса HTTP. Из журналов видно, что тайм-аут http-сессии истекает и уничтожается.

Но он не перенаправляет его на страницу выхода из системы. Также он не посылает ЗАПРЕЩЕННЫЙ код. Он не попадает в тот фрагмент кода, который указан в invalidSessionStrategy.

Вот мой конфиг:

        http.sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
            .invalidSessionUrl(PropertyMgr.getXyzURL() + XyzConstants.LOGOUT_PAGE)
            .invalidSessionStrategy(new InvalidSessionStrategy() {
                @Override
                public void onInvalidSessionDetected(HttpServletRequest httpServletRequest,
                                                     HttpServletResponse httpServletResponse)
                        throws IOException, ServletException {
                    logger.info("***************** Invalid session strategy called ***********************");
                    httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);

                }
            })
            .and().addFilter(XyzSpringSecurityConfig.customExceptionTranslationFilter())
                .addFilterBefore(webServiceAuthenticationFilter(), XyzPreAuthenticationFilter.class)
                .authorizeRequests()
                .antMatchers("/services/**")
                .authenticated()
            .and()
                .csrf().requireCsrfProtectionMatcher(new CSRFRequestMatcher())
            .and()
                .addFilter(preAuthenticatedProcessingFilter())
                .authenticationProvider(XyzSpringSecurityConfig.preAuthenticatedAuthenticationProvider())
                .authorizeRequests()
                .antMatchers("/services/**").permitAll()
                .anyRequest()
                .authenticated()
            .and()
                .exceptionHandling()
                .authenticationEntryPoint(XyzSpringSecurityConfig.loginEntryPoint())
                .accessDeniedHandler(XyzSpringSecurityConfig.customAccessDeniedHandler())
                .and()
                .logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/Logout"))
                .logoutUrl(PropertyMgr.getXyzURL() + XyzConstants.LOGOUT_PAGE)
                .invalidateHttpSession(true)
            .and()
                .addFilterAfter(XyzSpringSecurityConfig.forceLogoutFilter(), XyzPreAuthenticationFilter.class)
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
                .invalidSessionUrl(PropertyMgr.getXyzURL() + XyzConstants.LOGOUT_PAGE)
                .invalidSessionStrategy(new InvalidSessionStrategy() {
                    @Override
                    public void onInvalidSessionDetected(HttpServletRequest httpServletRequest,
                                                         HttpServletResponse httpServletResponse)
                            throws IOException, ServletException {
                        logger.info("*****************Invalid session strategy called ***********************");
                        httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);

                    }
                })
            .and()
                .headers().xssProtection().disable();

Нужно ли создавать фильтр для перенаправления во время тайм-аута http сессии? Разве это не возможно с пружинной безопасностью?

...