The definition of redirection after a successful login should be applied to Spring Security, not Spring MVC.
th:action defines the Spring security endpoint that will handle the authentication request. It does not define a redirect URL. Out of the box, Spring Boot Security will provide you with the /login endpoint. By default, Spring Security will be redirected after entering the protected resource that you were trying to access. If you want to always redirect to a specific URL, you can force this through the HttpSecurity configuration object.
Assuming you are using the latest version of Spring Boot, you should use JavaConfig.
Here is a simple example:
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userService; @Override protected void configure(HttpSecurity http) throws Exception {
Note that you need to define a proprer endpoint to serve content for the URL /success.html . The static resource, available by default in src/main/resources/public/ , could do the trick for testing purposes. I would rather define a secure URL served by Spring MVC controller serving content with Thymeleaf. You do not want any anonymous user to access the success page. Thymeleaf as some useful features for interacting with Spring Security when rendering HTML content.
Regards, Daniel
source share