index.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. .. _security_tutorials_j2ee:
  2. Configuring J2EE Authentication
  3. ===============================
  4. Servlet containers such as Tomcat and Jetty offer their own options for
  5. authentication. Often it is desirable for an application such as GeoServer
  6. to use that existing authentication mechanisms rather than require its own
  7. authentication configuration.
  8. J2EE authentication allows GeoServer to delegate to the servlet container for
  9. authentication. This tutorial walks through the process of setting up J2EE
  10. authentication.
  11. Prerequisites
  12. -------------
  13. This tutorial requires a servlet container capable of doing its own authentication.
  14. This tutorial uses Tomcat.
  15. Deploy GeoServer in tomcat before proceeding.
  16. Configure the J2EE authentication filter
  17. ----------------------------------------
  18. In order to delegate to the container for authentication a filter must first be
  19. configured to recognize the container authentication.
  20. #. Login to the GeoServer web admin interface as the ``admin`` user.
  21. #. Click the ``Authentication`` link located under the ``Security`` section of
  22. the navigation sidebar.
  23. .. figure:: images/j2ee1.jpg
  24. :align: center
  25. #. Scroll down to the ``Authentication Filter`` panel and click the ``Add new`` link.
  26. #. Create a new filter named "j2ee" and fill out the settings form
  27. as follows:
  28. * Set the ``Role service`` to "default"
  29. .. figure:: images/j2ee2.jpg
  30. :align: center
  31. #. Save
  32. #. Back on the authentication page scroll down to the ``Filter Chains`` panel.
  33. #. Select "Web UI" from the ``Request type`` drop down.
  34. #. Select the ``j2ee`` filter and position it after the ``anonymous`` filter.
  35. .. figure:: images/j2ee3.jpg
  36. :align: center
  37. #. Save.
  38. Configure the role service
  39. --------------------------
  40. Since it is not possible to ask a J2EE container for the roles of a principal it is
  41. necessary to have all J2EE roles enlisted in a role service. The only J2EE API GeoServer
  42. can use is::
  43. class: javax.servlet.http.HttpServletRequest
  44. method: boolean isUserInRole(String role)
  45. The idea is to query all roles from the role service and test each role with the "isUserInRole" method.
  46. This tutorial assumes a user named "admin" with password "password" and a J2EE role named "tomcat".
  47. #. Click the ``Users, Groups, and Roles`` link located under the ``Security`` section of
  48. the navigation sidebar.
  49. .. figure:: images/j2ee5.jpg
  50. :align: center
  51. #. Click on ``default`` to work with the role service named "default".
  52. .. figure:: images/j2ee6.jpeg
  53. :align: center
  54. #. Click on the ``Roles`` tab.
  55. .. figure:: images/j2ee7.jpeg
  56. :align: center
  57. #. Click on the ``Add new role`` link.
  58. .. figure:: images/j2ee8.jpeg
  59. :align: center
  60. * Set the ``Name`` to "tomcat"
  61. .. figure:: images/j2ee9.jpeg
  62. :align: center
  63. #. Save
  64. Configure Tomcat for authentication
  65. -----------------------------------
  66. By default Tomcat does not require authentication for web applications. In this
  67. section Tomcat will be configured to secure GeoServer requiring a basic authentication
  68. login.
  69. #. Shut down Tomcat.
  70. #. Edit the ``conf/tomcat-users.xml`` under the Tomcat root directory and add a user
  71. named "admin"::
  72. <user username="admin" password="password" roles="tomcat"/>
  73. #. Edit the GeoServer ``web.xml`` file located at ``webapps/geoserver/WEB-INF/web.xml``
  74. under the Tomcat root directory and add the following at the end of the file directly
  75. before the closing ``</web-app>`` element::
  76. <security-constraint>
  77. <web-resource-collection>
  78. <url-pattern>/*</url-pattern>
  79. <http-method>GET</http-method>
  80. <http-method>POST</http-method>
  81. </web-resource-collection>
  82. <auth-constraint>
  83. <role-name>tomcat</role-name>
  84. </auth-constraint>
  85. </security-constraint>
  86. <login-config>
  87. <auth-method>BASIC</auth-method>
  88. </login-config>
  89. #. Save ``web.xml`` and restart Tomcat.
  90. .. note::
  91. It is necessary to add all the role names specified in the ``web.xml`` to the
  92. configured role service. This is duplicate work but there is currently no other solution.
  93. Test J2EE login
  94. ---------------
  95. #. Navigate to the GeoServer web admin interface. The result should be a prompt
  96. to authenticate.
  97. #. Enter in the username "admin" and password "password"
  98. .. figure:: images/j2ee4.jpg
  99. :align: center
  100. The result should be the admin user logged into the GeoServer web admin.