在我登錄之前,我可以在我的安全約束目錄之外打任何內容。如果我嘗試去安全約束目錄內的一個位置,它會將我重定向到表單登錄頁面。正如你所期望的那樣。經過身份驗證的用戶已嘗試訪問所擁有的會話
一旦登錄,我就可以開始我的業務,並在我的安全約束條件之外和內部尋找資源。
但是,當LTPA令牌到期(仍然有一個活動會話),我試圖去一個無限制的頁面,讓我們說像被重定向到登錄頁面,我得到的標題錯誤。
所以我想弄清楚一些事情: 1.我可以讓LTPA令牌不像我的會話那樣過期嗎? 2.當LTPA令牌執行時,我可以過期嗎? 3.爲什麼我無法匿名訪問不受限制的頁面?很明顯,我的LTPA令牌已過期,並嘗試重定向我登錄。在哪一點失敗。
好吧,所以得到了一個過濾器的地方。過濾器將未登錄的人重定向到登錄頁面。但問題再次是一旦ltpa令牌過期,該行失敗((HttpServletRequest) request).getSession(false)
拋出標題中的異常UnauthorizedSessionRequestException
。正如你所看到的,我試圖捕捉那個錯誤並且註銷。哪一個,woops,拋出另一個UnauthorizedSessionRequestException
。那我該如何不使用會話呢?
@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);
}
這個jsf如何關聯?你的問題沒有顯示任何關係 – Kukeltje
這是一個JSF應用程序,我認爲這是相關的信息。 –
如果它與問題相關,這是恰當的。你還可以添加'java','energy','global-warming'(由燃燒運行java所需的化石燃料引起;-))。請刪除它 – Kukeltje