Rol*_*015 5 java spring spring-mvc spring-security spring-boot
我正在使用 Spring Security,我想为自动重定向到登录页面添加一个 flash 属性。但是,唯一的handle方法LogoutSuccessHandler有HttpServletRequest, HttpServletResponse,Authentication作为参数。如何RedirectAttributes在handle方法中检索以添加 flash 属性?或者有没有其他方法可以将 flash 属性添加到注销重定向?
对我来说,以下代码有效:
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
final FlashMap flashMap = new FlashMap();
flashMap.put("information", "You've been logged out.");
final FlashMapManager flashMapManager = new SessionFlashMapManager();
flashMapManager.saveOutputFlashMap(flashMap, request, response);
response.sendRedirect("/"); // or any other location you want
super.handle(request, response, authentication);
}
}
Run Code Online (Sandbox Code Playgroud)
灵感来自于用户@vallismortis 的这个答案。
| 归档时间: |
|
| 查看次数: |
435 次 |
| 最近记录: |