Handle session timeout for multiple login form springboot web

320 Views Asked by At

I build a webapp with multiple login form (1 for user, 1 for admin). I have a problem when session timeout, In case Im in admin dashboard page, if session timeout I want it go to admin login page. In case Im in user dashboard page, if session timeout, it will go to user login page.

but currently both of them go to user login page (not go to admin login page if the logged in user is admin)

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {

    @Configuration
    @Order(2)
    public static class ApartmentManagerSecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {

            http.authorizeRequests()....and()
                    .sessionManagement().maximumSessions(1).and().invalidSessionUrl("/userLoginForm");
        }
    }

    @Configuration
    @Order(1)
    public static class GovernmentStaffSecurityConfig extends WebSecurityConfigurerAdapter {

        protected void configure(HttpSecurity http) throws Exception {
            http.antMatcher("/gs/**").authorizeRequests()...
                    .and().sessionManagement().maximumSessions(1).and().invalidSessionUrl("/adminLoginForm");
        }
    }
}
1

There are 1 best solutions below

0
R.G On

invalidSessionUrl - the URL to redirect to when an invalid session is detected

Configuring the invalidSessionUrl("/gs/adminLoginForm") should match antMatcher("/gs/**") to get the admin login page

Note : I have not tried this out .