Redirecting HTTP to HTTPS(SSL) in Tomcat

Step 1:  Configure ssl (for https) in Tomcat-Home/conf/server.xml


<Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false"
keystoreFile="C:/Users/rg141a/.keystore" keystorePass="password"
maxThreads="25" port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
scheme="https" secure="true" sslProtocol="TLS"  />



Step 2 : Add the connector for redirecting http(8080) port to https port (8443)
<Connector port="8080" enableLookups="false" redirectPort="8443" />  // redirecting the http to https ( from http://localhost:8080 to https://localhost:8443)


Step 3 : 
Modify the web.xml($CATALINA_HOME/webapps/yourapplication/WEB-INF/web.xml)
<security-constraint>
<web-resource-collection>
<web-resource-name>application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
         <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

 Forcing to switch from http to https, using a secure protocol. If you want to turn off the SSL,simply change CONFIDENTIAL to NONE.

Thats it - type http://localhost:8080/yourApp - will redirect to https://localhost:8443/yourApp   :-)


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...