2016-07-13 34 views
0

我想將https添加到Web應用程序的某個頁面。
申請已根據的Tomcat 7寫有3.2.9.RELEASE版本和作品。如何將HTTPS添加到Web應用程序中的註冊頁面?

我需要從任何http頁面移動:

http://app/index.html

https註冊頁面:

https://app/registration

在此之後,你可以移動到http爲好,例如:

http://app/presenter.html

我不需要這方面的任何身份驗證和授權。只需爲這一頁進行傳輸安全。保護用戶輸入的數據。

我需要什麼來實現這種行爲?

我不確切知道如何將HTTPS部分集成到應用程序中(我之前從未使用過HTTPS)。

+2

如果您只在一個頁面中添加https,那麼您很容易受到sslstrip攻擊。最好將https添加到整個網站,並使用HSTS。這是對抗中間人和ssltrip攻擊的唯一保護手段。 – Tom

+0

@Tom也許你可以展示一些調優的例子? –

+0

不是tomcat專家,對不起。 https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html,https://melo.myds.me/wordpress/lets-encrypt-for-tomcat-7-on-ds/或https ://community.letsencrypt.org/t/how-to-use-the-certificate-for-tomcat/3677沒有幫助? – Tom

回答

0

首先,您需要在您的Tomcat服務器中配置https支持。爲了快速入門,您可以使用自簽名證書。 要使用Java生成自簽名證書,您可以在Internet上找到許多資源,但我指的是以下鏈接How to configure Tomcat to support SSL or https - mkyong

您可以使用Java的keytool實用程序生成證書。

生成證書後,在Tomcat中配置HTTPS連接器。 您需要修改以下文件:$ TOMCAT_HOME/conf/server.xml。 在這裏,您可以添加https連接器標記或修改現有的標記(如果它已被取消註釋)。

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" 
      maxThreads="150" scheme="https" secure="true" 
      clientAuth="false" sslProtocol="TLS" 
     keystoreFile="c:\mykeystore" 
     keystorePass="password" /> 

之後,您將能夠在https上運行tomcat。

現在配置HTTPS URL在你的web應用程序,修改web.xml,然後添加以下代碼:

<security-constraint> 

    <display-name>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>*.jsp</url-pattern> 
     <url-pattern>*.htm</url-pattern> 
    </web-resource-collection> 

    <user-data-constraint> 
     <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint> 

</security-constraint> 

在標籤,你可以定義模式(或者所有的URL爲https或特定的)。

希望它有幫助。

+0

這種方法不需要任何彈簧安全配置? –

+0

上面提到的web.xml配置將可互換,以在spring安全中實施https。所以如果你的項目中有spring security,你可以使用https來啓用它,否則你可以在web.xml中配置它。 –

+0

我認爲spring安全配置是更好的方法。因爲它不需要任何外部配置,比如Tomcat。只需使用項目配置。 –

相關問題