I want to add some FlashMessages to the request/response cycle.
Since I add these attributes not within a Controller, but inside an AuthenticationFailureHandler, I cannot rely on the usual redirect attribute helper. Therefore I use RequestContextUtils to get the outputFlashMap and add the parameter I want. However, I can't access them in Thymeleaf, neither by using ${#request.getAttribute('message')} nor directly by using the key itself ${message}.
The handler class looks like this:
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
@Override
public void onAuthenticationFailure(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception) throws IOException {
FlashMap outputFlashMap = RequestContextUtils.getOutputFlashMap(request);
outputFlashMap.addTargetRequestParam("message", "Elvis says Aloha from Hawaii");
redirectStrategy.sendRedirect(request, response, "/secrets");
}
}
What am I missing here?