【发布时间】:2018-10-21 21:41:15
【问题描述】:
我正在使用 Spring Boot 和 Thymeleaf 开发一个应用程序。
我的自定义登录页面中有以下 sn-p:
<p th:if="${param.logout}">Logged out successfully</p>
本段与以下安全配置相关联:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "*.css").permitAll()
.antMatchers("/myendpoint").authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.permitAll();
}
所以在注销后用户会被重定向到/login?logout 并显示注销消息。
我的问题是,当用户通过简单地将http://myserver:8080/login?logout 写入浏览器来明确导航到/login?logout 时,也会显示此消息。
是否可以阻止用户直接访问/login?logout(从而仅在实际注销时才显示消息)?
【问题讨论】:
-
使用非常短暂的cookie而不是查询参数...
-
如果用户未登录,您可能希望将用户从注销页面重定向回登录页面。
标签: java spring spring-security thymeleaf