Java 如何覆盖部署到Tomcat的webapp中的安全约束

Java 如何覆盖部署到Tomcat的webapp中的安全约束,java,tomcat,jenkins,Java,Tomcat,Jenkins,我有点为难,但一个合理的解决方案可能会帮助很多人(甚至数千人?) 我想将最新版本的Jenkins(撰写本文时为1.599)部署到Tomcat容器(7.0.39),然后强制所有流量使用SSL 我将$CATALINA_BASE/conf/server.xml中的连接器设置为所需的类型。然后,我将以下内容添加到$CATALINA_BASE/conf/web.xml中 <security-constraint> <web-resource-collection> &l

我有点为难,但一个合理的解决方案可能会帮助很多人(甚至数千人?)

我想将最新版本的Jenkins(撰写本文时为1.599)部署到Tomcat容器(7.0.39),然后强制所有流量使用SSL

我将$CATALINA_BASE/conf/server.xml中的连接器设置为所需的类型。然后,我将以下内容添加到$CATALINA_BASE/conf/web.xml中

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Jenkins</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>

詹金斯
/*
保密的
然而,遗憾的是,这不起作用,因为它在詹金斯战争中被web.xml覆盖

<security-constraint>
  <web-resource-collection>
    <web-resource-name>other</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <!-- no security constraint --> 
</security-constraint>

其他
/*
据我所知,没有办法允许我从tomcatweb.xml强制设置。我不会在每次发布新版本时手动编辑我的WAR,这不是一个选项

因此,问题是,更改服务器或客户端web.xml以使默认设置仍然存在的最佳方法是什么,但我们可以选择强制传输机密的保证


欢迎提出任何想法!:)

不确定这是否有用,但我遇到了相反的问题。公司的政策是不允许PUT、DELETE或OPTIONS,因此在tomcat conf/web.xml中有这样一个部分:

<security-constraint>
  <web-resource-collection>
     <web-resource-name>
       restricted methods
     </web-resource-name>
     <url-pattern> /* </url-pattern>
     <http-method> PUT </http-method>
     <http-method> DELETE </http-method>
     <http-method> OPTIONS </http-method>
     <http-method> TRACE </http-method>
  </web-resource-collection>
  <auth-constraint />
</security-constraint>

限制性方法
/* 
放
删除
选择权
痕迹
我发现我可以在应用程序web.xml的子目录中覆盖它

<security-constraint>
   <web-resource-collection>
    <web-resource-name>REST Endpoints</web-resource-name>
    <url-pattern>/rest/*</url-pattern>
  </web-resource-collection>
</security-constraint>

剩余端点
/休息/*
但不适用于上下文根(以下选项不允许使用):


剩余端点
/*

这意味着您可以毫无问题地要求子目录使用SSL。不确定这是否足以满足您的jenkins要求。

我刚刚注意到以下语言:

当相同的url模式和http方法出现在多个安全模式中时 约束,模式和方法上的约束由 组合各个约束,这可能导致 无意中拒绝访问

这表明您指定的约束将被组合,这意味着您正在尝试的应该是有效的。您确定在服务器上正确配置了SSL吗?在应用程序中编辑web.xml是否真的解决了这个问题?同一篇文章的这一部分似乎建议,如果SSL配置不正确,它可能会退回到http:

要确保通过安全连接传输数据,请确保 已为服务器配置该SSL支持。SSL支持已被禁用 为GlassFish服务器配置

<security-constraint>
   <web-resource-collection>
    <web-resource-name>REST Endpoints</web-resource-name>
    <url-pattern>/*</url-pattern>
   </web-resource-collection>
</security-constraint>