url to specific page with spring security

Tags: , , ,



I have an Spring Boot application.

I need to send emails that contain a direct url to a specific page of the system, something like:

Please, on click on the following link to accept the offer: http://example.com/somepage?id=5

The desired behaviour is the following:

  1. The user clicks on the link contained on the email.
  2. The login page appears.
  3. The user logs in and the specific page of the link opens.

But this is not working. When the user clicks the URL, he goes directly to home page, instead of the specific page included in the link.

I have this method in controller:

@GetMapping("/home")
public String menu(Model model) {   
    
    return "home";
}

And this is the Spring Security Configuration class:

...
.formLogin()
            .loginPage("/login")
            .permitAll()
            .defaultSuccessUrl("/home", true)
        ...

Does anyone know what should I do to make it work properly?

Thanks a million.

Regards,

Answer

Please try to change .defaultSuccessUrl("/home", true) to .defaultSuccessUrl("/home", false)



Source: stackoverflow