I am trying to write a before filter that will automatically redirect to the logic page
if the user is not authenticated:
before("/protected/*", (request, response) -> {
if (request.session().attribute(AppConstants.USER) == null) {
response.redirect("/login",401);
}
});
but it does not work.
If I access a protected URL, it just throws a raw ugly Jetty error page with a 401 code...but does not redirect to the /login page.
I tried different codes (200) just in case it was important, but makes no difference.
All the examples for before() filter only show halt(), but I want to just cleanly redirect the user to the login page.
Is there anything wrong with my code here?
thanks
Jacek
P.S. Spark rocks. Shows how good Java can be if you remove all the EE cruft.