轉帖保存web
配置jboss的HTTP請求走SSL(HTTPS協議)apache
l 生成keystore 文件瀏覽器
用keytool生成server.keystore文件:服務器
進入命令行app
C:\Documents and Settings\new>jsp
keytool -genkey -alias tc-ssl -keyalg RSA -keystore c:\server.keystore -validity 3650網站
會提示要求輸入私鑰信息。url
生成完後放入\jboss安裝目錄\server\default\conf下spa
l 修改D:\jboss-4.2.2.GA\server\default\deploy\jboss-web.deployer\server.xml文件命令行
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/server.keystore" keystorePass="123456"
keystoreType="jks"
/>
去掉該段註釋,添加代碼(紅色標註部分)
keystoreFile後面的內容是server.keystore文件的相對路徑。
keystorePass後面的內容是生成文件是的密碼。
l 修改完成後啓動JBOSS,訪問
https://127.0.0.1:8443/teamnet/project/login.jsp
點擊查看證書
是否繼續選擇是。
成功訪問,注意端口號爲配置文件中的8443,能夠根據須要修改。
問題:訪問原來的http://127.0.0.1:8080/teamnet/project/login.jsp也一樣能夠訪問頁面
l 修改web.xml文件,配置一個HtmlAdaptor。添加代碼:
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<description>
An example security config that only allows users with
the role JBossAdmin to access the HTML JMX console web
application
</description>
<url-pattern>/</url-pattern>
<!-- <http-method>GET</http-method>
<http-method>POST</http-method> -->
</web-resource-collection>
<!--<auth-constraint>
<role-name>JBossAdmin</role-name>
</auth-constraint> -->
<user-data-constraint>
<description>Protection should be CONFIDENTIAL</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
再次啓動JBOSS服務器,訪問http://127.0.0.1:8080/teamnet/project/login.jsp
能夠看到訪問http已經被自動的轉到https協議進行訪問。
另外若是jboss有啓用APR,那麼啓動時會報錯(No Certificate file specified or invalid file format ).
此時須要將傳統配置中
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" 。。。
的protocol修改成
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
。。。
最後:
用合法證書替換自簽名證書
依據上面文章的操做,在瀏覽器上打開https時,會提示證書錯誤。這個時候就須要去申請一個合法證書,收費的或是免費的都行。免費的證書將不會在
地址欄顯示公司名稱。
1.相似上文第一步,產生keystore文件
keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore keystore.jks -storepass password
輸入名稱時,要與域名相同,例如immtest.immerp.com
2.生成證書請求文件(CSR)
Keytool -certreq -alias server -sigalg SHA1withRSA -file certreq.csr -keystore keystore.jks -keypass password -storepass password
3.在證書申請網站,提交csr文件。審覈經過後發將證書經過郵件發送回來。這裏能夠採用www.comodo.com提供的免費證書,90天有效,不限制續用。
4.郵件中通常包含一個或多個的CA證書和服務器域名證書。先分別導入CA證書,最後導入域名證書。
CA證書的別名能夠隨意,域名證書的別名與生成keystore時的要相同.(下面用comodo頒發的證書爲例)
keytool -import -trustcacerts -alias AddTrustExternalCARoot -file AddTrustExternalCARoot.crt -keystore keystore.jks
keytool -import -trustcacerts -alias intermediate1 -file ComodoUTNSGCCA.crt -keystore keystore.jks
keytool -import -trustcacerts -alias intermediate2 -file UTNAddTrustSGCCA.crt -keystore keystore.jks
keytool -import -trustcacerts -alias intermediate3 -file EssentialSSLCA_2.crt -keystore keystore.jks
keytool -import -trustcacerts -alias server -file immtest_immerp_com.crt -keystore keystore.jks
5.將文件keystore.jks放到替換原來的keystore文件,重啓jboss。