如何解决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 举报,一经查实,本站将立刻删除。