I have a Spring MVC webapp that uses Spring Security. I want to add “Store is closed” functionality – i.e. if I set the store to be closed, regardless of where the user tries to navigate on my site they will end up on the page saying “Store is closed”.
I have implemented a Security Filter as follows (and can wire it in fine):
public class ClosedFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest req,
HttpServletResponse response,
FilterChain chain) throws ServletException, IOException {
if(storeIsClosed()) {
//do something useful here
}else {
chain.doFilter(req, response);
}
}
}
But am unsure what to put in the “//do something useful here” bit. I have tried:
throw new StoreIsClosedException(); //extends RuntimeException
but I can’t then map my exception to my view. I also tried
response.redirect("myClosedView");
with no luck. What I want is something conceptually like:
return new ModelAndView("closed");
Thanks.
I ended up with a solution, I changed my filter to:
and then added this to my security.xml