24 小时后强制注销用户 Spring Security

问题描述

我有一个应用程序并且我已经实现了 Spring Security。现在我想在用户登录后 24 小时强制注销他,而不管他的活动如何。我怎样才能做到这一点?

public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler
{

    public void onAuthenticationSuccess(HttpServletRequest request,HttpServletResponse response,Authentication authentication)
            throws IOException 
    {
        Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
        request.getSession(false).setMaxInactiveInterval(60);
        response.sendRedirect("/successfullLogin");
    }
}

setMaxInactiveInterval 仅用于在不活动的情况下超时会话。

http
            .authorizeRequests()
              .antMatchers("/resources/**").permitAll()
              .antMatchers("/loginPage**").permitAll()
              .antMatchers("/admin/*").hasRole("ADMIN")
              .antMatchers("/guest/*").hasRole("GUEST")
              .antMatchers("/**").authenticated()  
              .and()
              .logout()
                 .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
              .and()
              .formLogin()
              .loginPage("/loginPage")
                .usernameParameter("username")
                .passwordParameter("password")
                .successHandler(new MyAuthenticationSuccessHandler())
                .failureUrl("/loginPage?error=true")
              .and()
                .exceptionHandling().accessDeniedPage("/forbiddenPage")
              .and().csrf().disable();

这是我的 spring 安全配置方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)