{"id":5940,"date":"2012-06-29T13:01:53","date_gmt":"2012-06-29T07:31:53","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=5940"},"modified":"2017-04-24T15:59:44","modified_gmt":"2017-04-24T10:29:44","slug":"how-to-configure-ssl-on-tomcat-server-and-run-grailsjava-application-on-https","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-configure-ssl-on-tomcat-server-and-run-grailsjava-application-on-https\/","title":{"rendered":"How to configure SSL on Tomcat server and run Grails\/Java application on HTTPS"},"content":{"rendered":"<p><!-- \t\t@page { margin: 2cm } \t\tP { margin-bottom: 0.21cm } -->To run your <a title=\"Grails App\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails application<\/a> on SSL, firstly you need to configure the Tomcat server.<\/p>\n<p>Here in this example, I will show how to configure Tomcat instance and run Grails\/Java application.<\/p>\n<p>For SSL\/HTTPS:<\/p>\n<ol>\n<li>We need <strong>.keystore<\/strong> file. You can generate it by using command\u201c<span style=\"color: #000000;\"><strong>keytool<\/strong><\/span> <span style=\"color: #000000;\"><strong>-genkey\u201d. <\/strong><\/span><span style=\"color: #000000;\">Run this command<\/span> <span style=\"color: #000000;\">on linux terminal or window cmd,<\/span> <span style=\"color: #000000;\">follow<\/span> <span style=\"color: #000000;\">the<\/span> <span style=\"color: #000000;\">instructions. Fill the desire information and it will generate the .keystore file on following path: <\/span><span style=\"color: #000000;\">Linux: \/<\/span><span style=\"color: #000000;\"><strong>home\/[user]\/.keystore <\/strong><\/span><span style=\"color: #000000;\">file <\/span><span style=\"color: #000000;\">Window: <\/span><span style=\"color: #000000;\"><strong>\/Documents<\/strong><\/span> <span style=\"color: #000000;\"><strong>and<\/strong><\/span> <span style=\"color: #000000;\"><strong>Settings\/[user]\/.keystore<\/strong><\/span><\/li>\n<li><span style=\"color: #000000;\">One thing you would have to remember is the password that is used while generating the <\/span><span style=\"color: #000000;\"><strong>.keystore<\/strong><\/span><span style=\"color: #000000;\"> file because this password will be used in configuring Tomcat server instance<\/span><\/li>\n<li>After the generation of .keystore file, copy .keystore file to webapp of tomcat directory.<\/li>\n<li>Then open server.xml of Tomcat from conf\/server.xml and uncomment ssl port connector which is like<\/li>\n<\/ol>\n<p><!-- \t\t@page { margin: 2cm } \t\tP { margin-bottom: 0.21cm } --><\/p>\n<p>[xml]<br \/>\n&amp;lt;Connector port=&amp;quot;8443&amp;quot; protocol=&amp;quot;HTTP\/1.1&amp;quot; SSLEnabled=&amp;quot;true&amp;quot;<br \/>\n               maxThreads=&amp;quot;150&amp;quot;  scheme=&amp;quot;https&amp;quot; secure=&amp;quot;true&amp;quot;<br \/>\n               clientAuth=&amp;quot;false&amp;quot; sslProtocol=&amp;quot;TLS&amp;quot; keystoreFile=&amp;quot;webapps\/.keystore&amp;quot;<br \/>\nkeystorePass=&amp;quot;password-of-.keystore-file&amp;quot; \/&amp;gt;<br \/>\n[\/xml]<\/p>\n<p>&nbsp;<\/p>\n<p>Add <span style=\"color: #000000;\">following<\/span> <span style=\"color: #000000;\">line<\/span> <span style=\"color: #4f81bd;\">keystoreFile=&#8221;webapps\/.keystore&#8221;<\/span><span style=\"color: #4f81bd;\"> &amp; keystorePass=&#8221;<\/span><span style=\"color: #4f81bd;\">password-of-.keystore-file<\/span><span style=\"color: #4f81bd;\">&#8220;<\/span><\/p>\n<p><span style=\"color: #000000;\">Here <strong>keystoreFile<\/strong> is the location of .keystore file, and <strong>keystorePass <\/strong>is the password which initially used for creating .keystore file.<\/span><\/p>\n<p><span style=\"color: #000000;\"><br \/>\n<\/span><\/p>\n<p>5. Now SSL has been configured on <strong>Tomcat<\/strong><\/p>\n<p>6. Now configure your web application as SSL enabled. If you are working on Java application,\u00a0 add the following lines in web.xml file of your web application<\/p>\n<p>[xml]<br \/>\n&amp;lt;security-constraint&amp;gt;<br \/>\n\t\t&amp;lt;web-resource-collection&amp;gt;<br \/>\n\t\t\t&amp;lt;http-method&amp;gt;GET&amp;lt;\/http-method&amp;gt;<br \/>\n\t\t\t&amp;lt;http-method&amp;gt;POST&amp;lt;\/http-method&amp;gt;<br \/>\n\t\t\t&amp;lt;url-pattern&amp;gt;\/*&amp;lt;\/url-pattern&amp;gt;<br \/>\n\t\t&amp;lt;\/web-resource-collection&amp;gt;<\/p>\n<p>  \t\t&amp;lt;user-data-constraint&amp;gt;<br \/>\n      \t\t&amp;lt;transport-guarantee&amp;gt;CONFIDENTIAL&amp;lt;\/transport-guarantee&amp;gt;<br \/>\n   \t\t &amp;lt;\/user-data-constraint&amp;gt;<br \/>\n  \t&amp;lt;\/security-constraint&amp;gt;<br \/>\n[\/xml]<\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">If you are working on grails application, you need to run following command to generate the web.xml file because grails framework does not contain any web.xml file and web.xml file automatically generated when you are creating war file<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; line-height: 100%;\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">Run following command to get web.xml file in your grails application<\/span><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; line-height: 100%;\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"><br \/>\n<\/span><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"color: #4f81bd;\"><span style=\"font-family: Liberation Mono,monospace;\"><strong>grails install-templates<\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"color: #4f81bd;\"><span style=\"font-family: Liberation Mono,monospace;\"><strong><br \/>\n<\/strong><\/span><\/span><\/p>\n<p><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">web.xml file will be generated on the following location of your grails application <strong>\/src\/templates\/war\/web.xml<\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">Then add above mentioned snippet in <strong>web.xml<\/strong>, create the war file and deploy on tomcat server.<\/span><\/span><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"> Now your application will successfully run on SSL. You can access your application using following URL: <strong><span style=\"text-decoration: underline;\">https:\/\/localhost:8443\/&lt;application-name&gt;<\/span><\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"><strong><span style=\"text-decoration: underline;\"><br \/>\n<\/span><\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"><strong>Reference:-<a href=\"http:\/\/java.dzone.com\/articles\/setting-ssl-tomcat-5-minutes\" target=\"_blank\"><br \/>\n<\/a><\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><a href=\"..\/2012\/05\/31\/set-up-ssl-communication-between-two-server-using-keytool-command\/\">http:\/\/www.tothenew.com\/blog\/set-up-ssl-communication-between-two-server-using-keytool-command\/<\/a><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><a href=\"..\/2012\/06\/01\/how-to-set-up-ssl-certificates-on-your-server\/\">http:\/\/www.tothenew.com\/blog\/how-to-set-up-ssl-certificates-on-your-server\/<\/a><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\">\n<div style=\"width: 1px; height: 1px; overflow: hidden;\">\n<p><!-- \t\t@page { margin: 2cm } \t\tP { margin-bottom: 0.21cm } \t\tA:link { so-language: zxx } --><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">If you are working on grails application,you need to run following command to generate the web.xml file because grails framework does not contain any web.xml file and web.xml file automatically generated when you are creating war file<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">Run following command to get web.xml file in your grails application<\/span><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; line-height: 100%;\"><span style=\"color: #4f81bd;\"><span style=\"font-family: Liberation Mono,monospace;\"><strong> grails install-templates<\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">web.xml file generated on following location of your grails application <strong>\/src\/templates\/war\/web.xml<\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">Then add above mention snipplet in <strong>web.xml<\/strong>, create the war file and deploy on tomcat server.<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\">Now your application will successfully run on SSL <\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"> Access your application using following url&#8217;s:<\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"><strong> <span style=\"text-decoration: underline;\">https:\/\/localhost:8443\/application-name<\/span><\/strong><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm; text-decoration: none;\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"font-size: small;\"><strong> Reference:- http:\/\/java.dzone.com\/articles\/setting-ssl-tomcat-5-minutes<\/strong><\/span><\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To run your Grails application on SSL, firstly you need to configure the Tomcat server. Here in this example, I will show how to configure Tomcat instance and run Grails\/Java application. For SSL\/HTTPS: We need .keystore file. You can generate it by using command\u201ckeytool -genkey\u201d. Run this command on linux terminal or window cmd, follow [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":16},"categories":[7],"tags":[840,4840,4005,4844,824,589],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5940"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=5940"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5940\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=5940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=5940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=5940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}