![](/img/trans.png)
[英]Spring Security - session timeout redirection - how redirection initiated
[英]Spring autherization http security redirection, session issue
我正在使用 Spring http security(Enablewebsecurity) 来管理会话。 但我面临的问题是,每当我启动应用程序时,应用程序总是打开主页而不是登录页面。 这里的要求是如果 session 出来了,需要到 go 登录页面。 session 也需要超时 30 分钟。 下面的代码有什么问题吗,
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/login").setViewName("login");
}
尝试在 antmatcher 之后 remove.permitAll() 并重试
对于添加 session 管理,
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.sessionManagement()
.invalidSessionUrl("/invalidSession.html")
.and()
.logout()
.permitAll();
在应用程序属性中,您需要添加 session 超时。
server.servlet.session.timeout=30m
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.