paulwong

          啟用TOMCAT的SSL

          本教程使用 JDK 6 和 Tomcat 7,其他版本類似。

          基本步驟:

          使用 java 創(chuàng)建一個(gè) keystore 文件
          配置 Tomcat 以使用該 keystore 文件
          測(cè)試
          配置應(yīng)用以便使用 SSL ,例如 https://localhost:8443/yourApp
          1. 創(chuàng)建 keystore 文件

          執(zhí)行 keytool -genkey -alias tomcat -keyalg RSA 結(jié)果如下
          loiane:bin loiane$ keytool -genkey -alias tomcat -keyalg RSA
          Enter keystore password:  password
          Re-enter new password: password
          What is your first and last name?
            [Unknown]:  Loiane Groner
          What is the name of your organizational unit?
            [Unknown]:  home
          What is the name of your organization?
            [Unknown]:  home
          What is the name of your City or Locality?
            [Unknown]:  Sao Paulo
          What is the name of your State or Province?
            [Unknown]:  SP
          What is the two-letter country code for this unit?
            [Unknown]:  BR
          Is CN=Loiane Groner, OU=home, O=home, L=Sao Paulo, ST=SP, C=BR correct?
            [no]:  y
           
          Enter key password for
              (RETURN if same as keystore password):  password
          Re-enter new password: password


          這樣就在用戶的主目錄下創(chuàng)建了一個(gè) .keystore 文件

          2. 配置 Tomcat 以使用 keystore 文件

          打開 server.xml 找到下面被注釋的這段
          <!--
          <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
              maxThreads="150" scheme="https" secure="true"
              clientAuth="false" sslProtocol="TLS" />
          -->

          干掉注釋,并將內(nèi)容改為
          <Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
              disableUploadTimeout
          ="true" enableLookups="false" maxThreads="25"
              port
          ="8443" keystoreFile="/Users/loiane/.keystore" keystorePass="password"
              protocol
          ="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
              secure
          ="true" sslProtocol="TLS" />

          3. 測(cè)試

          啟動(dòng) Tomcat 并訪問(wèn) https://localhost:8443. 你將看到 Tomcat 默認(rèn)的首頁(yè)。

          需要注意的是,如果你訪問(wèn)默認(rèn)的 8080 端口,還是有效的。

          4. 配置應(yīng)用使用 SSL

          打開應(yīng)用的 web.xml 文件,增加配置如下:
          <security-constraint>
              <web-resource-collection>
                  <web-resource-name>securedapp</web-resource-name>
                  <url-pattern>/*</url-pattern>
              </web-resource-collection>
              <user-data-constraint>
                  <transport-guarantee>CONFIDENTIAL</transport-guarantee>
              </user-data-constraint>
          </security-constraint>

          將 URL 映射設(shè)為 /* ,這樣你的整個(gè)應(yīng)用都要求是 HTTPS 訪問(wèn),而 transport-guarantee 標(biāo)簽設(shè)置為 CONFIDENTIAL 以便使應(yīng)用支持 SSL。

          如果你希望關(guān)閉 SSL ,只需要將 CONFIDENTIAL 改為 NONE 即可。

          如果是MAVEN的TOMCAT插件,則加入如下配置
          <build>
                  <finalName>test-dropbox</finalName>
                  <plugins>
                      <plugin>
                          <groupId>org.apache.maven.plugins</groupId>
                          <artifactId>maven-compiler-plugin</artifactId>
                          <version>2.5.1</version>
                          <configuration>
                              <source>1.6</source>
                              <target>1.6</target>
                          </configuration>
                      </plugin>
                      <plugin>
                          <groupId>org.apache.tomcat.maven</groupId>
                          <artifactId>tomcat7-maven-plugin</artifactId>
                          <version>2.0</version>
                          <configuration>
                              <httpsPort>8443</httpsPort>
                              <keystorePass>password</keystorePass>
                              <keystoreFile>C:\Users\PAUL\.keystore</keystoreFile>
                          </configuration>
                      </plugin>
                  </plugins>
              </build>






          posted on 2013-10-14 08:02 paulwong 閱讀(1831) 評(píng)論(0)  編輯  收藏 所屬分類: J2EETOMCAT

          主站蜘蛛池模板: 周宁县| 大城县| 壶关县| 乌拉特后旗| 那曲县| 安吉县| 长岛县| 金华市| 正安县| 图们市| 西乌珠穆沁旗| 崇仁县| 达日县| 云安县| 冕宁县| 保山市| 类乌齐县| 长子县| 乃东县| 犍为县| 大邑县| 阳信县| 赤城县| 迁安市| 岑巩县| 石渠县| 鸡西市| 花莲市| 夏津县| 凤城市| 北碚区| 五台县| 竹山县| 花莲市| 黄梅县| 沧源| 东宁县| 商河县| 济源市| 聂荣县| 习水县|