I have been using spring boot, with spring security and Ext Js as frontend. I added this piece of code as configuration for spring security. It means that, when the session expires the user will be redirected to the referenced url, right?
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.authorizeRequests().antMatchers("/", "/login/**").permitAll().and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/userAuth")
.permitAll()
.and()
.logout()
.permitAll()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/**").permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();
http.sessionManagement().maximumSessions(1).expiredUrl("/login?logout");
}
Everytime my frontend sends an ajax request to spring, and the user has lost session, spring turns the request into a get request to /login?logout, as to be expected, but the page does not get redirected. All I can see is the login page on the response content of the request, without any effect on the page the user is seeing.
Why does this happen? Am I missing any configuration or implementation here?
EDIT: Here is what my Ext Js for the AJAX request looks like:
onAuthCheck: function (users) {
var result = Ext.Ajax.request({
url: '/Queue/requests/loginCheck',
method: 'POST',
async: false,
params: {
usersInfo: Ext.encode(users)
},
success: function (conn, response, options, eOpts) {
console.log(response)
console.log(conn.status);
if (conn.status === 401 || conn.status === 302) {
location.href='/login?logout';
}
},
failure: function (conn, response, options, eOpts) {
console.log(response)
console.log(conn.status)
if (conn.status === 401 || conn.status === 302) {
location.href='/login?logout';
}
}
})
return (Ext.JSON.decode(result.responseText, true).success);
},
EDIT2: Here is what my request looks like: It has a request with status 302, and still Im getting 200 status on my AJAX response on JS code.