So legen Sie eine benutzerdefinierte ungültige Sitzungsstrategie in Spring Security fest

Ich entwickle eine Webanwendung, die auf Spring-Boot - 1.1.6, Spring-Security -3.2.5 und mehr basiert.

Ich verwende eine Java-basierte Konfiguration:

@Configuration
@EnableWebMvcSecurity
public class SecurityCtxConfig extends WebSecurityConfigurerAdapter {


    @Bean
    DelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint() {
        LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> map = new LinkedHashMap<RequestMatcher, AuthenticationEntryPoint>();
        Http403ForbiddenEntryPoint defaultEntryPoint = new Http403ForbiddenEntryPoint();
        map.put(AnyRequestMatcher.INSTANCE, defaultEntryPoint);
        DelegatingAuthenticationEntryPoint retVal = new DelegatingAuthenticationEntryPoint(map);
        retVal.setDefaultEntryPoint(defaultEntryPoint);
        return retVal;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        ExceptionHandlingConfigurer<HttpSecurity> exceptionHandling = http.exceptionHandling();
        exceptionHandling.authenticationEntryPoint(delegatingAuthenticationEntryPoint());
        http.logout().logoutSuccessHandler(new LogoutSuccessHandler() {

            @Override
            public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication arg2)
                    throws IOException, ServletException {
                response.setStatus(HttpServletResponse.SC_OK);
            }
        });
    }

}

Die Anforderung besteht darin, den HTTP-Status 401 zurückzugeben, falls das Sitzungscookie ungültig ist oder fehlt (egal aus welchem Grund). Ich sehe dasInvalidSessionStrategy aber ich finde keine Möglichkeit, es auf dem @ einzustellSessionManagementFilter. Kann mir jemand bitte erklären, wie ich meinen Plan umsetzen soll, oder ein anderer, der die Anforderung erfüll

Antworten auf die Frage(3)

Ihre Antwort auf die Frage