【发布时间】:2019-04-22 05:36:44
【问题描述】:
我在我的应用程序中使用 Spring Boot MVC。如果令牌无效,我需要将用户重定向到 invalid-token.html 页面。令牌无效时,浏览器中的url会发生变化,但是invalid-token.html页面不会加载。
我已将security 配置为允许/invalid-token 路径,并且资源目录中还有invalid-token.html 文件。
我是否还需要在我的控制器中为/invalid-token 路径提供控制器映射?
@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");
}
}
【问题讨论】:
标签: spring spring-boot spring-mvc