JAVA—咖啡館

          ——歡迎訪問rogerfan的博客,常來《JAVA——咖啡館》坐坐,喝杯濃香的咖啡,彼此探討一下JAVA技術,交流工作經驗,分享JAVA帶來的快樂!本網站部分轉載文章,如果有版權問題請與我聯系。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks
          前幾天客戶提出要強制使用HTTPS方式訪問Tomcat中的相關項目,于是研究了下,現將具體的步驟寫下: 

              主要分2步:讓tomcat能使用https--->強制使用https訪問 

          1.讓tomcat能使用https 

            A.在運行命令JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg  
              RSA  -keystore     C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore 
              這樣就生成了證書,將證書放到合適的地方(任意地方都可以) 

            B.打開tomcat目錄下的server.xml文件并找到關于ssl的相關段 
            
          1    <!-- Define a SSL HTTP/1.1 Connector on port 8443
          2    This connector uses the JSSE configuration, when using APR, the 
          3    connector should be using the OpenSSL style configuration
          4    described in the APR documentation -->
          5    <!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
          6    maxThreads="150" scheme="https" secure="true"
          7    clientAuth="false"  sslProtocol="TLS" />-->
          8    
           
           
            C.去掉注釋,添keystoreFile="C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore" keystorePass="tomcat"的屬性改動完成后配置為:
          1  <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"   maxThreads="150" scheme="https" secure="true" clientAuth="false" keystoreFile="C:\Tomcat\GMAE3.0Tomcat\tomcat.keystore" keystorePass="tomcat" sslProtocol="TLS" />
          2

            D.然后重啟tomcat就能使用HTTPS訪問 

          2.強制https訪問 

            在tomcat\conf\web.xml中的</welcome-file-list>后面,加上這樣一段: 

           1  <login-config>
           2      <!-- Authorization setting for SSL -->
           3      <auth-method>CLIENT-CERT</auth-method>
           4      <realm-name>Client Cert Users-only Area</realm-name>
           5  </login-config>
           6  <security-constraint>
           7      <!-- Authorization setting for SSL -->
           8      <web-resource-collection >
           9          <web-resource-name >SSL</web-resource-name>
          10          <url-pattern>/*</url-pattern>
          11      </web-resource-collection>
          12      <user-data-constraint>
          13          <transport-guarantee>CONFIDENTIAL</transport-guarantee>
          14      </user-data-constraint>
          15  </security-constraint>
          16

          完成以上步驟后,在瀏覽器中輸入http的訪問地址也會自動轉換為https了
          posted on 2013-06-04 11:29 rogerfan 閱讀(1057) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 桑植县| 宝清县| 康平县| 白城市| 吉首市| 茶陵县| 商都县| 普宁市| 措美县| 通山县| 正蓝旗| 通江县| 沙湾县| 明光市| 邹城市| 香河县| 沛县| 福建省| 绥中县| 高碑店市| 承德县| 长顺县| 青铜峡市| 静宁县| 晴隆县| 韩城市| 永州市| 辽阳市| 无极县| 扎囊县| 鞍山市| 万山特区| 建宁县| 岚皋县| 额尔古纳市| 阿拉善右旗| 南乐县| 西昌市| 宁蒗| 武城县| 宁津县|