Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect http to https with glassfish v4

We have created a web site on Glassfish v4 and it using port 8080 for http and port 8081 for https. Our cisco firewall forwards requests to port 80 to port 8080 and requests to port 443 to port 8081.

But we don't want users to be able to access http site at all. We want to redirect all requests to http site to https. How can it be done? In the Glassfish Admin panel, we have made changes to Configurations -> server-config -> Network Listeners -> http-listener-1 and http-listener-2 to redirect to port 8081 under HTTP tab but it is not working. Users are still able to see the http site from outside. Thank you for you help.

enter image description here

like image 847
Sean Kilb Avatar asked Mar 13 '14 14:03

Sean Kilb


1 Answers

Open web.xml inside WEB-INF of war file. Add following lines of code inside <web-app> tag.

<web-app>
  ...
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>Viewpoint Secure URLs</web-resource-name>
        <url-pattern>/*</url-pattern>
      </web-resource-collection>
      <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
      </user-data-constraint>
    </security-constraint>
</web-app>

See also The Java EE 6 Tutorial for more information.

like image 50
Navin Avatar answered Nov 12 '22 07:11

Navin