【问题标题】:How to configure JBoss 4.0.* to make session cookie HttpOnly and secure?如何配置 JBoss 4.0.* 以使会话 cookie HttpOnly 和安全?
【发布时间】:2015-05-22 16:16:19
【问题描述】:

我试过了

< Context cookies="true" crossContext="true">

< SessionCookie secure="true" httpOnly="true" />

在 context.xml 中,但在 jboss4.0 中无法识别

我在java程序中试过

String sessionid = req.getSession().getId();
 resp.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + ";Path="+req.getContextPath()+"; Secure; Domain="+req.getServerName()+"; HttpOnly");

对于第二次请求,它不允许获取会话的会话验证对象,因此它显示会话过期页面

我尝试使用过滤器

public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain filterChain) throws IOException, ServletException {

                final HttpServletResponse response = (HttpServletResponse) res;

                final HttpServletRequest request = (HttpServletRequest) req;
                    System.out.println(response.containsHeader("SET-COOKIE"));
                if (response.containsHeader("Set-Cookie")) {  // *******

                    response.setHeader("SET-COOKIE", "JSESSIONID=" + request.getSession().getId() + "; Path=" + request.getContextPath()

                            + "; HttpOnly" + (request.isSecure()?SECURE_FLAG : ""));

                }

                filterChain.doFilter(req, res);

        }

如果我使用上述过滤器 response.containsHeader("SET-COOKIE") 或 response.containsHeader("Set-Cookie") 总是返回 false

谁能给我解决jboss 4.0 Jsessionid标志配置为安全和httponly的解决方案

【问题讨论】:

    标签: session-cookies configure jboss-4.0.x cookie-httponly


    【解决方案1】:

    server/default/deploy/jboss-web.deployer/conf/web.xml 下查找调用org.jboss.web.tomcat.filters.ReplyHeaderFilter 的过滤器并在初始化期间添加设置的cookie 参数,即

    <filter>
      <filter-name>CommonHeadersFilter</filter-name>
      <filter-class>org.jboss.web.tomcat.filters.ReplyHeaderFilter</filter-class>
      <init-param>
         <param-name>X-Powered-By</param-name>
         <param-value>Servlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0;</param-value>
      </init-param>     
        <init-param>
            <param-name>Set-Cookie</param-name>
            <param-value>Secure; HttpOnly</param-value>
        </init-param>
    

    【讨论】:

      【解决方案2】:

      我可以确认,对于 JBoss 4.0.3,它可以通过在 Filter 实现类中操作标头来工作。这对我有用:

      String sessionid = ((HttpServletRequest) request).getSession().getId();
      ((HttpServletResponse)response).setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; HttpOnly");
      

      我还没有确认为什么不支持通过 context.xml 的解决方案。我没有找到任何参考资料,只有博客文章声称在 JBoss 4 中实现它的唯一方法是编程。 http://syams18.blogspot.se/2012/01/setting-httponly-in-jboss-httponly-is.html

      【讨论】:

        猜你喜欢
        • 2023-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-04
        • 2022-01-07
        相关资源
        最近更新 更多