Skip to main content

Tomcat SSL Configuration and HTTP to HTTPS Redirect

SSL(Secure Sockets Layer)- Apache Documentation says "Transport Layer Security (TLS) and its predecessor, Secure Sockets Layer (SSL), are technologies which allow web browsers and web servers to communicate over a secured connection."

This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. This is a two-way process, meaning that both the server AND the browser encrypt all traffic before sending out data.

Setting Up Environment- In-order to continue this tutorial, we required tomcat in our system. You can download install-able file (.exe or .msi in case of Windows OS) or binaries files in form of .zip or .tar.gz from here. If you have downloaded install-able file then install it. If you have downloaded zip, then extract the compressed download file at your favorite location/path.

If you have installed the file then hit http://localhost:8080, you should be able to see web-page something like below -

If you have downloaded the binaries, extract the compressed file at your favorite path. Go to {tomcat-home}/bin and run the tomcat by double clicking on the file startup.bat(Windows OS) or startup.sh(Linux OS) then hit http://localhost:8080. Sometimes you need to give executable permission on the startup.sh file in Linux OS.

To make a shell script file executable, run the below command using terminal- 
    chmod +x filename.sh

Generating certificate for SSL - Run below command to create certificate on terminal or command prompt and fill the required details - 
   > keytool -genkey -alias tomcat -keyalg RSA -keystore <file-name>.keystore


Please use the password of your choice but remember it for future use. I have used 12345678 as password.

Go to {tomcat-home}/conf folder and edit server.xml file. Search and un-comment the below configuration - 

     <Connector
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           port="8443" maxThreads="200"
           scheme="https" secure="true" SSLEnabled="true"
           keystoreFile="conf/ssl_certificate.keystore" keystorePass="12345678"
           clientAuth="false" sslProtocol="TLS"/>                                    

Please change the value of keystoreFile and  keystorePass with yours and restart the tomcat. Now hit https://localhost:8443. Now you are seeing secured web-page.

If you hit http://localhost:8080 then it is not redirecting to https://localhost:8443 automatically. For the same we need to updated some more configurations as below.

HTTP to HTTPS Auto-redirect - 
After completing all the steps above, open web.xml file from {tomcat-home}/conf folder and add below configuration before <welcome-file-list> tag.


  <security-constraint>
    <web-resource-collection>
        <web-resource-name>Secured</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
Restart the tomcat and you are done with all configurations. Now if you hit http://localhost:8080, you will automatically redirect to https://localhost:8443.
Hope this will help you. Suggestions are most welcome. Keep visiting my blog :)

Comments

Popular posts from this blog

app-policy

PRIVACY POLICY Last updated April 19, 2023 This privacy notice for Team CoderzDuniya ( " Company ," " we ," " us ," or " our " ), describes how and why we might collect, store, use, and/or share ( " process " ) your information when you use our services ( " Services " ), such as when you: Download and use our mobile application ( Revenue Calculator) , or any other application of ours that links to this privacy notice Engage with us in other related ways, including any sales, marketing, or events Questions or concerns?  Reading this privacy notice will help you understand your privacy rights and choices. If you do not agree with our policies and practices, please do not use our Services. If you still have any questions or concerns, please contact us at droidamar007@gmail.com . SUMMARY OF KEY POINTS This summary provides key points from our privacy notice, but you can find out more details about any of these t

Working with MPAndroidChart (how to create Bar Chart using MPAndroidChart)

Hi Friends, In this tutorial i am going to show, "How to create Bar Chart using MPAndroidChart". There is a lot of libraries for creating charts in android like AChartEngine, MpAndroidChart, AndroidPlot etc. Your first question may be, Why MPAndroidChart. So MpAndroidChart provides better animation functionality and easy to use in comparision. Using  MPAndroidChart library  we can draw a: ·          Simple Bar Chart ·          Grouped Bar Chart ·          Horizontal Bar Chart ·          Simple Line Chart ·          Line Chart with Cubic Lines ·          Grouped Line Chart ·          Combined Line and Bar Chart ·          Pie Chart ·          Scatter Chart ·          Candlestick Chart ·          Radar Chart Here we will create Simple Bar Chart with multiple color based on ranging. Ok We start with coding part now. First of all create your project in Android Studio and add gradle dependency for  MPAndroidChart library  into y

Java Socket Basics(Socket Programming in Java) Part-2(UDP)

Hi friends, We are going to discuss about UDP Socket Programming . In previous post  we discussed about the differences between TCP & UDP and the sample example of TCP Socket Programming. Below is the sample example of chat application using UDP  Socket Programming . UDP Sample :-  We are going to create an small example which contains two classes. UdpServer.java:-  This is a server class. Means this class will serve the purpose of socket connection. DatagramSocket is the java class and serve the purpose of Server and Client both. The overloaded constructor of DatagramSocket class matters. DatagramPacket is the java class which is responsible to transmit the data/packet over the network from server to client and vice-versa. UdpClient.java:-  This is client class. This serves the purpose of client which will communicate to server and send data to server and receive the data sent by server. UdpServer.java import java.net.DatagramPacket ; import java.net.Datag