I am using Spring Boot MVC in my application. I need to redirect the user to invalid-token.html page, if the token is invalid. When the token is invalid, the url is changes in the browser, but, the invalid-token.html page does not load.
I have configured the security to allow for /invalid-token path and also have the invalid-token.html file inside the resources directory.
Do I also need to have a controller mapping for /invalid-token path inside my controller?
@GetMapping("/confirm")
public RedirectView confirmUser(RedirectAttributes attributes, @RequestParam("token") String token){
// Find the user associated with the reset token
Optional<User> optionalUser= userService.findByConfirmationToken(token);
if (!optionalUser.isPresent()) {
//redirect user to reset password page.
attributes.addFlashAttribute("invalidToken", "Invalid Token. Please enter your email address.");
return new RedirectView("redirect:invalid-token");
}
}