在Tomcat 6中使用SSL和非SSL

Chr*_*ner 5 tomcat tomcat6

我有一个Tomcat 6服务器,我想要一切都在SSL背后,但我希望通过非ssl可以访问一个servlet.是否可以这样配置Tomcat?它目前设置为将所有请求转发到安全端口.

Jos*_*seK 5

实现此目的的一种方法是编辑Web应用程序的web.xml.

我假设您已经设置了网络应用程序,以便将所有请求强制转换为https,<transport-guarantee> CONFIDENTIAL如下所示

<security-constraint>
      <display-name>Example Security Constraint</display-name>
      <web-resource-collection>
         <web-resource-name>Protected Area</web-resource-name>
     <!-- Define the context-relative URL(s) to be protected -->
         <url-pattern>/*</url-pattern>
     <!-- If you list http methods, only those methods are protected -->
     <http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
     <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
         <role-name>tomcat</role-name>
     <role-name>role1</role-name>
      </auth-constraint>
      <user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
    </security-constraint>
Run Code Online (Sandbox Code Playgroud)

现在为您希望绕过https的servlet添加另一个块.

    <security-constraint>
<web-resource-collection>
<web-resource-name>Unsecured resources</web-resource-name>
<url-pattern>/jsp/openforall.jsp</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint> 
Run Code Online (Sandbox Code Playgroud)

现在可以通过http访问此URL openforall.jsp.

注意:如果有人以这种方式访问​​,此URL也将在https上可用.