[英]How redirect user to login page after try to execute ajax request if spring security session is timeout?
I have spring boot app with spring security. 我有弹簧安全的春季启动应用程序。 I need check redirect to login page if user make request after session time out.
如果用户在会话超时后发出请求,我需要检查重定向到登录页面。 I have 2 page:
login
and index
. 我有2页:
login
和index
。 On index
page I get requests by Ajax
. 在
index
页面上,我收到了Ajax
请求。
I open index page. 我打开索引页面。 wait 30 sec.
等30秒 Try update page after Session timeout but I not redirect to login page.
在会话超时后尝试更新页面,但我没有重定向到登录页面。 But if I try update page
F5
spring redirect me to login page. 但如果我尝试更新页面
F5
spring将我重定向到登录页面。 But if I try make ajax request - it work find and I not redirect. 但是,如果我尝试发出ajax请求 - 它可以找到并且我不会重定向。
It is my configs: 这是我的配置:
http.authorizeRequests().
antMatchers("/css/**").permitAll()
.antMatchers("/", "/index/**").hasRole("USER")
.anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/login").permitAll().defaultSuccessUrl("/index")
.and()
.logout().logoutUrl("/logout").permitAll().logoutSuccessUrl("/login");
http.csrf()
.disable()
.authorizeRequests()
.antMatchers("/resources/**", "/**").permitAll()
.anyRequest().permitAll()
.and();
and button on index page: 和索引页面上的按钮:
<button type="button" class="btn btn-primary" onclick="reload()">show</button>
and js method: 和js方法:
function reload() {
table.ajax.reload(null, false);
}
When I press "show" button - my table send request to spring controller(Session already invalid) and controller return data and table update success/ But I need redirect user to login page. 当我按下“显示”按钮 - 我的表发送请求到spring控制器(Session已经无效)和控制器返回数据和表更新成功/但我需要将用户重定向到登录页面。
http
.authorizeRequests()
.antMatchers("/css/**", "/resources/**").permitAll()
// ??? .antMatchers("/", "/index/**").hasRole("USER")
.anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/login").permitAll()
.defaultSuccessUrl("/index")
.and()
.logout()
.logoutUrl("/logout").permitAll().logoutSuccessUrl("/login")
.and()
.csrf()
.disable();
Can you try this ? 你能试试吗? and
.antMatchers("/", "/index/**").hasRole("USER")
is very confused. 和
.antMatchers("/", "/index/**").hasRole("USER")
。 .antMatchers("/", "/index/**").hasRole("USER")
非常困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.