Before I log in I can hit anything outside of my security constraint directory. If I try to go to a location inside of the security constraint directory it redirects me to the form login page. As you would expect.
Once logged in I can go about my business, and hit resources both outside and inside my security constraint.
But, when the LTPA token expires (Still have an active session) and I try to go to a unrestricted page, lets say like being redirected to the login page, I get the error in the title.
So a few things I would like to figure out: 1. Can I get the LTPA token to not expire like my session? 2. Can I expire my session when the LTPA token does? 3. Why can't I hit an unrestricted page anonymously? It's clearly recognizing that my LTPA token has expired and tries to redirect me to login. At which point it fails.
OK, So got somewhere with a filter. The filter redirects someone who isn't logged in to the login page. But the problem again is as soon as the ltpa token is expired this line fails ((HttpServletRequest) request).getSession(false)
throwing the exception in the title, UnauthorizedSessionRequestException
. So as you can see I tried to catch that error and do a log out. Which, woops, throws another UnauthorizedSessionRequestException
. So how am I to not use the session?
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain chain) throws IOException, ServletException
{
final String sourceMethod = "doFilter";
if (logger.isLoggable(Level.FINER)) {
logger.entering(sourceClass, sourceMethod, new Object[] { request, response, chain });
}
try {
final HttpSession session = ((HttpServletRequest) request).getSession(false);
final UserBean user = (session != null) ? (UserBean) session.getAttribute("userBean")
: null;
if (user == null || (user != null && !user.isLoggedOn())) {
final HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect("../login.jsf");
}
} catch (final UnauthorizedSessionRequestException exc) {
((HttpServletRequest) request).logout();
final HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect("../login.jsf");
} catch (final Exception exc) {
final ServletException exception = new ServletException(
"[UserBeanFilter] Exception doFilter.", exc);
logger.throwing(sourceClass, sourceMethod, exception);
throw exception;
}
chain.doFilter(request, response);
logger.exiting(sourceClass, sourceMethod);
}