我们开发了一个 jsf web 应用程序,其中包含一个由 webapp 以编程方式注册的 Jaspic/JSR196 模块。
我们按照以下博客中的说明来实现这一点: http: //arjan-tijms.blogspot.pt/
该解决方案适用于验证用户:我们有一个接收用户名和密码并调用 request.authenticate 方法的 bean。该请求在服务器身份验证模块 (SAM) 中得到验证,并且用户通过了身份验证。
问题是,在 webapp 中导航时,会话似乎经常失效,这使得用户被重定向到登录页面。当 request.getUserPrincipal 在访问受保护的资源时返回 null 时,SAM 模块实现将用户重定向到登录页面。我们没有找到这种行为的模式。
在分析日志时,我们发现了一些抛出的异常:(有时这些异常会显示在网页中。)
HttpSession 无效
<Feb 26, 2013 5:13:30 PM GMT> <Error> <HTTP> <BEA-101020> <[ServletContext@1361767580[app:web-richfaces module:web-richfaces path:null spec-version:3.0]] Servlet failed with an Exception
java.lang.IllegalStateException: HttpSession is invalid
at weblogic.servlet.internal.session.SessionData.isNew(SessionData.java:891)
at weblogic.servlet.security.internal.SecurityModule.login(SecurityModule.java:252)
at weblogic.security.jaspic.servlet.JaspicSecurityModule.checkUserPerm(JaspicSecurityModule.java:85)
at weblogic.servlet.security.internal.SecurityModule.checkAccess(SecurityModule.java:95)
at weblogic.servlet.security.internal.SecurityModule.isAuthorized(SecurityModule.java:543)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:499)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:463)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2119)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
会话失效正在使用不同的线程进行
<Feb 26, 2013 5:16:12 PM GMT> <Error> <HTTP> <BEA-101020> <[ServletContext@1361767580[app:web-richfaces module:web-richfaces path:null spec-version:3.0]] Servlet failed with an Exception
java.lang.IllegalStateException: Session invalidation is in progress with different thread
at weblogic.servlet.internal.session.SessionData.invalidate(SessionData.java:880)
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.updateSessionId(ServletRequestImpl.java:3215)
at weblogic.servlet.internal.ServletObjectsFacadeImpl.updateSessionId(ServletObjectsFacadeImpl.java:54)
at weblogic.servlet.security.internal.SecurityModule.generateNewSession(SecurityModule.java:265)
at weblogic.servlet.security.internal.SecurityModule.login(SecurityModule.java:253)
at weblogic.security.jaspic.servlet.JaspicSecurityModule.checkUserPerm(JaspicSecurityModule.java:85)
at weblogic.servlet.security.internal.SecurityModule.checkAccess(SecurityModule.java:95)
at weblogic.servlet.security.internal.SecurityModule.isAuthorized(SecurityModule.java:543)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:499)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:463)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2119)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
响应已提交
<Feb 26, 2013 5:06:16 PM GMT> <Error> <HTTP> <BEA-101020> <[ServletContext@1361767580[app:web-richfaces module:web-richfaces path:null spec-version:3.0]] Servlet failed with an Exception
java.lang.IllegalStateException: Response already committed
at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1651)
at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:658)
at weblogic.security.jaspic.servlet.JaspicSecurityModule.checkUserPerm(JaspicSecurityModule.java:87)
at weblogic.servlet.security.internal.SecurityModule.checkAccess(SecurityModule.java:95)
at weblogic.servlet.security.internal.SecurityModule.isAuthorized(SecurityModule.java:543)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:499)
at weblogic.servlet.security.internal.WebAppSecurity.checkAccess(WebAppSecurity.java:463)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2119)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2089)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2074)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1513)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
以下日志条目显示未找到有效会话,因此用户被重定向到登录页面:
<HttpRequest@207744527 - /prototype-web-richfaces/pages/customer/customer.jsf: SessionID: MmGLRsrCKrVs2ms2ZYcJbxB1LLngk7pZcjPP4Fd071b1JJLPyLTg!1600091307 found in cookie header>
<HttpRequest@207744527 - /prototype-web-richfaces/pages/customer/customer.jsf: SessionID= MmGLRsrCKrVs2ms2ZYcJbxB1LLngk7pZcjPP4Fd071b1JJLPyLTg found for WASC=ServletContext@1361767580[app:web-richfaces module:web-richfaces path:/prototype-web-richfaces spec-version:3.0]>
<HttpRequest@207744527 - /prototype-web-richfaces/pages/customer/customer.jsf: Trying to find session: MmGLRsrCKrVs2ms2ZYcJbxB1LLngk7pZcjPP4Fd071b1JJLPyLTg!1600091307>
<HttpRequest@207744527 - /prototype-web-richfaces/pages/customer/customer.jsf: Trying other contexts to find valid session for id: MmGLRsrCKrVs2ms2ZYcJbxB1LLngk7pZcjPP4Fd071b1JJLPyLTg!1600091307>
<HttpRequest@207744527 - /prototype-web-richfaces/pages/customer/customer.jsf: Couldn't find valid session for id: MmGLRsrCKrVs2ms2ZYcJbxB1LLngk7pZcjPP4Fd071b1JJLPyLTg!1600091307>
[[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO authentication.jaspic.TestServerAuthModule - Request URI: /prototype-web-richfaces/pages/customer/customer.jsf
[[ACTIVE] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG authentication.jaspic.TestServerAuthModule - Principal is null. Redirecting to login page.
似乎容器使 Http Sessions 无效。但我们无法理解为什么。有什么帮助吗?