spring boot+react中的会话超时

vmjh9lq9  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(220)

我可以在web.xml中配置会话超时,但在会话超时后,会从react端收到错误。使用Spring Security 和jwt令牌。
websecurity.java

@Configuration
@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailServiceImpl userDetails;

    @Autowired
    JWTAuthenticationFilter jwtRequestFilter;

    @Autowired
    public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetails).passwordEncoder(getPasswordEncoder());
    }

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().disable().authorizeRequests()
                .antMatchers(HttpMethod.GET, "/index*", "/static/**", "/*.js", "/*.json", "/*.ico", "/*.png")
                .permitAll().antMatchers("/resources/**", "/login", "/", "/actuator").permitAll()
                .antMatchers("/authenticate/**", "/identity/**").permitAll().anyRequest().authenticated().and().cors().and()
                .exceptionHandling().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

    }

    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

web.xml

<session-config>
    <session-timeout>1</session-timeout>
</session-config>

我尝试了sessionmanagement().invalidsessionurl(“url”),但在登录时它总是只重定向到无效的url。没有用于登录的api,我们直接从react加载。请让我知道如何在会话超时时重定向到登录页面?如何从React端处理错误?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题