I am trying to configure /login to land on my home page on successful authentication. For example, "http://localhost:8080/app/login", land me on my home page, which is "http://localhost:8080/app/home". If I click same URL again, it redirects me to http://localhost:8080/app. However, if I do http://localhost:8080/app/logout and then again try to login, its good.
Why does it not redirect me to same home page on trying to login multiple times?
http.csrf().disable().authorizeRequests().antMatchers(staticResources).permitAll().antMatchers("/login*").permitAll().anyRequest().authenticated().and()
.formLogin().loginPage("/login").defaultSuccessUrl("/home")
.failureHandler(authFailureHandler).successHandler(sessionTimeoutAuthSuccessHandler).permitAll().and()
.logout().logoutSuccessHandler(logoutSuccessHandler()).deleteCookies(JSESSIONID)
.invalidateHttpSession(true).clearAuthentication(true);
With the configuration you have shared, users will be redirected to "/home"
after authenticating successfully if they have not visited a secured page prior to authenticating.
If they have visited a secured page prior to authenticating, then they will be redirected to that page.
If you wish to always redirect to "/home"
, then you can set alwaysUse
to true
.
.defaultSuccessUrl("/home", true)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.