繁体   English   中英

"Spring 安全注销不会清除经过身份验证的用户"

[英]Spring security logout does not clear authenticated user

我正在使用 Spring security 的默认注销机制来注销用户。 从我的前端应用程序(一个 React 应用程序)中,我在后端服务的“\/注销”上调用 GET。 但是,我看到注销后未清除身份验证详细信息,并且报告同一用户从上次登录时登录。 但是当从 Postman 调用相同的 '\/logout' URL 时,身份验证被清除。 这是我的安全配置:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type"));
        corsConfiguration.setAllowedOriginPatterns(Arrays.asList("*"));
        corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PUT","OPTIONS","PATCH", "DELETE"));
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.setExposedHeaders(Arrays.asList("Authorization"));

        http
                .cors()
                .configurationSource(request -> corsConfiguration)
                .and()
                .csrf()
                .disable()
                .authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS,"/**").permitAll()
                .antMatchers("/notes/**")
                .authenticated()
                .antMatchers("/register")
                .permitAll()
                .and()
                .logout(logout -> logout
                        .permitAll()
                        .logoutSuccessHandler((request, response, authentication) -> {
                                    response.setStatus(HttpServletResponse.SC_OK);
                                }
                        )
                        .invalidateHttpSession(true)
                        .clearAuthentication(true)
                )

                .httpBasic();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM