会话未正确失效,出现错误 UT000010:会话无效

问题描述 投票:0回答:1

我将Struts 2.3版本升级到6.0。它已成功构建,但当我尝试登录应用程序时,我得到了

UT000010:会话无效 HubC5VAM4TUaSwQgPtLbbmAEXTAZii0VTrfXfNJw

在浏览器上。

我正在使用 Wildfly 24+ 支柱 6.0

错误堆栈:

1:21:41,611 INFO  [stdout] (default task-1) 2024-02-19 01:21:41,602 ERROR [org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler] Exception occurred during processing request: UT000010: Session is invalid HubC5VAM4TUaSwQgPtLbbmAEXTAZii0VTrfXfNJw

01:21:41,611 INFO  [stdout] (default task-1) java.lang.IllegalStateException: UT000010: Session is invalid HubC5VAM4TUaSwQgPtLbbmAEXTAZii0VTrfXfNJw

01:21:41,611 INFO  [stdout] (default task-1)    at io.undertow.server.session.InMemorySessionManager$SessionImpl.getAttribute(InMemorySessionManager.java:519) ~[undertow-core-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,611 INFO  [stdout] (default task-1)    at io.undertow.servlet.spec.HttpSessionImpl.getAttribute(HttpSessionImpl.java:122) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,611 INFO  [stdout] (default task-1)    at org.apache.struts2.dispatcher.SessionMap.get(SessionMap.java:157) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,611 INFO  [stdout] (default task-1)    at org.apache.struts2.dispatcher.SessionMap.put(SessionMap.java:175) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at org.apache.struts2.interceptor.csp.DefaultCspSettings.associateNonceWithSession(DefaultCspSettings.java:90) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at org.apache.struts2.interceptor.csp.DefaultCspSettings.addCspHeaders(DefaultCspSettings.java:78) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at org.apache.struts2.interceptor.csp.CspInterceptor.beforeResult(CspInterceptor.java:49) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:274) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at com.ge.hca.torch.presentation.securityfilter.TorchTokenSessionStoreInterceptor.doIntercept(TorchTokenSessionStoreInterceptor.java:176) ~[classes:?]

01:21:41,612 INFO  [stdout] (default task-1)    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,612 INFO  [stdout] (default task-1)    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:251) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,613 INFO  [stdout] (default task-1)    at org.apache.struts2.factory.StrutsActionProxy.execute(StrutsActionProxy.java:48) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,613 INFO  [stdout] (default task-1)    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:637) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,613 INFO  [stdout] (default task-1)    at org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:79) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,613 INFO  [stdout] (default task-1)    at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:140) ~[struts2-core-6.0.0.jar:6.0.0]

01:21:41,613 INFO  [stdout] (default task-1)    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,613 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,613 INFO  [stdout] (default task-1)    at com.ge.hca.torch.presentation.securityfilter.SqlInjectionAndXSSFilter.doFilter(SqlInjectionAndXSSFilter.java:79) ~[classes:?]

01:21:41,613 INFO  [stdout] (default task-1)    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at com.ge.hca.torch.presentation.securityfilter.AccessFilter.doFilter(AccessFilter.java:86) ~[classes:?]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71) ~[log4j-web-2.17.1.jar:2.17.1]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,614 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,615 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,615 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,615 INFO  [stdout] (default task-1)    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) ~[?:?]

01:21:41,615 INFO  [stdout] (default task-1)    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-2.2.8.Final.jar!/:2.2.8.Final]

01:21:41,615 INFO  [stdout] (default task-1)    at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) ~[undertow-servlet-2.2.8.Final.jar!/:2.2.8.Final]

这是我的登录操作代码

            if(null==mode)
            {
                HttpSession session = getServletRequest().getSession(false);
                log.debug(session + "" + getServletRequest().getSession(false));
                if (null != session) 
                {
                    session.invalidate();                   
                }
                //removed form above if condition during migration of struts2 as struts1 session was created in locale settings
                session = getServletRequest().getSession(true);
            }           
            userVO=(UserVO)getSessionObject(getServletRequest(),TorchConstants.GLOBAL_USERINFO_KEY);

这是我的登录操作父类代码的会话代码

   protected Object getSessionObject(HttpServletRequest req, String attrName) {
        HttpSession httpSession = null;
        httpSession = req.getSession(false);
        Object obj = null;
        if (null != httpSession) {
            obj = httpSession.getAttribute(attrName);
        }
        return obj;
    }

不知道如何处理这种情况。

java struts2 httpsession wildfly-11
1个回答
0
投票

旧会话失效后,您将无法使用。在该操作中,您已使 http 会话无效。

它是一个servlet会话对象,在典型的Struts2应用程序中应该避免使用。相反,您应该使用

SessionMap

然后,您继续重用执行

SessionMap
时保留在
beforeResult
中的旧会话。您也没有更新保留
SessionMap
对象的 Struts2 操作上下文。

如果您的操作类实现了

SessionAware
,那么会话映射将被注入到操作实例中。如果您使用参考,那么它也应该更新。如果您使用
ActionContext
,则更新操作上下文。

如果您创建一个新的

SessionMap
对象,那么将在内部初始化一个新的 http 会话,但您会丢失旧会话中的属性。

如果您想了解如何更新将使用新 http 会话并传输旧会话属性的

SessionMap
,请参阅 Struts 2 会话失效,将请求会话设置为新会话 答案。

© www.soinside.com 2019 - 2024. All rights reserved.